bpo-35397: Remove deprecation and document urllib.parse.unwrap (GH-11481)
This commit is contained in:
parent
1f39c28e48
commit
674ee12600
|
@ -370,6 +370,13 @@ or on combining URL components into a URL string.
|
||||||
.. versionchanged:: 3.2
|
.. versionchanged:: 3.2
|
||||||
Result is a structured object rather than a simple 2-tuple.
|
Result is a structured object rather than a simple 2-tuple.
|
||||||
|
|
||||||
|
.. function:: unwrap(url)
|
||||||
|
|
||||||
|
Extract the url from a wrapped URL (that is, a string formatted as
|
||||||
|
``<URL:scheme://host/path>``, ``<scheme://host/path>``, ``URL:scheme://host/path``
|
||||||
|
or ``scheme://host/path``). If *url* is not a wrapped URL, it is returned
|
||||||
|
without changes.
|
||||||
|
|
||||||
.. _parsing-ascii-encoded-bytes:
|
.. _parsing-ascii-encoded-bytes:
|
||||||
|
|
||||||
Parsing ASCII Encoded Bytes
|
Parsing ASCII Encoded Bytes
|
||||||
|
|
|
@ -236,6 +236,8 @@ library/urllib.request,,:close,Connection:close
|
||||||
library/urllib.request,,:port,:port
|
library/urllib.request,,:port,:port
|
||||||
library/urllib.request,,:lang,"xmlns=""http://www.w3.org/1999/xhtml"" xml:lang=""en"" lang=""en"">\n\n<head>\n"
|
library/urllib.request,,:lang,"xmlns=""http://www.w3.org/1999/xhtml"" xml:lang=""en"" lang=""en"">\n\n<head>\n"
|
||||||
library/urllib.request,,:password,"""joe:password@python.org"""
|
library/urllib.request,,:password,"""joe:password@python.org"""
|
||||||
|
library/urllib.parse,,:scheme,<URL:scheme://host/path>
|
||||||
|
library/urllib.parse,,:scheme,URL:scheme://host/path
|
||||||
library/uuid,,:uuid,urn:uuid:12345678-1234-5678-1234-567812345678
|
library/uuid,,:uuid,urn:uuid:12345678-1234-5678-1234-567812345678
|
||||||
library/venv,,:param,":param nodist: If True, setuptools and pip are not installed into the"
|
library/venv,,:param,":param nodist: If True, setuptools and pip are not installed into the"
|
||||||
library/venv,,:param,":param progress: If setuptools or pip are installed, the progress of the"
|
library/venv,,:param,":param progress: If setuptools or pip are installed, the progress of the"
|
||||||
|
|
|
|
@ -1169,8 +1169,10 @@ class Utility_Tests(unittest.TestCase):
|
||||||
'http://www.python.org/medi\u00e6val')
|
'http://www.python.org/medi\u00e6val')
|
||||||
|
|
||||||
def test_unwrap(self):
|
def test_unwrap(self):
|
||||||
url = urllib.parse._unwrap('<URL:type://host/path>')
|
for wrapped_url in ('<URL:scheme://host/path>', '<scheme://host/path>',
|
||||||
self.assertEqual(url, 'type://host/path')
|
'URL:scheme://host/path', 'scheme://host/path'):
|
||||||
|
url = urllib.parse.unwrap(wrapped_url)
|
||||||
|
self.assertEqual(url, 'scheme://host/path')
|
||||||
|
|
||||||
|
|
||||||
class DeprecationTest(unittest.TestCase):
|
class DeprecationTest(unittest.TestCase):
|
||||||
|
@ -1251,12 +1253,6 @@ class DeprecationTest(unittest.TestCase):
|
||||||
self.assertEqual(str(cm.warning),
|
self.assertEqual(str(cm.warning),
|
||||||
'urllib.parse.to_bytes() is deprecated as of 3.8')
|
'urllib.parse.to_bytes() is deprecated as of 3.8')
|
||||||
|
|
||||||
def test_unwrap(self):
|
|
||||||
with self.assertWarns(DeprecationWarning) as cm:
|
|
||||||
urllib.parse.unwrap('')
|
|
||||||
self.assertEqual(str(cm.warning),
|
|
||||||
'urllib.parse.unwrap() is deprecated as of 3.8')
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|
|
@ -979,17 +979,15 @@ def _to_bytes(url):
|
||||||
|
|
||||||
|
|
||||||
def unwrap(url):
|
def unwrap(url):
|
||||||
warnings.warn("urllib.parse.unwrap() is deprecated as of 3.8",
|
"""Transform a string like '<URL:scheme://host/path>' into 'scheme://host/path'.
|
||||||
DeprecationWarning, stacklevel=2)
|
|
||||||
return _unwrap(url)
|
|
||||||
|
|
||||||
|
The string is returned unchanged if it's not a wrapped URL.
|
||||||
def _unwrap(url):
|
"""
|
||||||
"""unwrap('<URL:type://host/path>') --> 'type://host/path'."""
|
|
||||||
url = str(url).strip()
|
url = str(url).strip()
|
||||||
if url[:1] == '<' and url[-1:] == '>':
|
if url[:1] == '<' and url[-1:] == '>':
|
||||||
url = url[1:-1].strip()
|
url = url[1:-1].strip()
|
||||||
if url[:4] == 'URL:': url = url[4:].strip()
|
if url[:4] == 'URL:':
|
||||||
|
url = url[4:].strip()
|
||||||
return url
|
return url
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -101,7 +101,7 @@ import warnings
|
||||||
|
|
||||||
from urllib.error import URLError, HTTPError, ContentTooShortError
|
from urllib.error import URLError, HTTPError, ContentTooShortError
|
||||||
from urllib.parse import (
|
from urllib.parse import (
|
||||||
urlparse, urlsplit, urljoin, _unwrap, quote, unquote,
|
urlparse, urlsplit, urljoin, unwrap, quote, unquote,
|
||||||
_splittype, _splithost, _splitport, _splituser, _splitpasswd,
|
_splittype, _splithost, _splitport, _splituser, _splitpasswd,
|
||||||
_splitattr, _splitquery, _splitvalue, _splittag, _to_bytes,
|
_splitattr, _splitquery, _splitvalue, _splittag, _to_bytes,
|
||||||
unquote_to_bytes, urlunparse)
|
unquote_to_bytes, urlunparse)
|
||||||
|
@ -349,7 +349,7 @@ class Request:
|
||||||
@full_url.setter
|
@full_url.setter
|
||||||
def full_url(self, url):
|
def full_url(self, url):
|
||||||
# unwrap('<URL:type://host/path>') --> 'type://host/path'
|
# unwrap('<URL:type://host/path>') --> 'type://host/path'
|
||||||
self._full_url = _unwrap(url)
|
self._full_url = unwrap(url)
|
||||||
self._full_url, self.fragment = _splittag(self._full_url)
|
self._full_url, self.fragment = _splittag(self._full_url)
|
||||||
self._parse()
|
self._parse()
|
||||||
|
|
||||||
|
@ -1727,7 +1727,7 @@ class URLopener:
|
||||||
# External interface
|
# External interface
|
||||||
def open(self, fullurl, data=None):
|
def open(self, fullurl, data=None):
|
||||||
"""Use URLopener().open(file) instead of open(file, 'r')."""
|
"""Use URLopener().open(file) instead of open(file, 'r')."""
|
||||||
fullurl = _unwrap(_to_bytes(fullurl))
|
fullurl = unwrap(_to_bytes(fullurl))
|
||||||
fullurl = quote(fullurl, safe="%/:=&?~#+!$,;'@()*[]|")
|
fullurl = quote(fullurl, safe="%/:=&?~#+!$,;'@()*[]|")
|
||||||
if self.tempcache and fullurl in self.tempcache:
|
if self.tempcache and fullurl in self.tempcache:
|
||||||
filename, headers = self.tempcache[fullurl]
|
filename, headers = self.tempcache[fullurl]
|
||||||
|
@ -1775,7 +1775,7 @@ class URLopener:
|
||||||
def retrieve(self, url, filename=None, reporthook=None, data=None):
|
def retrieve(self, url, filename=None, reporthook=None, data=None):
|
||||||
"""retrieve(url) returns (filename, headers) for a local object
|
"""retrieve(url) returns (filename, headers) for a local object
|
||||||
or (tempfilename, headers) for a remote object."""
|
or (tempfilename, headers) for a remote object."""
|
||||||
url = _unwrap(_to_bytes(url))
|
url = unwrap(_to_bytes(url))
|
||||||
if self.tempcache and url in self.tempcache:
|
if self.tempcache and url in self.tempcache:
|
||||||
return self.tempcache[url]
|
return self.tempcache[url]
|
||||||
type, url1 = _splittype(url)
|
type, url1 = _splittype(url)
|
||||||
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
Remove deprecation and document urllib.parse.unwrap(). Patch contributed by
|
||||||
|
Rémi Lapeyre.
|
Loading…
Reference in New Issue