Skip to content

Commit

Permalink
Change Request.add_header to call string.capitalize in order to norma…
Browse files Browse the repository at this point in the history
…lize

headers and not have any dependency on case.  Closes patch #649742.

Also changed all instances of dict.items to dict.iteritems where appropriate.
  • Loading branch information
brettcannon committed May 12, 2003
1 parent bf3a752 commit 86503b1
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions Lib/urllib2.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,8 @@ def __init__(self, url, data=None, headers={}):
self.port = None
self.data = data
self.headers = {}
self.headers.update(headers)
for key, value in headers.iteritems():
self.add_header(key, value)

def __getattr__(self, attr):
# XXX this is a fallback mechanism to guard against these
Expand Down Expand Up @@ -248,7 +249,7 @@ def set_proxy(self, host, type):

def add_header(self, key, val):
# useful for something like authentication
self.headers[key] = val
self.headers[key.capitalize()] = val

class OpenerDirector:
def __init__(self):
Expand Down Expand Up @@ -478,7 +479,7 @@ def __init__(self, proxies=None):
proxies = getproxies()
assert hasattr(proxies, 'has_key'), "proxies must be a mapping"
self.proxies = proxies
for type, url in proxies.items():
for type, url in proxies.iteritems():
setattr(self, '%s_open' % type,
lambda r, proxy=url, type=type, meth=self.proxy_open: \
meth(r, proxy, type))
Expand Down Expand Up @@ -563,7 +564,7 @@ def add_password(self, realm, uri, user, passwd):
def find_user_password(self, realm, authuri):
domains = self.passwd.get(realm, {})
authuri = self.reduce_uri(authuri)
for uris, authinfo in domains.items():
for uris, authinfo in domains.iteritems():
for uri in uris:
if self.is_suburi(uri, authuri):
return authinfo
Expand Down Expand Up @@ -805,7 +806,7 @@ def do_open(self, http_class, req):
name, value = args
if name not in req.headers:
h.putheader(*args)
for k, v in req.headers.items():
for k, v in req.headers.iteritems():
h.putheader(k, v)
# httplib will attempt to connect() here. be prepared
# to convert a socket error to a URLError.
Expand Down Expand Up @@ -1012,7 +1013,7 @@ def check_cache(self):
# first check for old ones
t = time.time()
if self.soonest <= t:
for k, v in self.timeout.items():
for k, v in self.timeout.iteritems():
if v < t:
self.cache[k].close()
del self.cache[k]
Expand All @@ -1021,7 +1022,7 @@ def check_cache(self):

# then check the size
if len(self.cache) == self.max_conns:
for k, v in self.timeout.items():
for k, v in self.timeout.iteritems():
if v == self.soonest:
del self.cache[k]
del self.timeout[k]
Expand Down

0 comments on commit 86503b1

Please sign in to comment.