~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Robert Collins
  • Date: 2007-10-17 09:39:41 UTC
  • mfrom: (2911 +trunk)
  • mto: This revision was merged to the branch mainline in revision 2933.
  • Revision ID: robertc@robertcollins.net-20071017093941-v7d1djrt2617citb
Merge bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
49
49
    ca_bundle,
50
50
    _extract_headers,
51
51
    HttpTransportBase,
52
 
    _pycurl_errors,
53
52
    response,
54
53
    )
55
54
 
75
74
    raise DependencyNotPresent('pycurl', e)
76
75
 
77
76
 
 
77
 
 
78
 
 
79
def _get_pycurl_errcode(symbol, default):
 
80
    """
 
81
    Returns the numerical error code for a symbol defined by pycurl.
 
82
 
 
83
    Different pycurl implementations define different symbols for error
 
84
    codes. Old versions never define some symbols (wether they can return the
 
85
    corresponding error code or not). The following addresses the problem by
 
86
    defining the symbols we care about.  Note: this allows to define symbols
 
87
    for errors that older versions will never return, which is fine.
 
88
    """
 
89
    return pycurl.__dict__.get(symbol, default)
 
90
 
 
91
CURLE_SSL_CACERT_BADFILE = _get_pycurl_errcode('E_SSL_CACERT_BADFILE', 77)
 
92
CURLE_COULDNT_CONNECT = _get_pycurl_errcode('E_COULDNT_CONNECT', 7)
 
93
CURLE_COULDNT_RESOLVE_HOST = _get_pycurl_errcode('E_COULDNT_RESOLVE_HOST', 6)
 
94
CURLE_COULDNT_RESOLVE_PROXY = _get_pycurl_errcode('E_COULDNT_RESOLVE_PROXY', 5)
 
95
CURLE_GOT_NOTHING = _get_pycurl_errcode('E_GOT_NOTHING', 52)
 
96
CURLE_PARTIAL_FILE = _get_pycurl_errcode('E_PARTIAL_FILE', 18)
 
97
 
 
98
 
78
99
register_urlparse_netloc_protocol('http+pycurl')
79
100
 
80
101
 
269
290
        except pycurl.error, e:
270
291
            url = curl.getinfo(pycurl.EFFECTIVE_URL)
271
292
            mutter('got pycurl error: %s, %s, %s, url: %s ',
272
 
                    e[0], _pycurl_errors.errorcode[e[0]], e, url)
273
 
            if e[0] in (_pycurl_errors.CURLE_COULDNT_RESOLVE_HOST,
274
 
                        _pycurl_errors.CURLE_COULDNT_CONNECT,
275
 
                        _pycurl_errors.CURLE_GOT_NOTHING,
276
 
                        _pycurl_errors.CURLE_COULDNT_RESOLVE_PROXY):
 
293
                    e[0], e[1], e, url)
 
294
            if e[0] in (CURLE_SSL_CACERT_BADFILE,
 
295
                        CURLE_COULDNT_RESOLVE_HOST,
 
296
                        CURLE_COULDNT_CONNECT,
 
297
                        CURLE_GOT_NOTHING,
 
298
                        CURLE_COULDNT_RESOLVE_PROXY,):
277
299
                raise ConnectionError('curl connection error (%s)\non %s'
278
300
                              % (e[1], url))
279
 
            elif e[0] == _pycurl_errors.CURLE_PARTIAL_FILE:
 
301
            elif e[0] == CURLE_PARTIAL_FILE:
280
302
                # Pycurl itself has detected a short read.  We do
281
303
                # not have all the information for the
282
304
                # ShortReadvError, but that should be enough