summaryrefslogtreecommitdiffstats
path: root/Lib/urllib/request.py
diff options
context:
space:
mode:
authorGeorg Brandl <georg@python.org>2008-06-23 11:44:14 (GMT)
committerGeorg Brandl <georg@python.org>2008-06-23 11:44:14 (GMT)
commit029986af249f71a5603110a0f5f0b18d0f335828 (patch)
tree90fafdd902e370d05952d900b7270043ad4c0053 /Lib/urllib/request.py
parent0f7ede45693be57ba51c7aa23a0d841f160de874 (diff)
downloadcpython-029986af249f71a5603110a0f5f0b18d0f335828.zip
cpython-029986af249f71a5603110a0f5f0b18d0f335828.tar.gz
cpython-029986af249f71a5603110a0f5f0b18d0f335828.tar.bz2
Fix old urllib/urllib2/urlparse usage.
Diffstat (limited to 'Lib/urllib/request.py')
-rw-r--r--Lib/urllib/request.py21
1 files changed, 11 insertions, 10 deletions
diff --git a/Lib/urllib/request.py b/Lib/urllib/request.py
index da13147..9f5e607 100644
--- a/Lib/urllib/request.py
+++ b/Lib/urllib/request.py
@@ -47,24 +47,25 @@ _call_chain conventions
Example usage:
-import urllib2
+import urllib.request
# set up authentication info
-authinfo = urllib2.HTTPBasicAuthHandler()
+authinfo = urllib.request.HTTPBasicAuthHandler()
authinfo.add_password(realm='PDQ Application',
uri='https://mahler:8092/site-updates.py',
user='klem',
passwd='geheim$parole')
-proxy_support = urllib2.ProxyHandler({"http" : "http://ahad-haam:3128"})
+proxy_support = urllib.request.ProxyHandler({"http" : "http://ahad-haam:3128"})
# build a new opener that adds authentication and caching FTP handlers
-opener = urllib2.build_opener(proxy_support, authinfo, urllib2.CacheFTPHandler)
+opener = urllib.request.build_opener(proxy_support, authinfo,
+ urllib.request.CacheFTPHandler)
# install it
-urllib2.install_opener(opener)
+urllib.request.install_opener(opener)
-f = urllib2.urlopen('http://www.python.org/')
+f = urllib.request.urlopen('http://www.python.org/')
"""
# XXX issues:
@@ -502,7 +503,7 @@ class HTTPRedirectHandler(BaseHandler):
# Strictly (according to RFC 2616), 301 or 302 in response to
# a POST MUST NOT cause a redirection without confirmation
- # from the user (of urllib2, in this case). In practice,
+ # from the user (of urllib.request, in this case). In practice,
# essentially all clients do redirect in this case, so we do
# the same.
# be conciliant with URIs containing a space
@@ -655,7 +656,7 @@ class ProxyHandler(BaseHandler):
if proxy_type is None:
proxy_type = orig_type
if user and password:
- user_pass = '%s:%s' % (unquote(user),
+ user_pass = '%s:%s' % (urllib.parse.unquote(user),
urllib.parse.unquote(password))
creds = base64.b64encode(user_pass.encode()).decode("ascii")
req.add_header('Proxy-authorization', 'Basic ' + creds)
@@ -808,7 +809,7 @@ class ProxyBasicAuthHandler(AbstractBasicAuthHandler, BaseHandler):
def http_error_407(self, req, fp, code, msg, headers):
# http_error_auth_reqed requires that there is no userinfo component in
- # authority. Assume there isn't one, since urllib2 does not (and
+ # authority. Assume there isn't one, since urllib.request does not (and
# should not, RFC 3986 s. 3.2.1) support requests for URLs containing
# userinfo.
authority = req.get_host()
@@ -1194,7 +1195,7 @@ class FileHandler(BaseHandler):
return urllib.response.addinfourl(open(localfile, 'rb'),
headers, 'file:'+file)
except OSError as msg:
- # urllib2 users shouldn't expect OSErrors coming from urlopen()
+ # users shouldn't expect OSErrors coming from urlopen()
raise urllib.error.URLError(msg)
raise urllib.error.URLError('file not on local host')