]> granicus.if.org Git - python/commitdiff
Issue12541 - Add UserWarning for unquoted realms
authorSenthil Kumaran <senthil@uthcode.com>
Tue, 15 May 2012 16:03:29 +0000 (00:03 +0800)
committerSenthil Kumaran <senthil@uthcode.com>
Tue, 15 May 2012 16:03:29 +0000 (00:03 +0800)
1  2 
Lib/test/test_urllib2.py
Lib/urllib/request.py

Simple merge
index 6cc78edc4280a86259598b7928a99693186f6b43,0035e7067fdd6a6b0dc2d6881ba8c3e88625c2c6..96bb8d70686d044e953f31f038b09e95bc631b51
@@@ -925,20 -825,17 +925,23 @@@ class AbstractBasicAuthHandler
              self.retried += 1
  
          if authreq:
 -            mo = AbstractBasicAuthHandler.rx.search(authreq)
 -            if mo:
 -                scheme, quote, realm = mo.groups()
 -                if quote not in ["'", '"']:
 -                    warnings.warn("Basic Auth Realm was unquoted",
 -                                  UserWarning, 2)
 -                if scheme.lower() == 'basic':
 -                    response = self.retry_http_basic_auth(host, req, realm)
 -                    if response and response.code != 401:
 -                        self.retried = 0
 -                    return response
 +            scheme = authreq.split()[0]
 +            if scheme.lower() != 'basic':
 +                raise ValueError("AbstractBasicAuthHandler does not"
 +                                 " support the following scheme: '%s'" %
 +                                 scheme)
 +            else:
 +                mo = AbstractBasicAuthHandler.rx.search(authreq)
 +                if mo:
 +                    scheme, quote, realm = mo.groups()
++                    if quote not in ['"',"'"]:
++                        warnings.warn("Basic Auth Realm was unquoted",
++                                      UserWarning, 2)
 +                    if scheme.lower() == 'basic':
 +                        response = self.retry_http_basic_auth(host, req, realm)
 +                        if response and response.code != 401:
 +                            self.retried = 0
 +                        return response
  
      def retry_http_basic_auth(self, host, req, realm):
          user, pw = self.passwd.find_user_password(realm, host)