~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/util/bencode.py

  • Committer: Vincent Ladeuil
  • Date: 2009-05-04 14:48:21 UTC
  • mto: (4349.1.1 integration)
  • mto: This revision was merged to the branch mainline in revision 4350.
  • Revision ID: v.ladeuil+lp@free.fr-20090504144821-39dvqkikmd3zqkdg
Handle servers proposing several authentication schemes.

* bzrlib/transport/http/_urllib2_wrappers.py:
(AbstractAuthHandler.auth_required): Several schemes can be
proposed by the server, try to match each one in turn.
(BasicAuthHandler.auth_match): Delete dead code.

* bzrlib/tests/test_http.py:
(load_tests): Separate proxy and http authentication tests as they
require different server setups.
(TestAuth.create_transport_readonly_server): Simplified by using
parameter provided by load_tests.
(TestAuth.test_changing_nonce): Adapt to new parametrization.
(TestProxyAuth.create_transport_readonly_server): Deleted.

* bzrlib/tests/http_utils.py:
(DigestAndBasicAuthRequestHandler, HTTPBasicAndDigestAuthServer,
ProxyBasicAndDigestAuthServer): Add a test server proposing both
basic and digest auth schemes but accepting only digest as valid.

Show diffs side-by-side

added added

removed removed

Lines of Context:
86
86
        return (r, f + 1)
87
87
 
88
88
    def bdecode(self, x):
89
 
        if type(x) != str:
90
 
            raise TypeError
91
89
        try:
92
90
            r, l = self.decode_func[x[0]](x, 0)
93
 
        except (IndexError, KeyError, OverflowError), e:
94
 
            import sys
95
 
            raise ValueError, ValueError(str(e)), sys.exc_info()[2]
 
91
        except (IndexError, KeyError):
 
92
            raise ValueError
96
93
        if l != len(x):
97
94
            raise ValueError
98
95
        return r
155
152
        encode_int(int(x), r)
156
153
    encode_func[BooleanType] = encode_bool
157
154
 
158
 
from bzrlib._static_tuple_py import StaticTuple
159
 
encode_func[StaticTuple] = encode_list
160
 
try:
161
 
    from bzrlib._static_tuple_c import StaticTuple
162
 
except ImportError:
163
 
    pass
164
 
else:
165
 
    encode_func[StaticTuple] = encode_list
166
 
 
167
155
 
168
156
def bencode(x):
169
157
    r = []