From 130a9f73779bdc3c6278d028be7af4c37c7d36a0 Mon Sep 17 00:00:00 2001 From: Evan Blaudy Date: Fri, 22 Nov 2024 17:06:08 +0100 Subject: [PATCH 1/2] [package] add support for python 3.13 + ci --- .github/workflows/ci.yml | 3 ++- setup.cfg | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 02404fa8..52de0002 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -10,7 +10,8 @@ jobs: strategy: fail-fast: false matrix: - version: ["2.7", "3.6", "3.7", "3.8", "3.9", "3.10", "3.11", "3.12"] + version: + ["2.7", "3.6", "3.7", "3.8", "3.9", "3.10", "3.11", "3.12", "3.13"] include: - version: "2.7" container: python:2.7.18-buster diff --git a/setup.cfg b/setup.cfg index 0a127127..a88071ad 100644 --- a/setup.cfg +++ b/setup.cfg @@ -22,6 +22,7 @@ classifiers = Programming Language :: Python :: 3.10 Programming Language :: Python :: 3.11 Programming Language :: Python :: 3.12 + Programming Language :: Python :: 3.13 Programming Language :: Python :: Implementation :: CPython Programming Language :: Python :: Implementation :: PyPy Topic :: Multimedia :: Graphics From 6b0d897a1fbc335f0e62e0fc58f30bc6e682c5d6 Mon Sep 17 00:00:00 2001 From: Evan Blaudy Date: Mon, 25 Nov 2024 11:58:35 +0100 Subject: [PATCH 2/2] [ci] fix tests add_verify_file_callback due to cgi deleted from python 3.13 --- setup.cfg | 1 + tests/utils.py | 29 +++++++++++++++++++++++------ 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/setup.cfg b/setup.cfg index a88071ad..1ec4d377 100644 --- a/setup.cfg +++ b/setup.cfg @@ -48,6 +48,7 @@ test = pytest pytest-cov requests_mock + multipart; python_version >= '3.13' lint = autoflake==2.3.1; python_version >= '3.8' diff --git a/tests/utils.py b/tests/utils.py index ebb6daf8..a40367c1 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -7,7 +7,6 @@ import json import gazu.client import io -import cgi def fakeid(string): @@ -38,12 +37,30 @@ def add_verify_file_callback(mock, dict_assert={}, url=None): def verify_file_callback(request): if url is None or url == request.url: body_file = io.BytesIO(request.body) - _, pdict = cgi.parse_header(request.headers["Content-Type"]) - if sys.version_info[0] == 3: - pdict["boundary"] = bytes(pdict["boundary"], "UTF-8") + + if sys.version_info >= (3, 13): + import multipart + + p = multipart.MultipartParser( + body_file, + boundary=bytes( + multipart.parse_options_header( + request.headers["Content-Type"] + )[1]["boundary"], + "UTF-8", + ), + charset="UTF-8", + ) + parsed = {part.name: [part.raw] for part in p.parts()} else: - pdict["boundary"] = bytes(pdict["boundary"]) - parsed = cgi.parse_multipart(fp=body_file, pdict=pdict) + import cgi + + _, pdict = cgi.parse_header(request.headers["Content-Type"]) + if sys.version_info[0] == 3: + pdict["boundary"] = bytes(pdict["boundary"], "utf-8") + else: + pdict["boundary"] = bytes(pdict["boundary"]) + parsed = cgi.parse_multipart(fp=body_file, pdict=pdict) for key in dict_assert.keys(): assert key in parsed.keys() if isinstance(parsed[key][0], bytes):