Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down
3 changes: 2 additions & 1 deletion mechanize/_clientcookie.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
18 changes: 15 additions & 3 deletions mechanize/_urllib2_fork.py
Original file line number Diff line number Diff line change
Expand Up @@ -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", "")

Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down