~jelmer/brz/colocated-spec

« back to all changes in this revision

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

  • Committer: Jelmer Vernooij
  • Date: 2017-05-22 00:56:52 UTC
  • mfrom: (6621.2.26 py3_pokes)
  • Revision ID: jelmer@jelmer.uk-20170522005652-yjahcr9hwmjkno7n
Merge Python3 porting work ('py3 pokes')

Show diffs side-by-side

added added

removed removed

Lines of Context:
33
33
# from _curl_perform.  Not done because we may deprecate pycurl in the
34
34
# future -- vila 20070212
35
35
 
36
 
from cStringIO import StringIO
37
36
import httplib
38
37
 
39
38
import breezy
40
 
from breezy import (
 
39
from ... import (
41
40
    debug,
42
41
    errors,
43
42
    trace,
44
43
    )
45
 
from breezy.transport.http import (
 
44
from ...sixish import (
 
45
    BytesIO,
 
46
    )
 
47
from ...transport.http import (
46
48
    ca_bundle,
47
49
    HttpTransportBase,
48
50
    response,
51
53
 
52
54
try:
53
55
    import pycurl
54
 
except ImportError, e:
 
56
except ImportError as e:
55
57
    trace.mutter("failed to import pycurl: %s", e)
56
58
    raise errors.DependencyNotPresent('pycurl', e)
57
59
 
66
68
    #
67
69
    # reported by Alexander Belchenko, 2006-04-26
68
70
    pycurl.Curl()
69
 
except pycurl.error, e:
 
71
except pycurl.error as e:
70
72
    trace.mutter("failed to initialize pycurl: %s", e)
71
73
    raise errors.DependencyNotPresent('pycurl', e)
72
74
 
152
154
        # This means "NO BODY" not 'nobody'
153
155
        curl.setopt(pycurl.NOBODY, 1)
154
156
        # But we need headers to handle redirections
155
 
        header = StringIO()
 
157
        header = BytesIO()
156
158
        curl.setopt(pycurl.HEADERFUNCTION, header.write)
157
159
        # In some erroneous cases, pycurl will emit text on
158
160
        # stdout if we don't catch it (see InvalidStatus tests
159
161
        # for one such occurrence).
160
 
        blackhole = StringIO()
 
162
        blackhole = BytesIO()
161
163
        curl.setopt(pycurl.WRITEFUNCTION, blackhole.write)
162
164
        self._curl_perform(curl, header)
163
165
        code = curl.getinfo(pycurl.HTTP_CODE)
197
199
        curl.setopt(pycurl.URL, abspath)
198
200
        self._set_curl_options(curl)
199
201
 
200
 
        data = StringIO()
201
 
        header = StringIO()
 
202
        data = BytesIO()
 
203
        header = BytesIO()
202
204
        curl.setopt(pycurl.WRITEFUNCTION, data.write)
203
205
        curl.setopt(pycurl.HEADERFUNCTION, header.write)
204
206
 
267
269
        curl = self._get_curl()
268
270
        abspath, data, header = self._setup_request(curl, '.bzr/smart')
269
271
        curl.setopt(pycurl.POST, 1)
270
 
        fake_file = StringIO(body_bytes)
 
272
        fake_file = BytesIO(body_bytes)
271
273
        curl.setopt(pycurl.POSTFIELDSIZE, len(body_bytes))
272
274
        curl.setopt(pycurl.READFUNCTION, fake_file.read)
273
275
        # We override the Expect: header so that pycurl will send the POST
276
278
            self._curl_perform(curl, header,
277
279
                               ['Expect: ',
278
280
                                'Content-Type: application/octet-stream'])
279
 
        except pycurl.error, e:
 
281
        except pycurl.error as e:
280
282
            if e[0] == CURLE_SEND_ERROR:
281
283
                # When talking to an HTTP/1.0 server, getting a 400+ error code
282
284
                # triggers a bug in some combinations of curl/kernel in rare
393
395
                       'Connection: Keep-Alive']
394
396
            curl.setopt(pycurl.HTTPHEADER, headers + more_headers)
395
397
            curl.perform()
396
 
        except pycurl.error, e:
 
398
        except pycurl.error as e:
397
399
            url = curl.getinfo(pycurl.EFFECTIVE_URL)
398
400
            trace.mutter('got pycurl error: %s, %s, %s, url: %s ',
399
401
                         e[0], e[1], e, url)
431
433
 
432
434
def get_test_permutations():
433
435
    """Return the permutations to be used in testing."""
434
 
    from breezy.tests import features
435
 
    from breezy.tests import http_server
 
436
    from ...tests import features
 
437
    from ...tests import http_server
436
438
    permutations = [(PyCurlTransport, http_server.HttpServer_PyCurl),]
437
439
    if features.HTTPSServerFeature.available():
438
 
        from breezy.tests import (
 
440
        from ...tests import (
439
441
            https_server,
440
442
            ssl_certs,
441
443
            )