mirror of
https://github.com/python/cpython.git
synced 2025-08-29 05:05:03 +00:00
bpo-27485: Rename and deprecate undocumented functions in urllib.parse (GH-2205)
This commit is contained in:
parent
57faf34887
commit
0250de4819
6 changed files with 244 additions and 62 deletions
|
@ -30,6 +30,7 @@ test_urlparse.py provides a good indicator of parsing behavior.
|
|||
import re
|
||||
import sys
|
||||
import collections
|
||||
import warnings
|
||||
|
||||
__all__ = ["urlparse", "urlunparse", "urljoin", "urldefrag",
|
||||
"urlsplit", "urlunsplit", "urlencode", "parse_qs",
|
||||
|
@ -288,7 +289,7 @@ by reference to a primary resource and additional identifying information.
|
|||
"""
|
||||
|
||||
_ParseResultBase.__doc__ = """
|
||||
ParseResult(scheme, netloc, path, params, query, fragment)
|
||||
ParseResult(scheme, netloc, path, params, query, fragment)
|
||||
|
||||
A 6-tuple that contains components of a parsed URL.
|
||||
"""
|
||||
|
@ -913,7 +914,14 @@ def urlencode(query, doseq=False, safe='', encoding=None, errors=None,
|
|||
l.append(k + '=' + elt)
|
||||
return '&'.join(l)
|
||||
|
||||
|
||||
def to_bytes(url):
|
||||
warnings.warn("urllib.parse.to_bytes() is deprecated as of 3.8",
|
||||
DeprecationWarning, stacklevel=2)
|
||||
return _to_bytes(url)
|
||||
|
||||
|
||||
def _to_bytes(url):
|
||||
"""to_bytes(u"URL") --> 'URL'."""
|
||||
# Most URL schemes require ASCII. If that changes, the conversion
|
||||
# can be relaxed.
|
||||
|
@ -926,7 +934,14 @@ def to_bytes(url):
|
|||
" contains non-ASCII characters")
|
||||
return url
|
||||
|
||||
|
||||
def unwrap(url):
|
||||
warnings.warn("urllib.parse.unwrap() is deprecated as of 3.8",
|
||||
DeprecationWarning, stacklevel=2)
|
||||
return _unwrap(url)
|
||||
|
||||
|
||||
def _unwrap(url):
|
||||
"""unwrap('<URL:type://host/path>') --> 'type://host/path'."""
|
||||
url = str(url).strip()
|
||||
if url[:1] == '<' and url[-1:] == '>':
|
||||
|
@ -934,8 +949,16 @@ def unwrap(url):
|
|||
if url[:4] == 'URL:': url = url[4:].strip()
|
||||
return url
|
||||
|
||||
_typeprog = None
|
||||
|
||||
def splittype(url):
|
||||
warnings.warn("urllib.parse.splittype() is deprecated as of 3.8, "
|
||||
"use urllib.parse.urlparse() instead",
|
||||
DeprecationWarning, stacklevel=2)
|
||||
return _splittype(url)
|
||||
|
||||
|
||||
_typeprog = None
|
||||
def _splittype(url):
|
||||
"""splittype('type:opaquestring') --> 'type', 'opaquestring'."""
|
||||
global _typeprog
|
||||
if _typeprog is None:
|
||||
|
@ -947,8 +970,16 @@ def splittype(url):
|
|||
return scheme.lower(), data
|
||||
return None, url
|
||||
|
||||
_hostprog = None
|
||||
|
||||
def splithost(url):
|
||||
warnings.warn("urllib.parse.splithost() is deprecated as of 3.8, "
|
||||
"use urllib.parse.urlparse() instead",
|
||||
DeprecationWarning, stacklevel=2)
|
||||
return _splithost(url)
|
||||
|
||||
|
||||
_hostprog = None
|
||||
def _splithost(url):
|
||||
"""splithost('//host[:port]/path') --> 'host[:port]', '/path'."""
|
||||
global _hostprog
|
||||
if _hostprog is None:
|
||||
|
@ -962,19 +993,43 @@ def splithost(url):
|
|||
return host_port, path
|
||||
return None, url
|
||||
|
||||
|
||||
def splituser(host):
|
||||
warnings.warn("urllib.parse.splituser() is deprecated as of 3.8, "
|
||||
"use urllib.parse.urlparse() instead",
|
||||
DeprecationWarning, stacklevel=2)
|
||||
return _splituser(host)
|
||||
|
||||
|
||||
def _splituser(host):
|
||||
"""splituser('user[:passwd]@host[:port]') --> 'user[:passwd]', 'host[:port]'."""
|
||||
user, delim, host = host.rpartition('@')
|
||||
return (user if delim else None), host
|
||||
|
||||
|
||||
def splitpasswd(user):
|
||||
warnings.warn("urllib.parse.splitpasswd() is deprecated as of 3.8, "
|
||||
"use urllib.parse.urlparse() instead",
|
||||
DeprecationWarning, stacklevel=2)
|
||||
return _splitpasswd(user)
|
||||
|
||||
|
||||
def _splitpasswd(user):
|
||||
"""splitpasswd('user:passwd') -> 'user', 'passwd'."""
|
||||
user, delim, passwd = user.partition(':')
|
||||
return user, (passwd if delim else None)
|
||||
|
||||
|
||||
def splitport(host):
|
||||
warnings.warn("urllib.parse.splitport() is deprecated as of 3.8, "
|
||||
"use urllib.parse.urlparse() instead",
|
||||
DeprecationWarning, stacklevel=2)
|
||||
return _splitport(host)
|
||||
|
||||
|
||||
# splittag('/path#tag') --> '/path', 'tag'
|
||||
_portprog = None
|
||||
def splitport(host):
|
||||
def _splitport(host):
|
||||
"""splitport('host:port') --> 'host', 'port'."""
|
||||
global _portprog
|
||||
if _portprog is None:
|
||||
|
@ -987,7 +1042,15 @@ def splitport(host):
|
|||
return host, port
|
||||
return host, None
|
||||
|
||||
|
||||
def splitnport(host, defport=-1):
|
||||
warnings.warn("urllib.parse.splitnport() is deprecated as of 3.8, "
|
||||
"use urllib.parse.urlparse() instead",
|
||||
DeprecationWarning, stacklevel=2)
|
||||
return _splitnport(host, defport)
|
||||
|
||||
|
||||
def _splitnport(host, defport=-1):
|
||||
"""Split host and port, returning numeric port.
|
||||
Return given default port if no ':' found; defaults to -1.
|
||||
Return numerical port if a valid number are found after ':'.
|
||||
|
@ -1003,27 +1066,59 @@ def splitnport(host, defport=-1):
|
|||
return host, nport
|
||||
return host, defport
|
||||
|
||||
|
||||
def splitquery(url):
|
||||
warnings.warn("urllib.parse.splitquery() is deprecated as of 3.8, "
|
||||
"use urllib.parse.urlparse() instead",
|
||||
DeprecationWarning, stacklevel=2)
|
||||
return _splitquery(url)
|
||||
|
||||
|
||||
def _splitquery(url):
|
||||
"""splitquery('/path?query') --> '/path', 'query'."""
|
||||
path, delim, query = url.rpartition('?')
|
||||
if delim:
|
||||
return path, query
|
||||
return url, None
|
||||
|
||||
|
||||
def splittag(url):
|
||||
warnings.warn("urllib.parse.splittag() is deprecated as of 3.8, "
|
||||
"use urllib.parse.urlparse() instead",
|
||||
DeprecationWarning, stacklevel=2)
|
||||
return _splittag(url)
|
||||
|
||||
|
||||
def _splittag(url):
|
||||
"""splittag('/path#tag') --> '/path', 'tag'."""
|
||||
path, delim, tag = url.rpartition('#')
|
||||
if delim:
|
||||
return path, tag
|
||||
return url, None
|
||||
|
||||
|
||||
def splitattr(url):
|
||||
warnings.warn("urllib.parse.splitattr() is deprecated as of 3.8, "
|
||||
"use urllib.parse.urlparse() instead",
|
||||
DeprecationWarning, stacklevel=2)
|
||||
return _splitattr(url)
|
||||
|
||||
|
||||
def _splitattr(url):
|
||||
"""splitattr('/path;attr1=value1;attr2=value2;...') ->
|
||||
'/path', ['attr1=value1', 'attr2=value2', ...]."""
|
||||
words = url.split(';')
|
||||
return words[0], words[1:]
|
||||
|
||||
|
||||
def splitvalue(attr):
|
||||
warnings.warn("urllib.parse.splitvalue() is deprecated as of 3.8, "
|
||||
"use urllib.parse.parse_qsl() instead",
|
||||
DeprecationWarning, stacklevel=2)
|
||||
return _splitvalue(attr)
|
||||
|
||||
|
||||
def _splitvalue(attr):
|
||||
"""splitvalue('attr=value') --> 'attr', 'value'."""
|
||||
attr, delim, value = attr.partition('=')
|
||||
return attr, (value if delim else None)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue