/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 and resolve conflicts.

Show diffs side-by-side

added added

removed removed

Lines of Context:
30
30
 
31
31
And a custom Request class that lets us track redirections, and
32
32
handle authentication schemes.
 
33
 
 
34
For coherency with python libraries, we use capitalized header names throughout
 
35
the code, even if the header names will be titled just before sending the
 
36
request (see AbstractHTTPHandler.do_open).
33
37
"""
34
38
 
35
39
DEBUG = 0
309
313
        # confused
310
314
        Request.__init__(self, 'CONNECT', request.get_full_url(),
311
315
                         connection=request.connection)
312
 
        assert request.proxied_host is not None
 
316
        if request.proxied_host is None:
 
317
            raise AssertionError()
313
318
        self.proxied_host = request.proxied_host
314
319
 
315
320
    def get_selector(self):
406
411
    _default_headers = {'Pragma': 'no-cache',
407
412
                        'Cache-control': 'max-age=0',
408
413
                        'Connection': 'Keep-Alive',
409
 
                        # FIXME: Spell it User-*A*gent once we
410
 
                        # know how to properly avoid bogus
411
 
                        # urllib2 using capitalize() for headers
412
 
                        # instead of title(sp?).
413
414
                        'User-agent': 'bzr/%s (urllib)' % bzrlib_version,
414
415
                        'Accept': '*/*',
415
416
                        }
502
503
        The request will be retried once if it fails.
503
504
        """
504
505
        connection = request.connection
505
 
        assert connection is not None, \
506
 
            'Cannot process a request without a connection'
 
506
        if connection is None:
 
507
            raise AssertionError(
 
508
                'Cannot process a request without a connection')
507
509
 
508
510
        # Get all the headers
509
511
        headers = {}
510
512
        headers.update(request.header_items())
511
513
        headers.update(request.unredirected_hdrs)
 
514
        # Some servers or proxies will choke on headers not properly
 
515
        # cased. httplib/urllib/urllib2 all use capitalize to get canonical
 
516
        # header names, but only python2.5 urllib2 use title() to fix them just
 
517
        # before sending the request. And not all versions of python 2.5 do
 
518
        # that. Since we replace urllib2.AbstractHTTPHandler.do_open we do it
 
519
        # ourself below.
 
520
        headers = dict((name.title(), val) for name, val in headers.iteritems())
512
521
 
513
522
        try:
514
523
            method = request.get_method()
595
604
 
596
605
    def https_open(self, request):
597
606
        connection = request.connection
598
 
        assert isinstance(connection, HTTPSConnection)
599
607
        if connection.sock is None and \
600
608
                connection.proxied_host is not None and \
601
609
                request.get_method() != 'CONNECT' : # Don't loop
1333
1341
 
1334
1342
    def http_error_default(self, req, fp, code, msg, hdrs):
1335
1343
        if code == 403:
1336
 
            raise errors.TransportError('Server refuses to fullfil the request')
 
1344
            raise errors.TransportError(
 
1345
                'Server refuses to fulfill the request (403 Forbidden)'
 
1346
                ' for %s' % req.get_full_url())
1337
1347
        else:
1338
1348
            raise errors.InvalidHttpResponse(req.get_full_url(),
1339
1349
                                             'Unable to handle http code %d: %s'