Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
0250de48
Commit
0250de48
authored
Apr 25, 2018
by
Cheryl Sabella
Committed by
Łukasz Langa
Apr 25, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bpo-27485: Rename and deprecate undocumented functions in urllib.parse (GH-2205)
parent
57faf348
Changes
6
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
244 additions
and
62 deletions
+244
-62
Lib/mimetypes.py
Lib/mimetypes.py
+1
-1
Lib/test/test_urlparse.py
Lib/test/test_urlparse.py
+87
-1
Lib/urllib/parse.py
Lib/urllib/parse.py
+99
-4
Lib/urllib/request.py
Lib/urllib/request.py
+53
-53
Lib/xmlrpc/client.py
Lib/xmlrpc/client.py
+3
-3
Misc/NEWS.d/next/Library/2018-04-25-14-05-21.bpo-27485.nclVSU.rst
...S.d/next/Library/2018-04-25-14-05-21.bpo-27485.nclVSU.rst
+1
-0
No files found.
Lib/mimetypes.py
View file @
0250de48
...
...
@@ -113,7 +113,7 @@ class MimeTypes:
Optional `strict' argument when False adds a bunch of commonly found,
but non-standard types.
"""
scheme
,
url
=
urllib
.
parse
.
splittype
(
url
)
scheme
,
url
=
urllib
.
parse
.
_
splittype
(
url
)
if
scheme
==
'data'
:
# syntax of data URLs:
# dataurl := "data:" [ mediatype ] [ ";base64" ] "," data
...
...
Lib/test/test_urlparse.py
View file @
0250de48
import
unittest
import
urllib.parse
import
warnings
RFC1808_BASE
=
"http://a/b/c/d;p?q#f"
RFC2396_BASE
=
"http://a/b/c/d;p?q"
...
...
@@ -1129,7 +1130,7 @@ class Utility_Tests(unittest.TestCase):
def
test_to_bytes
(
self
):
result
=
urllib
.
parse
.
to_bytes
(
'http://www.python.org'
)
self
.
assertEqual
(
result
,
'http://www.python.org'
)
self
.
assertRaises
(
UnicodeError
,
urllib
.
parse
.
to_bytes
,
self
.
assertRaises
(
UnicodeError
,
urllib
.
parse
.
_
to_bytes
,
'http://www.python.org/medi
\
u00e6
val'
)
def
test_unwrap
(
self
):
...
...
@@ -1137,5 +1138,90 @@ class Utility_Tests(unittest.TestCase):
self
.
assertEqual
(
url
,
'type://host/path'
)
class
DeprecationTest
(
unittest
.
TestCase
):
def
test_splittype_deprecation
(
self
):
with
self
.
assertWarns
(
DeprecationWarning
)
as
cm
:
urllib
.
parse
.
splittype
(
''
)
self
.
assertEqual
(
str
(
cm
.
warning
),
'urllib.parse.splittype() is deprecated as of 3.8, '
'use urllib.parse.urlparse() instead'
)
def
test_splithost_deprecation
(
self
):
with
self
.
assertWarns
(
DeprecationWarning
)
as
cm
:
urllib
.
parse
.
splithost
(
''
)
self
.
assertEqual
(
str
(
cm
.
warning
),
'urllib.parse.splithost() is deprecated as of 3.8, '
'use urllib.parse.urlparse() instead'
)
def
test_splituser_deprecation
(
self
):
with
self
.
assertWarns
(
DeprecationWarning
)
as
cm
:
urllib
.
parse
.
splituser
(
''
)
self
.
assertEqual
(
str
(
cm
.
warning
),
'urllib.parse.splituser() is deprecated as of 3.8, '
'use urllib.parse.urlparse() instead'
)
def
test_splitpasswd_deprecation
(
self
):
with
self
.
assertWarns
(
DeprecationWarning
)
as
cm
:
urllib
.
parse
.
splitpasswd
(
''
)
self
.
assertEqual
(
str
(
cm
.
warning
),
'urllib.parse.splitpasswd() is deprecated as of 3.8, '
'use urllib.parse.urlparse() instead'
)
def
test_splitport_deprecation
(
self
):
with
self
.
assertWarns
(
DeprecationWarning
)
as
cm
:
urllib
.
parse
.
splitport
(
''
)
self
.
assertEqual
(
str
(
cm
.
warning
),
'urllib.parse.splitport() is deprecated as of 3.8, '
'use urllib.parse.urlparse() instead'
)
def
test_splitnport_deprecation
(
self
):
with
self
.
assertWarns
(
DeprecationWarning
)
as
cm
:
urllib
.
parse
.
splitnport
(
''
)
self
.
assertEqual
(
str
(
cm
.
warning
),
'urllib.parse.splitnport() is deprecated as of 3.8, '
'use urllib.parse.urlparse() instead'
)
def
test_splitquery_deprecation
(
self
):
with
self
.
assertWarns
(
DeprecationWarning
)
as
cm
:
urllib
.
parse
.
splitquery
(
''
)
self
.
assertEqual
(
str
(
cm
.
warning
),
'urllib.parse.splitquery() is deprecated as of 3.8, '
'use urllib.parse.urlparse() instead'
)
def
test_splittag_deprecation
(
self
):
with
self
.
assertWarns
(
DeprecationWarning
)
as
cm
:
urllib
.
parse
.
splittag
(
''
)
self
.
assertEqual
(
str
(
cm
.
warning
),
'urllib.parse.splittag() is deprecated as of 3.8, '
'use urllib.parse.urlparse() instead'
)
def
test_splitattr_deprecation
(
self
):
with
self
.
assertWarns
(
DeprecationWarning
)
as
cm
:
urllib
.
parse
.
splitattr
(
''
)
self
.
assertEqual
(
str
(
cm
.
warning
),
'urllib.parse.splitattr() is deprecated as of 3.8, '
'use urllib.parse.urlparse() instead'
)
def
test_splitvalue_deprecation
(
self
):
with
self
.
assertWarns
(
DeprecationWarning
)
as
cm
:
urllib
.
parse
.
splitvalue
(
''
)
self
.
assertEqual
(
str
(
cm
.
warning
),
'urllib.parse.splitvalue() is deprecated as of 3.8, '
'use urllib.parse.parse_qsl() instead'
)
def
test_to_bytes_deprecation
(
self
):
with
self
.
assertWarns
(
DeprecationWarning
)
as
cm
:
urllib
.
parse
.
to_bytes
(
''
)
self
.
assertEqual
(
str
(
cm
.
warning
),
'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__"
:
unittest
.
main
()
Lib/urllib/parse.py
View file @
0250de48
...
...
@@ -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
)
Lib/urllib/request.py
View file @
0250de48
This diff is collapsed.
Click to expand it.
Lib/xmlrpc/client.py
View file @
0250de48
...
...
@@ -1214,7 +1214,7 @@ class Transport:
if
isinstance
(
host
,
tuple
):
host
,
x509
=
host
auth
,
host
=
urllib
.
parse
.
splituser
(
host
)
auth
,
host
=
urllib
.
parse
.
_
splituser
(
host
)
if
auth
:
auth
=
urllib
.
parse
.
unquote_to_bytes
(
auth
)
...
...
@@ -1413,10 +1413,10 @@ class ServerProxy:
# establish a "logical" server connection
# get the url
type
,
uri
=
urllib
.
parse
.
splittype
(
uri
)
type
,
uri
=
urllib
.
parse
.
_
splittype
(
uri
)
if
type
not
in
(
"http"
,
"https"
):
raise
OSError
(
"unsupported XML-RPC protocol"
)
self
.
__host
,
self
.
__handler
=
urllib
.
parse
.
splithost
(
uri
)
self
.
__host
,
self
.
__handler
=
urllib
.
parse
.
_
splithost
(
uri
)
if
not
self
.
__handler
:
self
.
__handler
=
"/RPC2"
...
...
Misc/NEWS.d/next/Library/2018-04-25-14-05-21.bpo-27485.nclVSU.rst
0 → 100644
View file @
0250de48
Rename and deprecate undocumented functions in :func:`urllib.parse`.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment