~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Tarmac
  • Author(s): Vincent Ladeuil
  • Date: 2017-01-30 14:42:05 UTC
  • mfrom: (6620.1.1 trunk)
  • Revision ID: tarmac-20170130144205-r8fh2xpmiuxyozpv
Merge  2.7 into trunk including fix for bug #1657238 [r=vila]

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006-2010 Canonical Ltd
 
1
# Copyright (C) 2006-2011, 2017 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
16
16
 
17
17
"""http/https transport using pycurl"""
18
18
 
 
19
from __future__ import absolute_import
 
20
 
19
21
# TODO: test reporting of http errors
20
22
#
21
23
# TODO: Transport option to control caching of particular requests; broadly we
34
36
from cStringIO import StringIO
35
37
import httplib
36
38
 
 
39
import bzrlib
37
40
from bzrlib import (
38
41
    debug,
39
42
    errors,
40
43
    trace,
41
44
    )
42
 
import bzrlib
43
45
from bzrlib.transport.http import (
44
46
    ca_bundle,
45
47
    HttpTransportBase,
83
85
    """
84
86
    return pycurl.__dict__.get(symbol, default)
85
87
 
 
88
# Yes, weird but returned on weird http error (invalid status line)
 
89
CURLE_FTP_WEIRD_SERVER_REPLY = _get_pycurl_errcode(
 
90
    'E_FTP_WEIRD_SERVER_REPLY', 8)
86
91
CURLE_COULDNT_CONNECT = _get_pycurl_errcode('E_COULDNT_CONNECT', 7)
87
92
CURLE_COULDNT_RESOLVE_HOST = _get_pycurl_errcode('E_COULDNT_RESOLVE_HOST', 6)
88
93
CURLE_COULDNT_RESOLVE_PROXY = _get_pycurl_errcode('E_COULDNT_RESOLVE_PROXY', 5)
327
332
                % (code, msg, plaintext_body))
328
333
 
329
334
    def _debug_cb(self, kind, text):
330
 
        if kind in (pycurl.INFOTYPE_HEADER_IN, pycurl.INFOTYPE_DATA_IN,
331
 
                    pycurl.INFOTYPE_SSL_DATA_IN):
 
335
        if kind in (pycurl.INFOTYPE_HEADER_IN, pycurl.INFOTYPE_DATA_IN):
332
336
            self._report_activity(len(text), 'read')
333
337
            if (kind == pycurl.INFOTYPE_HEADER_IN
334
338
                and 'http' in debug.debug_flags):
335
339
                trace.mutter('< %s' % (text.rstrip(),))
336
 
        elif kind in (pycurl.INFOTYPE_HEADER_OUT, pycurl.INFOTYPE_DATA_OUT,
337
 
                      pycurl.INFOTYPE_SSL_DATA_OUT):
 
340
        elif kind in (pycurl.INFOTYPE_HEADER_OUT, pycurl.INFOTYPE_DATA_OUT):
338
341
            self._report_activity(len(text), 'write')
339
342
            if (kind == pycurl.INFOTYPE_HEADER_OUT
340
343
                and 'http' in debug.debug_flags):
352
355
                trace.mutter('> ' + '\n> '.join(lines))
353
356
        elif kind == pycurl.INFOTYPE_TEXT and 'http' in debug.debug_flags:
354
357
            trace.mutter('* %s' % text.rstrip())
 
358
        elif (kind in (pycurl.INFOTYPE_TEXT, pycurl.INFOTYPE_SSL_DATA_IN,
 
359
                       pycurl.INFOTYPE_SSL_DATA_OUT)
 
360
              and 'http' in debug.debug_flags):
 
361
            trace.mutter('* %s' % text)
355
362
 
356
363
    def _set_curl_options(self, curl):
357
364
        """Set options for all requests"""
393
400
            if e[0] in (CURLE_COULDNT_RESOLVE_HOST,
394
401
                        CURLE_COULDNT_RESOLVE_PROXY,
395
402
                        CURLE_COULDNT_CONNECT,
 
403
                        CURLE_FTP_WEIRD_SERVER_REPLY,
396
404
                        CURLE_GOT_NOTHING,
397
405
                        CURLE_SSL_CACERT,
398
406
                        CURLE_SSL_CACERT_BADFILE,
423
431
 
424
432
def get_test_permutations():
425
433
    """Return the permutations to be used in testing."""
426
 
    from bzrlib import tests
 
434
    from bzrlib.tests import features
427
435
    from bzrlib.tests import http_server
428
436
    permutations = [(PyCurlTransport, http_server.HttpServer_PyCurl),]
429
 
    if tests.HTTPSServerFeature.available():
 
437
    if features.HTTPSServerFeature.available():
430
438
        from bzrlib.tests import (
431
439
            https_server,
432
440
            ssl_certs,