Skip to content

Commit e6f276e

Browse files
committed
bpo-27485: Rename and deprecate undocumented functions in urllib.parse
1 parent ea4d9be commit e6f276e

File tree

3 files changed

+47
-47
lines changed

3 files changed

+47
-47
lines changed

Lib/lib2to3/fixes/fix_urllib.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616
"pathname2url", "url2pathname"]),
1717
("urllib.parse",
1818
["quote", "quote_plus", "unquote", "unquote_plus",
19-
"urlencode", "_splitattr", "_splithost", "_splitnport",
20-
"_splitpasswd", "_splitport", "_splitquery", "_splittag",
21-
"_splittype", "_splituser", "_splitvalue", ]),
19+
"urlencode", "splitattr", "splithost", "splitnport",
20+
"splitpasswd", "splitport", "splitquery", "splittag",
21+
"splittype", "splituser", "splitvalue", ]),
2222
("urllib.error",
2323
["ContentTooShortError"])],
2424
"urllib2" : [

Lib/test/test_urlparse.py

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -994,15 +994,15 @@ class Utility_Tests(unittest.TestCase):
994994
# In Python 2 this test class was in test_urllib.
995995

996996
def test_splittype(self):
997-
splittype = urllib.parse._splittype
997+
splittype = urllib.parse.splittype
998998
self.assertEqual(splittype('type:opaquestring'), ('type', 'opaquestring'))
999999
self.assertEqual(splittype('opaquestring'), (None, 'opaquestring'))
10001000
self.assertEqual(splittype(':opaquestring'), (None, ':opaquestring'))
10011001
self.assertEqual(splittype('type:'), ('type', ''))
10021002
self.assertEqual(splittype('type:opaque:string'), ('type', 'opaque:string'))
10031003

10041004
def test_splithost(self):
1005-
splithost = urllib.parse._splithost
1005+
splithost = urllib.parse.splithost
10061006
self.assertEqual(splithost('//www.example.org:80/foo/bar/baz.html'),
10071007
('www.example.org:80', '/foo/bar/baz.html'))
10081008
self.assertEqual(splithost('//www.example.org:80'),
@@ -1031,7 +1031,7 @@ def test_splithost(self):
10311031
('example.net', '/file#'))
10321032

10331033
def test_splituser(self):
1034-
splituser = urllib.parse._splituser
1034+
splituser = urllib.parse.splituser
10351035
self.assertEqual(splituser('User:[email protected]:080'),
10361036
('User:Pass', 'www.python.org:080'))
10371037
self.assertEqual(splituser('@www.python.org:080'),
@@ -1046,7 +1046,7 @@ def test_splituser(self):
10461046
def test_splitpasswd(self):
10471047
# Some of the password examples are not sensible, but it is added to
10481048
# confirming to RFC2617 and addressing issue4675.
1049-
splitpasswd = urllib.parse._splitpasswd
1049+
splitpasswd = urllib.parse.splitpasswd
10501050
self.assertEqual(splitpasswd('user:ab'), ('user', 'ab'))
10511051
self.assertEqual(splitpasswd('user:a\nb'), ('user', 'a\nb'))
10521052
self.assertEqual(splitpasswd('user:a\tb'), ('user', 'a\tb'))
@@ -1062,7 +1062,7 @@ def test_splitpasswd(self):
10621062
self.assertEqual(splitpasswd(':ab'), ('', 'ab'))
10631063

10641064
def test_splitport(self):
1065-
splitport = urllib.parse._splitport
1065+
splitport = urllib.parse.splitport
10661066
self.assertEqual(splitport('parrot:88'), ('parrot', '88'))
10671067
self.assertEqual(splitport('parrot'), ('parrot', None))
10681068
self.assertEqual(splitport('parrot:'), ('parrot', None))
@@ -1073,7 +1073,7 @@ def test_splitport(self):
10731073
self.assertEqual(splitport(':88'), ('', '88'))
10741074

10751075
def test_splitnport(self):
1076-
splitnport = urllib.parse._splitnport
1076+
splitnport = urllib.parse.splitnport
10771077
self.assertEqual(splitnport('parrot:88'), ('parrot', 88))
10781078
self.assertEqual(splitnport('parrot'), ('parrot', -1))
10791079
self.assertEqual(splitnport('parrot', 55), ('parrot', 55))
@@ -1087,7 +1087,7 @@ def test_splitnport(self):
10871087
def test_splitquery(self):
10881088
# Normal cases are exercised by other tests; ensure that we also
10891089
# catch cases with no port specified (testcase ensuring coverage)
1090-
splitquery = urllib.parse._splitquery
1090+
splitquery = urllib.parse.splitquery
10911091
self.assertEqual(splitquery('http://python.org/fake?foo=bar'),
10921092
('http://python.org/fake', 'foo=bar'))
10931093
self.assertEqual(splitquery('http://python.org/fake?foo=bar?'),
@@ -1097,7 +1097,7 @@ def test_splitquery(self):
10971097
self.assertEqual(splitquery('?foo=bar'), ('', 'foo=bar'))
10981098

10991099
def test_splittag(self):
1100-
splittag = urllib.parse._splittag
1100+
splittag = urllib.parse.splittag
11011101
self.assertEqual(splittag('http://example.com?foo=bar#baz'),
11021102
('http://example.com?foo=bar', 'baz'))
11031103
self.assertEqual(splittag('http://example.com?foo=bar#'),
@@ -1109,7 +1109,7 @@ def test_splittag(self):
11091109
('http://example.com?foo=bar#baz', 'boo'))
11101110

11111111
def test_splitattr(self):
1112-
splitattr = urllib.parse._splitattr
1112+
splitattr = urllib.parse.splitattr
11131113
self.assertEqual(splitattr('/path;attr1=value1;attr2=value2'),
11141114
('/path', ['attr1=value1', 'attr2=value2']))
11151115
self.assertEqual(splitattr('/path;'), ('/path', ['']))
@@ -1120,105 +1120,105 @@ def test_splitattr(self):
11201120
def test_splitvalue(self):
11211121
# Normal cases are exercised by other tests; test pathological cases
11221122
# with no key/value pairs. (testcase ensuring coverage)
1123-
splitvalue = urllib.parse._splitvalue
1123+
splitvalue = urllib.parse.splitvalue
11241124
self.assertEqual(splitvalue('foo=bar'), ('foo', 'bar'))
11251125
self.assertEqual(splitvalue('foo='), ('foo', ''))
11261126
self.assertEqual(splitvalue('=bar'), ('', 'bar'))
11271127
self.assertEqual(splitvalue('foobar'), ('foobar', None))
11281128
self.assertEqual(splitvalue('foo=bar=baz'), ('foo', 'bar=baz'))
11291129

11301130
def test_to_bytes(self):
1131-
result = urllib.parse._to_bytes('http://www.python.org')
1131+
result = urllib.parse.to_bytes('http://www.python.org')
11321132
self.assertEqual(result, 'http://www.python.org')
11331133
self.assertRaises(UnicodeError, urllib.parse._to_bytes,
11341134
'http://www.python.org/medi\u00e6val')
11351135

11361136
def test_unwrap(self):
1137-
url = urllib.parse._unwrap('<URL:type://host/path>')
1137+
url = urllib.parse.unwrap('<URL:type://host/path>')
11381138
self.assertEqual(url, 'type://host/path')
11391139

11401140

11411141
class DeprecationTest(unittest.TestCase):
11421142

11431143
def test_splittype_deprecation(self):
11441144
with self.assertWarns(DeprecationWarning) as cm:
1145-
urllib.parse.splittype()
1145+
urllib.parse.splittype('')
11461146
self.assertEqual(str(cm.warning),
11471147
'urllib.parse.splittype() is deprecated as of 3.7, '
11481148
'use urllib.parse.urlparse() instead')
11491149

11501150
def test_splithost_deprecation(self):
11511151
with self.assertWarns(DeprecationWarning) as cm:
1152-
urllib.parse.splithost()
1152+
urllib.parse.splithost('')
11531153
self.assertEqual(str(cm.warning),
11541154
'urllib.parse.splithost() is deprecated as of 3.7, '
11551155
'use urllib.parse.urlparse() instead')
11561156

11571157
def test_splituser_deprecation(self):
11581158
with self.assertWarns(DeprecationWarning) as cm:
1159-
urllib.parse.splituser()
1159+
urllib.parse.splituser('')
11601160
self.assertEqual(str(cm.warning),
11611161
'urllib.parse.splituser() is deprecated as of 3.7, '
11621162
'use urllib.parse.urlparse() instead')
11631163

11641164
def test_splitpasswd_deprecation(self):
11651165
with self.assertWarns(DeprecationWarning) as cm:
1166-
urllib.parse.splitpasswd()
1166+
urllib.parse.splitpasswd('')
11671167
self.assertEqual(str(cm.warning),
11681168
'urllib.parse.splitpasswd() is deprecated as of 3.7, '
11691169
'use urllib.parse.urlparse() instead')
11701170

11711171
def test_splitport_deprecation(self):
11721172
with self.assertWarns(DeprecationWarning) as cm:
1173-
urllib.parse.splitport()
1173+
urllib.parse.splitport('')
11741174
self.assertEqual(str(cm.warning),
11751175
'urllib.parse.splitport() is deprecated as of 3.7, '
11761176
'use urllib.parse.urlparse() instead')
11771177

11781178
def test_splitnport_deprecation(self):
11791179
with self.assertWarns(DeprecationWarning) as cm:
1180-
urllib.parse.splitnport()
1180+
urllib.parse.splitnport('')
11811181
self.assertEqual(str(cm.warning),
11821182
'urllib.parse.splitnport() is deprecated as of 3.7, '
11831183
'use urllib.parse.urlparse() instead')
11841184

11851185
def test_splitquery_deprecation(self):
11861186
with self.assertWarns(DeprecationWarning) as cm:
1187-
urllib.parse.splitquery()
1187+
urllib.parse.splitquery('')
11881188
self.assertEqual(str(cm.warning),
11891189
'urllib.parse.splitquery() is deprecated as of 3.7, '
11901190
'use urllib.parse.urlparse() instead')
11911191

11921192
def test_splittag_deprecation(self):
11931193
with self.assertWarns(DeprecationWarning) as cm:
1194-
urllib.parse.splittag()
1194+
urllib.parse.splittag('')
11951195
self.assertEqual(str(cm.warning),
11961196
'urllib.parse.splittag() is deprecated as of 3.7, '
11971197
'use urllib.parse.urlparse() instead')
11981198

11991199
def test_splitattr_deprecation(self):
12001200
with self.assertWarns(DeprecationWarning) as cm:
1201-
urllib.parse.splitattr()
1201+
urllib.parse.splitattr('')
12021202
self.assertEqual(str(cm.warning),
12031203
'urllib.parse.splitattr() is deprecated as of 3.7, '
12041204
'use urllib.parse.urlparse() instead')
12051205

12061206
def test_splitvalue_deprecation(self):
12071207
with self.assertWarns(DeprecationWarning) as cm:
1208-
urllib.parse.splitvalue()
1208+
urllib.parse.splitvalue('')
12091209
self.assertEqual(str(cm.warning),
12101210
'urllib.parse.splitvalue() is deprecated as of 3.7, '
1211-
'use urllib.parse.urlparse() instead')
1211+
'use urllib.parse.parse_qsl() instead')
12121212

12131213
def test_to_bytes_deprecation(self):
12141214
with self.assertWarns(DeprecationWarning) as cm:
1215-
urllib.parse.to_bytes()
1215+
urllib.parse.to_bytes('')
12161216
self.assertEqual(str(cm.warning),
12171217
'urllib.parse.to_bytes() is deprecated as of 3.7')
12181218

12191219
def test_unwrap(self):
12201220
with self.assertWarns(DeprecationWarning) as cm:
1221-
urllib.parse.unwrap()
1221+
urllib.parse.unwrap('')
12221222
self.assertEqual(str(cm.warning),
12231223
'urllib.parse.unwrap() is deprecated as of 3.7')
12241224

Lib/urllib/parse.py

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ def _hostinfo(self):
289289
"""
290290

291291
_ParseResultBase.__doc__ = """
292-
ParseResult(scheme, netloc, path, params, query, fragment)
292+
ParseResult(scheme, netloc, path, params, query, fragment)
293293
294294
A 6-tuple that contains components of a parsed URL.
295295
"""
@@ -915,7 +915,7 @@ def urlencode(query, doseq=False, safe='', encoding=None, errors=None,
915915
return '&'.join(l)
916916

917917

918-
def to_bytes(url=''):
918+
def to_bytes(url):
919919
warnings.warn("urllib.parse.to_bytes() is deprecated as of 3.7",
920920
DeprecationWarning, stacklevel=2)
921921
return _to_bytes(url)
@@ -935,7 +935,7 @@ def _to_bytes(url):
935935
return url
936936

937937

938-
def unwrap(url=''):
938+
def unwrap(url):
939939
warnings.warn("urllib.parse.unwrap() is deprecated as of 3.7",
940940
DeprecationWarning, stacklevel=2)
941941
return _unwrap(url)
@@ -950,7 +950,7 @@ def _unwrap(url):
950950
return url
951951

952952

953-
def splittype(url=''):
953+
def splittype(url):
954954
warnings.warn("urllib.parse.splittype() is deprecated as of 3.7, "
955955
"use urllib.parse.urlparse() instead",
956956
DeprecationWarning, stacklevel=2)
@@ -971,7 +971,7 @@ def _splittype(url):
971971
return None, url
972972

973973

974-
def splithost(url=''):
974+
def splithost(url):
975975
warnings.warn("urllib.parse.splithost() is deprecated as of 3.7, "
976976
"use urllib.parse.urlparse() instead",
977977
DeprecationWarning, stacklevel=2)
@@ -994,11 +994,11 @@ def _splithost(url):
994994
return None, url
995995

996996

997-
def splituser(url=''):
997+
def splituser(host):
998998
warnings.warn("urllib.parse.splituser() is deprecated as of 3.7, "
999999
"use urllib.parse.urlparse() instead",
10001000
DeprecationWarning, stacklevel=2)
1001-
return _splituser(url)
1001+
return _splituser(host)
10021002

10031003

10041004
def _splituser(host):
@@ -1007,11 +1007,11 @@ def _splituser(host):
10071007
return (user if delim else None), host
10081008

10091009

1010-
def splitpasswd(url=''):
1010+
def splitpasswd(user):
10111011
warnings.warn("urllib.parse.splitpasswd() is deprecated as of 3.7, "
10121012
"use urllib.parse.urlparse() instead",
10131013
DeprecationWarning, stacklevel=2)
1014-
return _splitpasswd(url)
1014+
return _splitpasswd(user)
10151015

10161016

10171017
def _splitpasswd(user):
@@ -1020,11 +1020,11 @@ def _splitpasswd(user):
10201020
return user, (passwd if delim else None)
10211021

10221022

1023-
def splitport(url=''):
1023+
def splitport(host):
10241024
warnings.warn("urllib.parse.splitport() is deprecated as of 3.7, "
10251025
"use urllib.parse.urlparse() instead",
10261026
DeprecationWarning, stacklevel=2)
1027-
return _splitport(url)
1027+
return _splitport(host)
10281028

10291029

10301030
# splittag('/path#tag') --> '/path', 'tag'
@@ -1043,11 +1043,11 @@ def _splitport(host):
10431043
return host, None
10441044

10451045

1046-
def splitnport(url=''):
1046+
def splitnport(host, defport=-1):
10471047
warnings.warn("urllib.parse.splitnport() is deprecated as of 3.7, "
10481048
"use urllib.parse.urlparse() instead",
10491049
DeprecationWarning, stacklevel=2)
1050-
return _splitnport(url)
1050+
return _splitnport(host, defport)
10511051

10521052

10531053
def _splitnport(host, defport=-1):
@@ -1067,7 +1067,7 @@ def _splitnport(host, defport=-1):
10671067
return host, defport
10681068

10691069

1070-
def splitquery(url=''):
1070+
def splitquery(url):
10711071
warnings.warn("urllib.parse.splitquery() is deprecated as of 3.7, "
10721072
"use urllib.parse.urlparse() instead",
10731073
DeprecationWarning, stacklevel=2)
@@ -1082,7 +1082,7 @@ def _splitquery(url):
10821082
return url, None
10831083

10841084

1085-
def splittag(url=''):
1085+
def splittag(url):
10861086
warnings.warn("urllib.parse.splittag() is deprecated as of 3.7, "
10871087
"use urllib.parse.urlparse() instead",
10881088
DeprecationWarning, stacklevel=2)
@@ -1097,7 +1097,7 @@ def _splittag(url):
10971097
return url, None
10981098

10991099

1100-
def splitattr(url=''):
1100+
def splitattr(url):
11011101
warnings.warn("urllib.parse.splitattr() is deprecated as of 3.7, "
11021102
"use urllib.parse.urlparse() instead",
11031103
DeprecationWarning, stacklevel=2)
@@ -1111,11 +1111,11 @@ def _splitattr(url):
11111111
return words[0], words[1:]
11121112

11131113

1114-
def splitvalue(url=''):
1114+
def splitvalue(attr):
11151115
warnings.warn("urllib.parse.splitvalue() is deprecated as of 3.7, "
1116-
"use urllib.parse.urlparse() instead",
1116+
"use urllib.parse.parse_qsl() instead",
11171117
DeprecationWarning, stacklevel=2)
1118-
return _splitvalue(url)
1118+
return _splitvalue(attr)
11191119

11201120

11211121
def _splitvalue(attr):

0 commit comments

Comments
 (0)