~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Vincent Ladeuil
  • Date: 2007-04-15 15:57:08 UTC
  • mto: (2420.1.1 bzr.http.auth)
  • mto: This revision was merged to the branch mainline in revision 2463.
  • Revision ID: v.ladeuil+lp@free.fr-20070415155708-frrm29cd9vvvd8do
Take jam's review comments into account. Fix typos, give better
explanations, add a test, complete another.

* bzrlib/transport/http/_urllib2_wrappers.py:
(HTTPBasicAuthHandler.http_error_401): Better explanation.

* bzrlib/transport/http/_urllib.py:
(HttpTransport_urllib.__init__): _auth renamed to _auth_scheme.

* bzrlib/tests/test_http.py:
(TestHTTPBasicAuth.test_unknown_user): New test.

* bzrlib/tests/HTTPTestUtil.py:
(BasicAuthHTTPServer): New class. Be explicit about use
requirements: basic authentication is mandatory.

Show diffs side-by-side

added added

removed removed

Lines of Context:
50
50
        if from_transport is not None:
51
51
            super(HttpTransport_urllib, self).__init__(base, from_transport)
52
52
            self._connection = from_transport._connection
53
 
            self._auth = from_transport._auth
 
53
            self._auth_scheme = from_transport._auth_scheme
54
54
            self._user = from_transport._user
55
55
            self._password = from_transport._password
56
56
            self._opener = from_transport._opener
57
57
        else:
58
 
            # urllib2 will be confused if it find
59
 
            # authentification infos in the urls. So we handle
60
 
            # them separatly. Note that we don't need to do that
61
 
            # when cloning (as above) since the cloned base is
62
 
            # already clean.
 
58
            # urllib2 will be confused if it find authentication
 
59
            # info in the urls. So we handle them separatly.
 
60
            # Note: we don't need to when cloning because it was
 
61
            # already done.
63
62
            clean_base, user, password = self._extract_auth(base)
64
63
            super(HttpTransport_urllib, self).__init__(clean_base,
65
64
                                                       from_transport)
66
65
            self._connection = None
67
 
            self._auth = None # We have to wait the 401 to know
 
66
            # auth_scheme will be set once we authenticate
 
67
            # successfully after a 401 error.
 
68
            self._auth_scheme = None
68
69
            self._user = user
69
70
            self._password = password
70
71
            self._opener = self._opener_class()
94
95
                pm.add_password(None, authuri, self._user, self._password)
95
96
 
96
97
    def _extract_auth(self, url):
97
 
        """Extracts authentification information from url.
 
98
        """Extracts authentication information from url.
98
99
 
99
100
        Get user and password from url of the form: http://user:pass@host/path
100
101
        :returns: (clean_url, user, password)
130
131
            # We will issue our first request, time to ask for a
131
132
            # password if needed
132
133
            self._ask_password()
133
 
        # Ensure authentification info is provided
134
 
        request.set_auth(self._auth, self._user, self._password)
 
134
        # Ensure authentication info is provided
 
135
        request.set_auth(self._auth_scheme, self._user, self._password)
135
136
 
136
137
        mutter('%s: [%s]' % (request.method, request.get_full_url()))
137
138
        if self._debuglevel > 0:
144
145
            # to connect to the server
145
146
            self._connection = request.connection
146
147
            # And get auth parameters too
147
 
            self._auth = request.auth
 
148
            self._auth_scheme = request.auth_scheme
148
149
            self._user = request.user
149
150
            self._password = request.password
150
151