diff options
| author | shadchin <[email protected]> | 2025-02-16 15:28:01 +0300 |
|---|---|---|
| committer | shadchin <[email protected]> | 2025-02-16 16:03:50 +0300 |
| commit | a27b6a96fdc5ca444428ddef4823d0486dcdccb9 (patch) | |
| tree | adde5c24d9ea37e1634e7972e27e682a820ab941 /contrib/tools/python3/Lib/urllib | |
| parent | 7a3958c3c6de324baab9dba4bd4eb808c1b839a6 (diff) | |
Update Python 3 to 3.12.9
commit_hash:c8651982d81e18f18e037fb247cc6ae53c4fa7f1
Diffstat (limited to 'contrib/tools/python3/Lib/urllib')
| -rw-r--r-- | contrib/tools/python3/Lib/urllib/parse.py | 20 | ||||
| -rw-r--r-- | contrib/tools/python3/Lib/urllib/request.py | 4 | ||||
| -rw-r--r-- | contrib/tools/python3/Lib/urllib/robotparser.py | 2 |
3 files changed, 22 insertions, 4 deletions
diff --git a/contrib/tools/python3/Lib/urllib/parse.py b/contrib/tools/python3/Lib/urllib/parse.py index 24815952037..c72138a33ca 100644 --- a/contrib/tools/python3/Lib/urllib/parse.py +++ b/contrib/tools/python3/Lib/urllib/parse.py @@ -436,6 +436,23 @@ def _checknetloc(netloc): raise ValueError("netloc '" + netloc + "' contains invalid " + "characters under NFKC normalization") +def _check_bracketed_netloc(netloc): + # Note that this function must mirror the splitting + # done in NetlocResultMixins._hostinfo(). + hostname_and_port = netloc.rpartition('@')[2] + before_bracket, have_open_br, bracketed = hostname_and_port.partition('[') + if have_open_br: + # No data is allowed before a bracket. + if before_bracket: + raise ValueError("Invalid IPv6 URL") + hostname, _, port = bracketed.partition(']') + # No data is allowed after the bracket but before the port delimiter. + if port and not port.startswith(":"): + raise ValueError("Invalid IPv6 URL") + else: + hostname, _, port = hostname_and_port.partition(':') + _check_bracketed_host(hostname) + # Valid bracketed hosts are defined in # https://www.rfc-editor.org/rfc/rfc3986#page-49 and https://url.spec.whatwg.org/ def _check_bracketed_host(hostname): @@ -496,8 +513,7 @@ def urlsplit(url, scheme='', allow_fragments=True): (']' in netloc and '[' not in netloc)): raise ValueError("Invalid IPv6 URL") if '[' in netloc and ']' in netloc: - bracketed_host = netloc.partition('[')[2].partition(']')[0] - _check_bracketed_host(bracketed_host) + _check_bracketed_netloc(netloc) if allow_fragments and '#' in url: url, fragment = url.split('#', 1) if '?' in url: diff --git a/contrib/tools/python3/Lib/urllib/request.py b/contrib/tools/python3/Lib/urllib/request.py index 9a559f44152..c7ded0f67fc 100644 --- a/contrib/tools/python3/Lib/urllib/request.py +++ b/contrib/tools/python3/Lib/urllib/request.py @@ -903,9 +903,9 @@ class HTTPPasswordMgrWithDefaultRealm(HTTPPasswordMgr): class HTTPPasswordMgrWithPriorAuth(HTTPPasswordMgrWithDefaultRealm): - def __init__(self, *args, **kwargs): + def __init__(self): self.authenticated = {} - super().__init__(*args, **kwargs) + super().__init__() def add_password(self, realm, uri, user, passwd, is_authenticated=False): self.update_authenticated(uri, is_authenticated) diff --git a/contrib/tools/python3/Lib/urllib/robotparser.py b/contrib/tools/python3/Lib/urllib/robotparser.py index c58565e3945..409f2b2e48d 100644 --- a/contrib/tools/python3/Lib/urllib/robotparser.py +++ b/contrib/tools/python3/Lib/urllib/robotparser.py @@ -11,6 +11,7 @@ """ import collections +import urllib.error import urllib.parse import urllib.request @@ -65,6 +66,7 @@ class RobotFileParser: self.disallow_all = True elif err.code >= 400 and err.code < 500: self.allow_all = True + err.close() else: raw = f.read() self.parse(raw.decode("utf-8").splitlines()) |
