/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

Merge bzr.dev

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
232
232
        httplib.HTTPConnection.connect(self)
233
233
 
234
234
 
235
 
# 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
 
236
248
class HTTPSConnection(AbstractHTTPConnection, httplib.HTTPSConnection):
237
249
 
238
250
    def __init__(self, host, port=None, key_file=None, cert_file=None,
251
263
            self.connect_to_origin()
252
264
 
253
265
    def connect_to_origin(self):
254
 
        ssl = socket.ssl(self.sock, self.key_file, self.cert_file)
255
 
        self.sock = httplib.FakeSocket(self.sock, ssl)
 
266
        self.sock = _ssl_wrap_socket(self.sock, self.key_file, self.cert_file)
256
267
 
257
268
 
258
269
class Request(urllib2.Request):