/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

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

  • Committer: Ian Clatworthy
  • Date: 2008-12-15 06:18:29 UTC
  • mfrom: (3905 +trunk)
  • mto: (3586.1.23 views-ui)
  • mto: This revision was merged to the branch mainline in revision 4030.
  • Revision ID: ian.clatworthy@canonical.com-20081215061829-c8qwa93g71u9fsh5
merge bzr.dev 3905

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006, 2007 Canonical Ltd
 
1
# Copyright (C) 2006, 2007, 2008 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
47
47
# ensure that.
48
48
 
49
49
import httplib
50
 
import md5
51
 
import sha
52
50
import socket
53
51
import urllib
54
52
import urllib2
62
60
    config,
63
61
    debug,
64
62
    errors,
 
63
    osutils,
65
64
    trace,
66
65
    transport,
67
66
    ui,
233
232
        httplib.HTTPConnection.connect(self)
234
233
 
235
234
 
236
 
# FIXME: Should test for ssl availability
 
235
# Build the appropriate socket wrapper for ssl
 
236
try:
 
237
    # python 2.6 introduced a better ssl package
 
238
    import ssl
 
239
    _ssl_wrap_socket = ssl.wrap_socket
 
240
except ImportError:
 
241
    # python versions prior to 2.6 don't have ssl and ssl.wrap_socket instead
 
242
    # they use httplib.FakeSocket
 
243
    def _ssl_wrap_socket(sock, key_file, cert_file):
 
244
        ssl_sock = socket.ssl(sock, key_file, cert_file)
 
245
        return httplib.FakeSocket(sock, ssl_sock)
 
246
 
 
247
 
237
248
class HTTPSConnection(AbstractHTTPConnection, httplib.HTTPSConnection):
238
249
 
239
250
    def __init__(self, host, port=None, key_file=None, cert_file=None,
252
263
            self.connect_to_origin()
253
264
 
254
265
    def connect_to_origin(self):
255
 
        ssl = socket.ssl(self.sock, self.key_file, self.cert_file)
256
 
        self.sock = httplib.FakeSocket(self.sock, ssl)
 
266
        self.sock = _ssl_wrap_socket(self.sock, self.key_file, self.cert_file)
257
267
 
258
268
 
259
269
class Request(urllib2.Request):
1123
1133
    H = None
1124
1134
    KD = None
1125
1135
    if algorithm == 'MD5':
1126
 
        H = lambda x: md5.new(x).hexdigest()
 
1136
        H = lambda x: osutils.md5(x).hexdigest()
1127
1137
    elif algorithm == 'SHA':
1128
 
        H = lambda x: sha.new(x).hexdigest()
 
1138
        H = lambda x: osutils.sha(x).hexdigest()
1129
1139
    if H is not None:
1130
1140
        KD = lambda secret, data: H("%s:%s" % (secret, data))
1131
1141
    return H, KD
1134
1144
def get_new_cnonce(nonce, nonce_count):
1135
1145
    raw = '%s:%d:%s:%s' % (nonce, nonce_count, time.ctime(),
1136
1146
                           urllib2.randombytes(8))
1137
 
    return sha.new(raw).hexdigest()[:16]
 
1147
    return osutils.sha(raw).hexdigest()[:16]
1138
1148
 
1139
1149
 
1140
1150
class DigestAuthHandler(AbstractAuthHandler):