~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Vincent Ladeuil
  • Date: 2007-11-30 17:48:41 UTC
  • mfrom: (3052.3.4 172701)
  • mto: This revision was merged to the branch mainline in revision 3060.
  • Revision ID: v.ladeuil+lp@free.fr-20071130174841-6yitg1imn504sttr
Fix bug #172701 by catching the pycurl ShortReadvError and allowing readv to issue several get requests

Show diffs side-by-side

added added

removed removed

Lines of Context:
32
32
handle authentication schemes.
33
33
"""
34
34
 
 
35
# TODO: now that we have -Dhttp most of the needs should be covered in a more
 
36
# accessible way (i.e. no need to edit the source), if experience confirms
 
37
# that, delete all DEBUG uses -- vila20071130 (happy birthday).
35
38
DEBUG = 0
36
39
 
37
40
# FIXME: Oversimplifying, two kind of exceptions should be
56
59
from bzrlib import __version__ as bzrlib_version
57
60
from bzrlib import (
58
61
    config,
 
62
    debug,
59
63
    errors,
 
64
    trace,
60
65
    transport,
61
66
    ui,
62
67
    )
101
106
                # having issued the response headers (even if the
102
107
                # headers indicate a Content-Type...)
103
108
                body = self.fp.read(self.length)
104
 
                if self.debuglevel > 0:
 
109
                if self.debuglevel > 3:
 
110
                    # This one can be huge and is generally not interesting
105
111
                    print "Consumed body: [%s]" % body
106
112
            self.close()
107
113
        elif self.status == 200:
143
149
 
144
150
    # XXX: Needs refactoring at the caller level.
145
151
    def __init__(self, host, port=None, strict=None, proxied_host=None):
 
152
        if 'http' in debug.debug_flags:
 
153
            netloc = host
 
154
            if port is not None:
 
155
                netloc += '%d' % port
 
156
            if proxied_host is not None:
 
157
                netloc += '(proxy for %s)' % proxied_host
 
158
            trace.mutter('* About to connect() to %s' % netloc)
146
159
        httplib.HTTPConnection.__init__(self, host, port, strict)
147
160
        self.proxied_host = proxied_host
148
161
 
425
438
        headers.update(request.unredirected_hdrs)
426
439
 
427
440
        try:
428
 
            connection._send_request(request.get_method(),
429
 
                                     request.get_selector(),
 
441
            method = request.get_method()
 
442
            url = request.get_selector()
 
443
            connection._send_request(method, url,
430
444
                                     # FIXME: implements 100-continue
431
445
                                     #None, # We don't send the body yet
432
446
                                     request.get_data(),
433
447
                                     headers)
 
448
            if 'http' in debug.debug_flags:
 
449
                trace.mutter('> %s %s' % (method, url))
 
450
                hdrs = ['%s: %s' % (k, v) for k,v in headers.items()]
 
451
                trace.mutter('> ' + '\n> '.join(hdrs) + '\n')
434
452
            if self._debuglevel > 0:
435
453
                print 'Request sent: [%r]' % request
436
454
            response = connection.getresponse()
453
471
#            connection.send(body)
454
472
#            response = connection.getresponse()
455
473
 
 
474
        if 'http' in debug.debug_flags:
 
475
            version = 'HTTP/%d.%d'
 
476
            try:
 
477
                version = version % (response.version / 10,
 
478
                                     response.version % 10)
 
479
            except:
 
480
                version = 'HTTP/%r' % version
 
481
            trace.mutter('< %s %s %s' % (version, response.status,
 
482
                                            response.reason))
 
483
            hdrs = [h.rstrip('\r\n') for h in response.msg.headers]
 
484
            trace.mutter('< ' + '\n< '.join(hdrs) + '\n')
456
485
        if self._debuglevel > 0:
457
486
            print 'Receives response: %r' % response
458
487
            print '  For: %r(%r)' % (request.get_method(),
1285
1314
            )
1286
1315
 
1287
1316
        self.open = self._opener.open
1288
 
        if DEBUG >= 2:
 
1317
        if DEBUG >= 3:
1289
1318
            # When dealing with handler order, it's easy to mess
1290
1319
            # things up, the following will help understand which
1291
1320
            # handler is used, when and for what.