Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(89)

Side by Side Diff: Lib/urllib2.py

Issue 4683: urllib2.HTTPDigestAuthHandler fails on third hostname?
Patch Set: Created 9 years, 5 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 """An extensible library for opening URLs using a variety of protocols 1 """An extensible library for opening URLs using a variety of protocols
2 2
3 The simplest way to use this module is to call the urlopen function, 3 The simplest way to use this module is to call the urlopen function,
4 which accepts a string containing a URL or a Request object (described 4 which accepts a string containing a URL or a Request object (described
5 below). It opens the URL and returns the results as file-like 5 below). It opens the URL and returns the results as file-like
6 object; the returned object has some extra methods described below. 6 object; the returned object has some extra methods described below.
7 7
8 The OpenerDirector manages a collection of Handler objects that do 8 The OpenerDirector manages a collection of Handler objects that do
9 all the actual work. Each Handler implements a particular protocol or 9 all the actual work. Each Handler implements a particular protocol or
10 option. The OpenerDirector is a composite object that invokes the 10 option. The OpenerDirector is a composite object that invokes the
(...skipping 875 matching lines...) Expand 10 before | Expand all | Expand 10 after
886 886
887 # XXX qop="auth-int" supports is shaky 887 # XXX qop="auth-int" supports is shaky
888 888
889 def __init__(self, passwd=None): 889 def __init__(self, passwd=None):
890 if passwd is None: 890 if passwd is None:
891 passwd = HTTPPasswordMgr() 891 passwd = HTTPPasswordMgr()
892 self.passwd = passwd 892 self.passwd = passwd
893 self.add_password = self.passwd.add_password 893 self.add_password = self.passwd.add_password
894 self.retried = 0 894 self.retried = 0
895 self.nonce_count = 0 895 self.nonce_count = 0
896 self.last_nonce = None
896 897
897 def reset_retry_count(self): 898 def reset_retry_count(self):
898 self.retried = 0 899 self.retried = 0
899 900
900 def http_error_auth_reqed(self, auth_header, host, req, headers): 901 def http_error_auth_reqed(self, auth_header, host, req, headers):
901 authreq = headers.get(auth_header, None) 902 authreq = headers.get(auth_header, None)
902 if self.retried > 5: 903 if self.retried > 5:
903 # Don't fail endlessly - if we failed once, we'll probably 904 # Don't fail endlessly - if we failed once, we'll probably
904 # fail a second time. Hm. Unless the Password Manager is 905 # fail a second time. Hm. Unless the Password Manager is
905 # prompting for the information. Crap. This isn't great 906 # prompting for the information. Crap. This isn't great
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
960 if req.has_data(): 961 if req.has_data():
961 entdig = self.get_entity_digest(req.get_data(), chal) 962 entdig = self.get_entity_digest(req.get_data(), chal)
962 else: 963 else:
963 entdig = None 964 entdig = None
964 965
965 A1 = "%s:%s:%s" % (user, realm, pw) 966 A1 = "%s:%s:%s" % (user, realm, pw)
966 A2 = "%s:%s" % (req.get_method(), 967 A2 = "%s:%s" % (req.get_method(),
967 # XXX selector: what about proxies and full urls 968 # XXX selector: what about proxies and full urls
968 req.get_selector()) 969 req.get_selector())
969 if qop == 'auth': 970 if qop == 'auth':
970 self.nonce_count += 1 971 if nonce == self.last_nonce:
972 self.nonce_count += 1
973 else:
974 self.nonce_count = 1
975 self.last_nonce = nonce
971 ncvalue = '%08x' % self.nonce_count 976 ncvalue = '%08x' % self.nonce_count
972 cnonce = self.get_cnonce(nonce) 977 cnonce = self.get_cnonce(nonce)
973 noncebit = "%s:%s:%s:%s:%s" % (nonce, ncvalue, cnonce, qop, H(A2)) 978 noncebit = "%s:%s:%s:%s:%s" % (nonce, ncvalue, cnonce, qop, H(A2))
974 respdig = KD(H(A1), noncebit) 979 respdig = KD(H(A1), noncebit)
975 elif qop is None: 980 elif qop is None:
976 respdig = KD(H(A1), "%s:%s" % (nonce, H(A2))) 981 respdig = KD(H(A1), "%s:%s" % (nonce, H(A2)))
977 else: 982 else:
978 # XXX handle auth-int. 983 # XXX handle auth-int.
979 raise URLError("qop '%s' is not supported." % qop) 984 raise URLError("qop '%s' is not supported." % qop)
980 985
(...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after
1372 self.soonest = min(self.timeout.values()) 1377 self.soonest = min(self.timeout.values())
1373 1378
1374 # then check the size 1379 # then check the size
1375 if len(self.cache) == self.max_conns: 1380 if len(self.cache) == self.max_conns:
1376 for k, v in self.timeout.items(): 1381 for k, v in self.timeout.items():
1377 if v == self.soonest: 1382 if v == self.soonest:
1378 del self.cache[k] 1383 del self.cache[k]
1379 del self.timeout[k] 1384 del self.timeout[k]
1380 break 1385 break
1381 self.soonest = min(self.timeout.values()) 1386 self.soonest = min(self.timeout.values())
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+