mirror of
https://github.com/python/cpython.git
synced 2025-09-16 05:36:29 +00:00
Revert r43399.
This commit is contained in:
parent
d34fa52a06
commit
80bb2bb7eb
4 changed files with 25 additions and 31 deletions
|
@ -493,11 +493,11 @@ class HandlerTests(unittest.TestCase):
|
||||||
r = MockResponse(200, "OK", {}, "")
|
r = MockResponse(200, "OK", {}, "")
|
||||||
newreq = h.do_request_(req)
|
newreq = h.do_request_(req)
|
||||||
if data is None: # GET
|
if data is None: # GET
|
||||||
self.assert_("Content-Length" not in req.unredirected_hdrs)
|
self.assert_("Content-length" not in req.unredirected_hdrs)
|
||||||
self.assert_("Content-Type" not in req.unredirected_hdrs)
|
self.assert_("Content-type" not in req.unredirected_hdrs)
|
||||||
else: # POST
|
else: # POST
|
||||||
self.assertEqual(req.unredirected_hdrs["Content-Length"], "0")
|
self.assertEqual(req.unredirected_hdrs["Content-length"], "0")
|
||||||
self.assertEqual(req.unredirected_hdrs["Content-Type"],
|
self.assertEqual(req.unredirected_hdrs["Content-type"],
|
||||||
"application/x-www-form-urlencoded")
|
"application/x-www-form-urlencoded")
|
||||||
# XXX the details of Host could be better tested
|
# XXX the details of Host could be better tested
|
||||||
self.assertEqual(req.unredirected_hdrs["Host"], "example.com")
|
self.assertEqual(req.unredirected_hdrs["Host"], "example.com")
|
||||||
|
@ -509,8 +509,8 @@ class HandlerTests(unittest.TestCase):
|
||||||
req.add_unredirected_header("Host", "baz")
|
req.add_unredirected_header("Host", "baz")
|
||||||
req.add_unredirected_header("Spam", "foo")
|
req.add_unredirected_header("Spam", "foo")
|
||||||
newreq = h.do_request_(req)
|
newreq = h.do_request_(req)
|
||||||
self.assertEqual(req.unredirected_hdrs["Content-Length"], "foo")
|
self.assertEqual(req.unredirected_hdrs["Content-length"], "foo")
|
||||||
self.assertEqual(req.unredirected_hdrs["Content-Type"], "bar")
|
self.assertEqual(req.unredirected_hdrs["Content-type"], "bar")
|
||||||
self.assertEqual(req.unredirected_hdrs["Host"], "baz")
|
self.assertEqual(req.unredirected_hdrs["Host"], "baz")
|
||||||
self.assertEqual(req.unredirected_hdrs["Spam"], "foo")
|
self.assertEqual(req.unredirected_hdrs["Spam"], "foo")
|
||||||
|
|
||||||
|
|
|
@ -118,7 +118,7 @@ class URLopener:
|
||||||
self.proxies = proxies
|
self.proxies = proxies
|
||||||
self.key_file = x509.get('key_file')
|
self.key_file = x509.get('key_file')
|
||||||
self.cert_file = x509.get('cert_file')
|
self.cert_file = x509.get('cert_file')
|
||||||
self.addheaders = [('User-Agent', self.version)]
|
self.addheaders = [('User-agent', self.version)]
|
||||||
self.__tempfiles = []
|
self.__tempfiles = []
|
||||||
self.__unlink = os.unlink # See cleanup()
|
self.__unlink = os.unlink # See cleanup()
|
||||||
self.tempcache = None
|
self.tempcache = None
|
||||||
|
@ -314,8 +314,8 @@ class URLopener:
|
||||||
h = httplib.HTTP(host)
|
h = httplib.HTTP(host)
|
||||||
if data is not None:
|
if data is not None:
|
||||||
h.putrequest('POST', selector)
|
h.putrequest('POST', selector)
|
||||||
h.putheader('Content-Type', 'application/x-www-form-urlencoded')
|
h.putheader('Content-type', 'application/x-www-form-urlencoded')
|
||||||
h.putheader('Content-Length', '%d' % len(data))
|
h.putheader('Content-length', '%d' % len(data))
|
||||||
else:
|
else:
|
||||||
h.putrequest('GET', selector)
|
h.putrequest('GET', selector)
|
||||||
if proxy_auth: h.putheader('Proxy-Authorization', 'Basic %s' % proxy_auth)
|
if proxy_auth: h.putheader('Proxy-Authorization', 'Basic %s' % proxy_auth)
|
||||||
|
@ -400,9 +400,9 @@ class URLopener:
|
||||||
cert_file=self.cert_file)
|
cert_file=self.cert_file)
|
||||||
if data is not None:
|
if data is not None:
|
||||||
h.putrequest('POST', selector)
|
h.putrequest('POST', selector)
|
||||||
h.putheader('Content-Type',
|
h.putheader('Content-type',
|
||||||
'application/x-www-form-urlencoded')
|
'application/x-www-form-urlencoded')
|
||||||
h.putheader('Content-Length', '%d' % len(data))
|
h.putheader('Content-length', '%d' % len(data))
|
||||||
else:
|
else:
|
||||||
h.putrequest('GET', selector)
|
h.putrequest('GET', selector)
|
||||||
if proxy_auth: h.putheader('Proxy-Authorization: Basic %s' % proxy_auth)
|
if proxy_auth: h.putheader('Proxy-Authorization: Basic %s' % proxy_auth)
|
||||||
|
@ -584,7 +584,7 @@ class URLopener:
|
||||||
data = base64.decodestring(data)
|
data = base64.decodestring(data)
|
||||||
else:
|
else:
|
||||||
data = unquote(data)
|
data = unquote(data)
|
||||||
msg.append('Content-Length: %d' % len(data))
|
msg.append('Content-length: %d' % len(data))
|
||||||
msg.append('')
|
msg.append('')
|
||||||
msg.append(data)
|
msg.append(data)
|
||||||
msg = '\n'.join(msg)
|
msg = '\n'.join(msg)
|
||||||
|
|
|
@ -254,11 +254,11 @@ class Request:
|
||||||
|
|
||||||
def add_header(self, key, val):
|
def add_header(self, key, val):
|
||||||
# useful for something like authentication
|
# useful for something like authentication
|
||||||
self.headers[key.title()] = val
|
self.headers[key.capitalize()] = val
|
||||||
|
|
||||||
def add_unredirected_header(self, key, val):
|
def add_unredirected_header(self, key, val):
|
||||||
# will not be added to a redirected request
|
# will not be added to a redirected request
|
||||||
self.unredirected_hdrs[key.title()] = val
|
self.unredirected_hdrs[key.capitalize()] = val
|
||||||
|
|
||||||
def has_header(self, header_name):
|
def has_header(self, header_name):
|
||||||
return (header_name in self.headers or
|
return (header_name in self.headers or
|
||||||
|
@ -277,7 +277,7 @@ class Request:
|
||||||
class OpenerDirector:
|
class OpenerDirector:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
client_version = "Python-urllib/%s" % __version__
|
client_version = "Python-urllib/%s" % __version__
|
||||||
self.addheaders = [('User-Agent', client_version)]
|
self.addheaders = [('User-agent', client_version)]
|
||||||
# manage the individual handlers
|
# manage the individual handlers
|
||||||
self.handlers = []
|
self.handlers = []
|
||||||
self.handle_open = {}
|
self.handle_open = {}
|
||||||
|
@ -592,7 +592,7 @@ class ProxyHandler(BaseHandler):
|
||||||
user, password = user_pass.split(':', 1)
|
user, password = user_pass.split(':', 1)
|
||||||
user_pass = base64.encodestring('%s:%s' % (unquote(user),
|
user_pass = base64.encodestring('%s:%s' % (unquote(user),
|
||||||
unquote(password))).strip()
|
unquote(password))).strip()
|
||||||
req.add_header('Proxy-Authorization', 'Basic ' + user_pass)
|
req.add_header('Proxy-authorization', 'Basic ' + user_pass)
|
||||||
host = unquote(host)
|
host = unquote(host)
|
||||||
req.set_proxy(host, type)
|
req.set_proxy(host, type)
|
||||||
if orig_type == type:
|
if orig_type == type:
|
||||||
|
@ -755,7 +755,7 @@ class HTTPBasicAuthHandler(AbstractBasicAuthHandler, BaseHandler):
|
||||||
|
|
||||||
class ProxyBasicAuthHandler(AbstractBasicAuthHandler, BaseHandler):
|
class ProxyBasicAuthHandler(AbstractBasicAuthHandler, BaseHandler):
|
||||||
|
|
||||||
auth_header = 'Proxy-Authorization'
|
auth_header = 'Proxy-authorization'
|
||||||
|
|
||||||
def http_error_407(self, req, fp, code, msg, headers):
|
def http_error_407(self, req, fp, code, msg, headers):
|
||||||
host = req.get_host()
|
host = req.get_host()
|
||||||
|
@ -955,20 +955,20 @@ class AbstractHTTPHandler(BaseHandler):
|
||||||
|
|
||||||
if request.has_data(): # POST
|
if request.has_data(): # POST
|
||||||
data = request.get_data()
|
data = request.get_data()
|
||||||
if not request.has_header('Content-Type'):
|
if not request.has_header('Content-type'):
|
||||||
request.add_unredirected_header(
|
request.add_unredirected_header(
|
||||||
'Content-Type',
|
'Content-type',
|
||||||
'application/x-www-form-urlencoded')
|
'application/x-www-form-urlencoded')
|
||||||
if not request.has_header('Content-Length'):
|
if not request.has_header('Content-length'):
|
||||||
request.add_unredirected_header(
|
request.add_unredirected_header(
|
||||||
'Content-Length', '%d' % len(data))
|
'Content-length', '%d' % len(data))
|
||||||
|
|
||||||
scheme, sel = splittype(request.get_selector())
|
scheme, sel = splittype(request.get_selector())
|
||||||
sel_host, sel_path = splithost(sel)
|
sel_host, sel_path = splithost(sel)
|
||||||
if not request.has_header('Host'):
|
if not request.has_header('Host'):
|
||||||
request.add_unredirected_header('Host', sel_host or host)
|
request.add_unredirected_header('Host', sel_host or host)
|
||||||
for name, value in self.parent.addheaders:
|
for name, value in self.parent.addheaders:
|
||||||
name = name.title()
|
name = name.capitalize()
|
||||||
if not request.has_header(name):
|
if not request.has_header(name):
|
||||||
request.add_unredirected_header(name, value)
|
request.add_unredirected_header(name, value)
|
||||||
|
|
||||||
|
@ -1145,7 +1145,7 @@ class FileHandler(BaseHandler):
|
||||||
modified = email.Utils.formatdate(stats.st_mtime, usegmt=True)
|
modified = email.Utils.formatdate(stats.st_mtime, usegmt=True)
|
||||||
mtype = mimetypes.guess_type(file)[0]
|
mtype = mimetypes.guess_type(file)[0]
|
||||||
headers = mimetools.Message(StringIO(
|
headers = mimetools.Message(StringIO(
|
||||||
'Content-Type: %s\nContent-Length: %d\nLast-Modified: %s\n' %
|
'Content-type: %s\nContent-length: %d\nLast-modified: %s\n' %
|
||||||
(mtype or 'text/plain', size, modified)))
|
(mtype or 'text/plain', size, modified)))
|
||||||
if host:
|
if host:
|
||||||
host, port = splitport(host)
|
host, port = splitport(host)
|
||||||
|
@ -1198,9 +1198,9 @@ class FTPHandler(BaseHandler):
|
||||||
headers = ""
|
headers = ""
|
||||||
mtype = mimetypes.guess_type(req.get_full_url())[0]
|
mtype = mimetypes.guess_type(req.get_full_url())[0]
|
||||||
if mtype:
|
if mtype:
|
||||||
headers += "Content-Type: %s\n" % mtype
|
headers += "Content-type: %s\n" % mtype
|
||||||
if retrlen is not None and retrlen >= 0:
|
if retrlen is not None and retrlen >= 0:
|
||||||
headers += "Content-Length: %d\n" % retrlen
|
headers += "Content-length: %d\n" % retrlen
|
||||||
sf = StringIO(headers)
|
sf = StringIO(headers)
|
||||||
headers = mimetools.Message(sf)
|
headers = mimetools.Message(sf)
|
||||||
return addinfourl(fp, headers, req.get_full_url())
|
return addinfourl(fp, headers, req.get_full_url())
|
||||||
|
|
|
@ -483,12 +483,6 @@ Extension Modules
|
||||||
Library
|
Library
|
||||||
-------
|
-------
|
||||||
|
|
||||||
- Bug #1459963: urllib2 now normalizes HTTP header names correctly
|
|
||||||
with title().
|
|
||||||
|
|
||||||
- Bug #1459963: urllib2 now normalizes HTTP header names correctly
|
|
||||||
with title().
|
|
||||||
|
|
||||||
- Queue.Queue objects now support .task_done() and .join() methods
|
- Queue.Queue objects now support .task_done() and .join() methods
|
||||||
to make it easier to monitor when daemon threads have completed
|
to make it easier to monitor when daemon threads have completed
|
||||||
processing all enqueued tasks. Patch #1455676.
|
processing all enqueued tasks. Patch #1455676.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue