3030import re
3131import sys
3232import collections
33+ import warnings
3334
3435__all__ = ["urlparse" , "urlunparse" , "urljoin" , "urldefrag" ,
3536 "urlsplit" , "urlunsplit" , "urlencode" , "parse_qs" ,
@@ -288,7 +289,7 @@ def _hostinfo(self):
288289"""
289290
290291_ParseResultBase .__doc__ = """
291- ParseResult(scheme, netloc, path, params, query, fragment)
292+ ParseResult(scheme, netloc, path, params, query, fragment)
292293
293294A 6-tuple that contains components of a parsed URL.
294295"""
@@ -913,7 +914,14 @@ def urlencode(query, doseq=False, safe='', encoding=None, errors=None,
913914 l .append (k + '=' + elt )
914915 return '&' .join (l )
915916
917+
916918def to_bytes (url ):
919+ warnings .warn ("urllib.parse.to_bytes() is deprecated as of 3.8" ,
920+ DeprecationWarning , stacklevel = 2 )
921+ return _to_bytes (url )
922+
923+
924+ def _to_bytes (url ):
917925 """to_bytes(u"URL") --> 'URL'."""
918926 # Most URL schemes require ASCII. If that changes, the conversion
919927 # can be relaxed.
@@ -926,16 +934,31 @@ def to_bytes(url):
926934 " contains non-ASCII characters" )
927935 return url
928936
937+
929938def unwrap (url ):
939+ warnings .warn ("urllib.parse.unwrap() is deprecated as of 3.8" ,
940+ DeprecationWarning , stacklevel = 2 )
941+ return _unwrap (url )
942+
943+
944+ def _unwrap (url ):
930945 """unwrap('<URL:type://host/path>') --> 'type://host/path'."""
931946 url = str (url ).strip ()
932947 if url [:1 ] == '<' and url [- 1 :] == '>' :
933948 url = url [1 :- 1 ].strip ()
934949 if url [:4 ] == 'URL:' : url = url [4 :].strip ()
935950 return url
936951
937- _typeprog = None
952+
938953def splittype (url ):
954+ warnings .warn ("urllib.parse.splittype() is deprecated as of 3.8, "
955+ "use urllib.parse.urlparse() instead" ,
956+ DeprecationWarning , stacklevel = 2 )
957+ return _splittype (url )
958+
959+
960+ _typeprog = None
961+ def _splittype (url ):
939962 """splittype('type:opaquestring') --> 'type', 'opaquestring'."""
940963 global _typeprog
941964 if _typeprog is None :
@@ -947,8 +970,16 @@ def splittype(url):
947970 return scheme .lower (), data
948971 return None , url
949972
950- _hostprog = None
973+
951974def splithost (url ):
975+ warnings .warn ("urllib.parse.splithost() is deprecated as of 3.8, "
976+ "use urllib.parse.urlparse() instead" ,
977+ DeprecationWarning , stacklevel = 2 )
978+ return _splithost (url )
979+
980+
981+ _hostprog = None
982+ def _splithost (url ):
952983 """splithost('//host[:port]/path') --> 'host[:port]', '/path'."""
953984 global _hostprog
954985 if _hostprog is None :
@@ -962,19 +993,43 @@ def splithost(url):
962993 return host_port , path
963994 return None , url
964995
996+
965997def splituser (host ):
998+ warnings .warn ("urllib.parse.splituser() is deprecated as of 3.8, "
999+ "use urllib.parse.urlparse() instead" ,
1000+ DeprecationWarning , stacklevel = 2 )
1001+ return _splituser (host )
1002+
1003+
1004+ def _splituser (host ):
9661005 """splituser('user[:passwd]@host[:port]') --> 'user[:passwd]', 'host[:port]'."""
9671006 user , delim , host = host .rpartition ('@' )
9681007 return (user if delim else None ), host
9691008
1009+
9701010def splitpasswd (user ):
1011+ warnings .warn ("urllib.parse.splitpasswd() is deprecated as of 3.8, "
1012+ "use urllib.parse.urlparse() instead" ,
1013+ DeprecationWarning , stacklevel = 2 )
1014+ return _splitpasswd (user )
1015+
1016+
1017+ def _splitpasswd (user ):
9711018 """splitpasswd('user:passwd') -> 'user', 'passwd'."""
9721019 user , delim , passwd = user .partition (':' )
9731020 return user , (passwd if delim else None )
9741021
1022+
1023+ def splitport (host ):
1024+ warnings .warn ("urllib.parse.splitport() is deprecated as of 3.8, "
1025+ "use urllib.parse.urlparse() instead" ,
1026+ DeprecationWarning , stacklevel = 2 )
1027+ return _splitport (host )
1028+
1029+
9751030# splittag('/path#tag') --> '/path', 'tag'
9761031_portprog = None
977- def splitport (host ):
1032+ def _splitport (host ):
9781033 """splitport('host:port') --> 'host', 'port'."""
9791034 global _portprog
9801035 if _portprog is None :
@@ -987,7 +1042,15 @@ def splitport(host):
9871042 return host , port
9881043 return host , None
9891044
1045+
9901046def splitnport (host , defport = - 1 ):
1047+ warnings .warn ("urllib.parse.splitnport() is deprecated as of 3.8, "
1048+ "use urllib.parse.urlparse() instead" ,
1049+ DeprecationWarning , stacklevel = 2 )
1050+ return _splitnport (host , defport )
1051+
1052+
1053+ def _splitnport (host , defport = - 1 ):
9911054 """Split host and port, returning numeric port.
9921055 Return given default port if no ':' found; defaults to -1.
9931056 Return numerical port if a valid number are found after ':'.
@@ -1003,27 +1066,59 @@ def splitnport(host, defport=-1):
10031066 return host , nport
10041067 return host , defport
10051068
1069+
10061070def splitquery (url ):
1071+ warnings .warn ("urllib.parse.splitquery() is deprecated as of 3.8, "
1072+ "use urllib.parse.urlparse() instead" ,
1073+ DeprecationWarning , stacklevel = 2 )
1074+ return _splitquery (url )
1075+
1076+
1077+ def _splitquery (url ):
10071078 """splitquery('/path?query') --> '/path', 'query'."""
10081079 path , delim , query = url .rpartition ('?' )
10091080 if delim :
10101081 return path , query
10111082 return url , None
10121083
1084+
10131085def splittag (url ):
1086+ warnings .warn ("urllib.parse.splittag() is deprecated as of 3.8, "
1087+ "use urllib.parse.urlparse() instead" ,
1088+ DeprecationWarning , stacklevel = 2 )
1089+ return _splittag (url )
1090+
1091+
1092+ def _splittag (url ):
10141093 """splittag('/path#tag') --> '/path', 'tag'."""
10151094 path , delim , tag = url .rpartition ('#' )
10161095 if delim :
10171096 return path , tag
10181097 return url , None
10191098
1099+
10201100def splitattr (url ):
1101+ warnings .warn ("urllib.parse.splitattr() is deprecated as of 3.8, "
1102+ "use urllib.parse.urlparse() instead" ,
1103+ DeprecationWarning , stacklevel = 2 )
1104+ return _splitattr (url )
1105+
1106+
1107+ def _splitattr (url ):
10211108 """splitattr('/path;attr1=value1;attr2=value2;...') ->
10221109 '/path', ['attr1=value1', 'attr2=value2', ...]."""
10231110 words = url .split (';' )
10241111 return words [0 ], words [1 :]
10251112
1113+
10261114def splitvalue (attr ):
1115+ warnings .warn ("urllib.parse.splitvalue() is deprecated as of 3.8, "
1116+ "use urllib.parse.parse_qsl() instead" ,
1117+ DeprecationWarning , stacklevel = 2 )
1118+ return _splitvalue (attr )
1119+
1120+
1121+ def _splitvalue (attr ):
10271122 """splitvalue('attr=value') --> 'attr', 'value'."""
10281123 attr , delim , value = attr .partition ('=' )
10291124 return attr , (value if delim else None )
0 commit comments