mirror of
https://github.com/python/cpython.git
synced 2025-12-08 06:10:17 +00:00
Make a new urllib package .
It consists of code from urllib, urllib2, urlparse, and robotparser. The old modules have all been removed. The new package has five submodules: urllib.parse, urllib.request, urllib.response, urllib.error, and urllib.robotparser. The urllib.request.urlopen() function uses the url opener from urllib2. Note that the unittests have not been renamed for the beta, but they will be renamed in the future. Joint work with Senthil Kumaran.
This commit is contained in:
parent
a656d2cd89
commit
1afc169616
40 changed files with 3190 additions and 3536 deletions
|
|
@ -7,8 +7,9 @@
|
|||
|
||||
__revision__ = "$Id$"
|
||||
|
||||
import os, string, urllib2, getpass, urlparse
|
||||
import os, string, getpass
|
||||
import io
|
||||
import urllib.parse, urllib.request
|
||||
|
||||
from distutils.core import PyPIRCCommand
|
||||
from distutils.errors import *
|
||||
|
|
@ -94,7 +95,8 @@ def _set_config(self):
|
|||
def classifiers(self):
|
||||
''' Fetch the list of classifiers from the server.
|
||||
'''
|
||||
response = urllib2.urlopen(self.repository+'?:action=list_classifiers')
|
||||
url = self.repository+'?:action=list_classifiers'
|
||||
response = urllib.request.urlopen(url)
|
||||
print(response.read())
|
||||
|
||||
def verify_metadata(self):
|
||||
|
|
@ -166,8 +168,8 @@ def send_metadata(self):
|
|||
password = getpass.getpass('Password: ')
|
||||
|
||||
# set up the authentication
|
||||
auth = urllib2.HTTPPasswordMgr()
|
||||
host = urlparse.urlparse(self.repository)[1]
|
||||
auth = urllib.request.HTTPPasswordMgr()
|
||||
host = urllib.parse.urlparse(self.repository)[1]
|
||||
auth.add_password(self.realm, host, username, password)
|
||||
# send the info to the server and report the result
|
||||
code, result = self.post_to_server(self.build_post_data('submit'),
|
||||
|
|
@ -276,20 +278,20 @@ def post_to_server(self, data, auth=None):
|
|||
'Content-type': 'multipart/form-data; boundary=%s; charset=utf-8'%boundary,
|
||||
'Content-length': str(len(body))
|
||||
}
|
||||
req = urllib2.Request(self.repository, body, headers)
|
||||
req = urllib.request.Request(self.repository, body, headers)
|
||||
|
||||
# handle HTTP and include the Basic Auth handler
|
||||
opener = urllib2.build_opener(
|
||||
urllib2.HTTPBasicAuthHandler(password_mgr=auth)
|
||||
opener = urllib.request.build_opener(
|
||||
urllib.request.HTTPBasicAuthHandler(password_mgr=auth)
|
||||
)
|
||||
data = ''
|
||||
try:
|
||||
result = opener.open(req)
|
||||
except urllib2.HTTPError as e:
|
||||
except urllib.error.HTTPError as e:
|
||||
if self.show_response:
|
||||
data = e.fp.read()
|
||||
result = e.code, e.msg
|
||||
except urllib2.URLError as e:
|
||||
except urllib.error.URLError as e:
|
||||
result = 500, str(e)
|
||||
else:
|
||||
if self.show_response:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue