~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/transport/http/_urllib2_wrappers.py

  • Committer: Robert J. Tanner
  • Date: 2009-04-30 22:40:42 UTC
  • mfrom: (4323 +trunk)
  • mto: This revision was merged to the branch mainline in revision 4324.
  • Revision ID: tanner@real-time.com-20090430224042-53v45axtue5bw45l
Merge 1.14.1 back to trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
917
917
 
918
918
        (scheme, user, password,
919
919
         host, port, path) = transport.ConnectedTransport._split_url(proxy)
 
920
        if not host:
 
921
            raise errors.InvalidURL(proxy, 'No host component')
920
922
 
921
923
        if request.proxy_auth == {}:
922
924
            # No proxy auth parameter are available, we are handling the first
1127
1129
        if user is None:
1128
1130
            user = auth_conf.get_user(auth['protocol'], auth['host'],
1129
1131
                                      port=auth['port'], path=auth['path'],
1130
 
                                      realm=realm)
 
1132
                                      realm=realm, ask=True,
 
1133
                                      prompt=self.build_username_prompt(auth))
1131
1134
        if user is not None and password is None:
1132
1135
            password = auth_conf.get_password(
1133
1136
                auth['protocol'], auth['host'], user, port=auth['port'],
1154
1157
        prompt += ' password'
1155
1158
        return prompt
1156
1159
 
 
1160
    def _build_username_prompt(self, auth):
 
1161
        """Build a prompt taking the protocol used into account.
 
1162
 
 
1163
        The AuthHandler is used by http and https, we want that information in
 
1164
        the prompt, so we build the prompt from the authentication dict which
 
1165
        contains all the needed parts.
 
1166
 
 
1167
        Also, http and proxy AuthHandlers present different prompts to the
 
1168
        user. The daughter classes should implements a public
 
1169
        build_username_prompt using this method.
 
1170
        """
 
1171
        prompt = '%s' % auth['protocol'].upper() + ' %(host)s'
 
1172
        realm = auth['realm']
 
1173
        if realm is not None:
 
1174
            prompt += ", Realm: '%s'" % realm
 
1175
        prompt += ' username'
 
1176
        return prompt
 
1177
 
1157
1178
    def http_request(self, request):
1158
1179
        """Insert an authentication header if information is available"""
1159
1180
        auth = self.get_auth(request)
1225
1246
        auth_header = 'Basic ' + raw.encode('base64').strip()
1226
1247
        return auth_header
1227
1248
 
 
1249
    def extract_realm(self, header_value):
 
1250
        match = self.auth_regexp.search(header_value)
 
1251
        realm = None
 
1252
        if match:
 
1253
            realm = match.group(1)
 
1254
        return match, realm
 
1255
 
1228
1256
    def auth_match(self, header, auth):
1229
1257
        scheme, raw_auth = self._parse_auth_header(header)
1230
1258
        if scheme != 'basic':
1231
1259
            return False
1232
1260
 
1233
 
        match = self.auth_regexp.search(raw_auth)
 
1261
        match, realm = self.extract_realm(raw_auth)
1234
1262
        if match:
1235
 
            realm = match.groups()
1236
1263
            if scheme != 'basic':
1237
1264
                return False
1238
1265
 
1385
1412
    def build_password_prompt(self, auth):
1386
1413
        return self._build_password_prompt(auth)
1387
1414
 
 
1415
    def build_username_prompt(self, auth):
 
1416
        return self._build_username_prompt(auth)
 
1417
 
1388
1418
    def http_error_401(self, req, fp, code, msg, headers):
1389
1419
        return self.auth_required(req, headers)
1390
1420
 
1416
1446
        prompt = 'Proxy ' + prompt
1417
1447
        return prompt
1418
1448
 
 
1449
    def build_username_prompt(self, auth):
 
1450
        prompt = self._build_username_prompt(auth)
 
1451
        prompt = 'Proxy ' + prompt
 
1452
        return prompt
 
1453
 
1419
1454
    def http_error_407(self, req, fp, code, msg, headers):
1420
1455
        return self.auth_required(req, headers)
1421
1456