annotate AuthHandlers.py @ 8:4d61c56473c2 default tip

Fixed a problem where some feeds would have unpickleable expatreaders.
author Atul Varma <varmaa@toolness.com>
date Fri, 18 Apr 2008 17:13:02 -0700
parents f7f1b66283c6
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
6
f7f1b66283c6 Factored out the auth handlers from LocalAuth.py.sample and moved them to AuthHandlers.py, added comments to them.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
1 import urllib2
f7f1b66283c6 Factored out the auth handlers from LocalAuth.py.sample and moved them to AuthHandlers.py, added comments to them.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
2 import re
f7f1b66283c6 Factored out the auth handlers from LocalAuth.py.sample and moved them to AuthHandlers.py, added comments to them.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
3
f7f1b66283c6 Factored out the auth handlers from LocalAuth.py.sample and moved them to AuthHandlers.py, added comments to them.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
4 # Auth handlers that can be modified to provide logging or
f7f1b66283c6 Factored out the auth handlers from LocalAuth.py.sample and moved them to AuthHandlers.py, added comments to them.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
5 # hacks/bug-fixes.
f7f1b66283c6 Factored out the auth handlers from LocalAuth.py.sample and moved them to AuthHandlers.py, added comments to them.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
6
f7f1b66283c6 Factored out the auth handlers from LocalAuth.py.sample and moved them to AuthHandlers.py, added comments to them.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
7 class BasicAuthHandler( urllib2.HTTPBasicAuthHandler ):
f7f1b66283c6 Factored out the auth handlers from LocalAuth.py.sample and moved them to AuthHandlers.py, added comments to them.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
8 def http_error_401(self, req, fp, code, msg, headers):
f7f1b66283c6 Factored out the auth handlers from LocalAuth.py.sample and moved them to AuthHandlers.py, added comments to them.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
9 result = urllib2.HTTPBasicAuthHandler.http_error_401(
f7f1b66283c6 Factored out the auth handlers from LocalAuth.py.sample and moved them to AuthHandlers.py, added comments to them.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
10 self, req, fp, code, msg, headers
f7f1b66283c6 Factored out the auth handlers from LocalAuth.py.sample and moved them to AuthHandlers.py, added comments to them.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
11 )
f7f1b66283c6 Factored out the auth handlers from LocalAuth.py.sample and moved them to AuthHandlers.py, added comments to them.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
12 return result
f7f1b66283c6 Factored out the auth handlers from LocalAuth.py.sample and moved them to AuthHandlers.py, added comments to them.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
13
f7f1b66283c6 Factored out the auth handlers from LocalAuth.py.sample and moved them to AuthHandlers.py, added comments to them.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
14 def http_error_auth_reqed(self, authreq, host, req, headers):
f7f1b66283c6 Factored out the auth handlers from LocalAuth.py.sample and moved them to AuthHandlers.py, added comments to them.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
15 # This auth has been modified to fix the bug outlined in
f7f1b66283c6 Factored out the auth handlers from LocalAuth.py.sample and moved them to AuthHandlers.py, added comments to them.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
16 # Issue 2136: http://bugs.python.org/issue2136
f7f1b66283c6 Factored out the auth handlers from LocalAuth.py.sample and moved them to AuthHandlers.py, added comments to them.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
17 rx_sq = re.compile('(?:.*,)*[ \t]*([^ \t]+)[ \t]+realm=\'([^\']*)\'',
f7f1b66283c6 Factored out the auth handlers from LocalAuth.py.sample and moved them to AuthHandlers.py, added comments to them.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
18 re.I)
f7f1b66283c6 Factored out the auth handlers from LocalAuth.py.sample and moved them to AuthHandlers.py, added comments to them.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
19
f7f1b66283c6 Factored out the auth handlers from LocalAuth.py.sample and moved them to AuthHandlers.py, added comments to them.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
20 authreq = headers.get(authreq, None)
f7f1b66283c6 Factored out the auth handlers from LocalAuth.py.sample and moved them to AuthHandlers.py, added comments to them.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
21 if authreq:
f7f1b66283c6 Factored out the auth handlers from LocalAuth.py.sample and moved them to AuthHandlers.py, added comments to them.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
22 mo = urllib2.AbstractBasicAuthHandler.rx.search(authreq)
f7f1b66283c6 Factored out the auth handlers from LocalAuth.py.sample and moved them to AuthHandlers.py, added comments to them.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
23 if not mo:
f7f1b66283c6 Factored out the auth handlers from LocalAuth.py.sample and moved them to AuthHandlers.py, added comments to them.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
24 mo = rx_sq.search(authreq)
f7f1b66283c6 Factored out the auth handlers from LocalAuth.py.sample and moved them to AuthHandlers.py, added comments to them.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
25 if mo:
f7f1b66283c6 Factored out the auth handlers from LocalAuth.py.sample and moved them to AuthHandlers.py, added comments to them.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
26 scheme, realm = mo.groups()
f7f1b66283c6 Factored out the auth handlers from LocalAuth.py.sample and moved them to AuthHandlers.py, added comments to them.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
27 if scheme.lower() == 'basic':
f7f1b66283c6 Factored out the auth handlers from LocalAuth.py.sample and moved them to AuthHandlers.py, added comments to them.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
28 return self.retry_http_basic_auth(host, req, realm)
f7f1b66283c6 Factored out the auth handlers from LocalAuth.py.sample and moved them to AuthHandlers.py, added comments to them.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
29
f7f1b66283c6 Factored out the auth handlers from LocalAuth.py.sample and moved them to AuthHandlers.py, added comments to them.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
30 class DigestAuthHandler( urllib2.HTTPDigestAuthHandler ):
f7f1b66283c6 Factored out the auth handlers from LocalAuth.py.sample and moved them to AuthHandlers.py, added comments to them.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
31 def get_authorization(self, req, chal):
f7f1b66283c6 Factored out the auth handlers from LocalAuth.py.sample and moved them to AuthHandlers.py, added comments to them.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
32 return urllib2.HTTPDigestAuthHandler.get_authorization(
f7f1b66283c6 Factored out the auth handlers from LocalAuth.py.sample and moved them to AuthHandlers.py, added comments to them.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
33 self, req, chal
f7f1b66283c6 Factored out the auth handlers from LocalAuth.py.sample and moved them to AuthHandlers.py, added comments to them.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
34 )
f7f1b66283c6 Factored out the auth handlers from LocalAuth.py.sample and moved them to AuthHandlers.py, added comments to them.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
35
f7f1b66283c6 Factored out the auth handlers from LocalAuth.py.sample and moved them to AuthHandlers.py, added comments to them.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
36 def http_error_401(self, req, fp, code, msg, headers):
f7f1b66283c6 Factored out the auth handlers from LocalAuth.py.sample and moved them to AuthHandlers.py, added comments to them.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
37 return urllib2.HTTPDigestAuthHandler.http_error_401(
f7f1b66283c6 Factored out the auth handlers from LocalAuth.py.sample and moved them to AuthHandlers.py, added comments to them.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
38 self, req, fp, code, msg, headers
f7f1b66283c6 Factored out the auth handlers from LocalAuth.py.sample and moved them to AuthHandlers.py, added comments to them.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
39 )