~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2007-11-30 18:21:02 UTC
  • mfrom: (3059.1.1 trunk)
  • Revision ID: pqm@pqm.ubuntu.com-20071130182102-i0t564k01anm7uk2
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:
36
36
import sys
37
37
 
38
38
from bzrlib import (
 
39
    debug,
39
40
    errors,
 
41
    trace,
40
42
    __version__ as bzrlib_version,
41
43
    )
42
44
import bzrlib
43
 
from bzrlib.errors import (NoSuchFile,
44
 
                           ConnectionError,
45
 
                           DependencyNotPresent)
46
45
from bzrlib.trace import mutter
47
46
from bzrlib.transport.http import (
48
47
    ca_bundle,
55
54
    import pycurl
56
55
except ImportError, e:
57
56
    mutter("failed to import pycurl: %s", e)
58
 
    raise DependencyNotPresent('pycurl', e)
 
57
    raise errors.DependencyNotPresent('pycurl', e)
59
58
 
60
59
try:
61
60
    # see if we can actually initialize PyCurl - sometimes it will load but
70
69
    pycurl.Curl()
71
70
except pycurl.error, e:
72
71
    mutter("failed to initialize pycurl: %s", e)
73
 
    raise DependencyNotPresent('pycurl', e)
 
72
    raise errors.DependencyNotPresent('pycurl', e)
74
73
 
75
74
 
76
75
 
112
111
            # protocols
113
112
            supported = pycurl.version_info()[8]
114
113
            if 'https' not in supported:
115
 
                raise DependencyNotPresent('pycurl', 'no https support')
 
114
                raise errors.DependencyNotPresent('pycurl', 'no https support')
116
115
        self.cabundle = ca_bundle.get_ca_path()
117
116
 
118
117
    def _get_curl(self):
202
201
        data.seek(0)
203
202
 
204
203
        if code == 404:
205
 
            raise NoSuchFile(abspath)
 
204
            raise errors.NoSuchFile(abspath)
206
205
        if code != 200:
207
206
            self._raise_curl_http_error(
208
207
                curl, 'expected 200 or 404 for full response.')
264
263
 
265
264
    def _set_curl_options(self, curl):
266
265
        """Set options for all requests"""
267
 
        ## curl.setopt(pycurl.VERBOSE, 1)
268
 
        # TODO: maybe include a summary of the pycurl version
269
 
        ua_str = 'bzr/%s (pycurl)' % (bzrlib.__version__,)
 
266
        if 'http' in debug.debug_flags:
 
267
            curl.setopt(pycurl.VERBOSE, 1)
 
268
            # pycurl doesn't implement the CURLOPT_STDERR option, so we can't
 
269
            # do : curl.setopt(pycurl.STDERR, trace._trace_file)
 
270
 
 
271
        ua_str = 'bzr/%s (pycurl: %s)' % (bzrlib.__version__, pycurl.version)
270
272
        curl.setopt(pycurl.USERAGENT, ua_str)
271
273
        if self.cabundle:
272
274
            curl.setopt(pycurl.CAINFO, self.cabundle)
292
294
                        CURLE_COULDNT_CONNECT,
293
295
                        CURLE_GOT_NOTHING,
294
296
                        CURLE_COULDNT_RESOLVE_PROXY,):
295
 
                raise ConnectionError('curl connection error (%s)\non %s'
296
 
                              % (e[1], url))
 
297
                raise errors.ConnectionError(
 
298
                    'curl connection error (%s)\non %s' % (e[1], url))
297
299
            elif e[0] == CURLE_PARTIAL_FILE:
298
300
                # Pycurl itself has detected a short read.  We do
299
301
                # not have all the information for the