diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c1777e4..84e714d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -15,7 +15,7 @@ jobs: strategy: fail-fast: false matrix: - python-version: ['3.10', '3.11', '3.12', '3.13', '3.14', '3.15'] + python-version: ['3.10', '3.11', '3.12', '3.13', '3.14', '3.15', '3.16'] steps: - uses: actions/checkout@v4 @@ -48,7 +48,7 @@ jobs: fail-fast: false matrix: os: [macos-latest, windows-latest] - python-version: ['3.10', '3.15'] + python-version: ['3.10', '3.16'] steps: - uses: actions/checkout@v4 diff --git a/mechanize/_clientcookie.py b/mechanize/_clientcookie.py index 6c89cbf..9c49323 100644 --- a/mechanize/_clientcookie.py +++ b/mechanize/_clientcookie.py @@ -240,7 +240,8 @@ def _really_load(self, f, filename, ignore_discard, ignore_expires): assert domain_specified == initial_dot discard = False - if expires == "": + if expires in ("", "0"): + # 3.16+ stdlib save() writes "0" (not "") for session cookies expires = None discard = True diff --git a/mechanize/_urllib2_fork.py b/mechanize/_urllib2_fork.py index 6a10292..0041d2d 100644 --- a/mechanize/_urllib2_fork.py +++ b/mechanize/_urllib2_fork.py @@ -130,7 +130,11 @@ def request_host(request): """ url = request.get_full_url() - host = urlparse(url)[1] + try: + host = urlparse(url)[1] + except ValueError: + # 3.16+ urlparse() rejects non-integer ports + host = "" if host == "": host = request.get_header("Host", "") @@ -173,7 +177,11 @@ def fix_invalid_bytes_in_url_component(component, allowed_chars=PATH_CHARS): def normalize_url(url): - parsed = urlparse(url) + try: + parsed = urlparse(url) + except ValueError: + # 3.16+ urlparse() rejects non-integer ports; keep the URL as-is + return url netloc = parsed.netloc if not isinstance(netloc, bytes) and netloc: def safe_encode(label): @@ -569,7 +577,11 @@ def http_error_default(self, req, fp, code, msg, hdrs): def _url_origin(url): - parts = urlsplit(url) + try: + parts = urlsplit(url) + except ValueError: + # 3.16+ urlsplit() rejects non-integer ports; treat as its own origin + return url scheme = (parts.scheme or '').lower() try: port = parts.port diff --git a/pyproject.toml b/pyproject.toml index 5928401..f30034a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -27,6 +27,7 @@ classifiers = [ "Programming Language :: Python :: 3.13", "Programming Language :: Python :: 3.14", "Programming Language :: Python :: 3.15", + "Programming Language :: Python :: 3.16", "Topic :: Internet", "Topic :: Internet :: File Transfer Protocol (FTP)", "Topic :: Internet :: WWW/HTTP",