From: Senthil Kumaran Date: Tue, 15 May 2012 16:03:29 +0000 (+0800) Subject: Issue12541 - Add UserWarning for unquoted realms X-Git-Tag: v3.3.0a4~155^2~5 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=92a5bf0c0aae607da90bb08a01b7d06c4c8b45fe;p=python Issue12541 - Add UserWarning for unquoted realms --- 92a5bf0c0aae607da90bb08a01b7d06c4c8b45fe diff --cc Lib/urllib/request.py index 6cc78edc42,0035e7067f..96bb8d7068 --- a/Lib/urllib/request.py +++ b/Lib/urllib/request.py @@@ -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)