diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 3c87037..93f8a58 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -6,7 +6,7 @@ jobs: strategy: max-parallel: 3 matrix: - python-version: ["3.7", "3.8", "3.9", "3.10"] + python-version: ["3.9", "3.10", "3.11", "3.12"] steps: - name: checkout @@ -20,7 +20,7 @@ jobs: - name: Install dependencies run: | python -m pip install --upgrade pip - pip install -U black pytest pytest-cov + pip install -U black pytest pytest-cov setuptools[core] python setup.py -q install - name: Style Check diff --git a/cdxj_indexer/postquery.py b/cdxj_indexer/postquery.py index aafb110..0d93759 100644 --- a/cdxj_indexer/postquery.py +++ b/cdxj_indexer/postquery.py @@ -1,17 +1,19 @@ -from warcio.utils import to_native_str +import base64 +import json +import sys from urllib.parse import unquote_plus, urlencode from io import BytesIO +from multipart import MultipartParser +from warcio.utils import to_native_str + from cdxj_indexer.amf import amf_parse -import base64 -import cgi -import json -import sys MAX_QUERY_LENGTH = 4096 + # ============================================================================ def append_method_query_from_req_resp(req, resp): len_ = req.http_headers.get_header("Content-Length") @@ -93,25 +95,16 @@ def handle_binary(query_data): query = handle_binary(query_data) elif mime.startswith("multipart/"): - env = { - "REQUEST_METHOD": "POST", - "CONTENT_TYPE": mime, - "CONTENT_LENGTH": len(query_data), - } - - args = dict(fp=BytesIO(query_data), environ=env, keep_blank_values=True) - - args["encoding"] = "utf-8" - try: - data = cgi.FieldStorage(**args) - except ValueError: + boundary = mime.split("boundary=")[1] + parser = MultipartParser(BytesIO(query_data), boundary, charset="utf8") + except (ValueError, IndexError): # Content-Type multipart/form-data may lack "boundary" info query = handle_binary(query_data) else: values = [] - for item in data.list: - values.append((item.name, item.value)) + for part in parser: + values.append((part.name, part.value)) query = urlencode(values, True) diff --git a/setup.py b/setup.py index 9679105..0220633 100755 --- a/setup.py +++ b/setup.py @@ -51,6 +51,7 @@ def run_tests(self): # temp fix for requests "idna<3.0", "py3amf", + "multipart", ], zip_safe=True, entry_points="""