view 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
line wrap: on
line source

import urllib2
import re

# Auth handlers that can be modified to provide logging or
# hacks/bug-fixes.

class BasicAuthHandler( urllib2.HTTPBasicAuthHandler ):
    def http_error_401(self, req, fp, code, msg, headers):
        result = urllib2.HTTPBasicAuthHandler.http_error_401(
            self, req, fp, code, msg, headers
            )
        return result

    def http_error_auth_reqed(self, authreq, host, req, headers):
        # This auth has been modified to fix the bug outlined in
        # Issue 2136: http://bugs.python.org/issue2136
        rx_sq = re.compile('(?:.*,)*[ \t]*([^ \t]+)[ \t]+realm=\'([^\']*)\'',
                           re.I)

        authreq = headers.get(authreq, None)
        if authreq:
            mo = urllib2.AbstractBasicAuthHandler.rx.search(authreq)
            if not mo:
                mo = rx_sq.search(authreq)
            if mo:
                scheme, realm = mo.groups()
                if scheme.lower() == 'basic':
                    return self.retry_http_basic_auth(host, req, realm)

class DigestAuthHandler( urllib2.HTTPDigestAuthHandler ):
    def get_authorization(self, req, chal):
        return urllib2.HTTPDigestAuthHandler.get_authorization(
            self, req, chal
            )

    def http_error_401(self, req, fp, code, msg, headers):
        return urllib2.HTTPDigestAuthHandler.http_error_401(
            self, req, fp, code, msg, headers
            )