From 95988466ec467cc525188652649b2a6d2784e53b Mon Sep 17 00:00:00 2001 From: JustAnotherArchivist Date: Fri, 25 Mar 2022 20:35:03 +0000 Subject: [PATCH] Make S3 response pattern matching more flexible (so it also works on Scaleway) --- s3-bucket-list | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/s3-bucket-list b/s3-bucket-list index 352e65e..6d20670 100755 --- a/s3-bucket-list +++ b/s3-bucket-list @@ -3,12 +3,16 @@ import html import http.client import json import os +import re import shlex import ssl import sys import urllib.parse +RESPONSE_PATTERN = re.compile(r'''^<\?xml version=(["'])1\.0\1 encoding=(["'])UTF-8\2\?>''' '\n?' r''''''.encode('ascii')) + + # Arguments i = 1 withListUrls = False @@ -79,7 +83,7 @@ while True: break attempt += 1 continue - if not body.startswith(b'\n') and not body.startswith(b""): + if not RESPONSE_PATTERN.match(body): raise RuntimeError(f'Invalid body: {body[:200]}...') if b'' in body[:200] and 'marker' in params: