/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

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

  • Committer: Vincent Ladeuil
  • Date: 2011-07-06 09:22:00 UTC
  • mfrom: (6008 +trunk)
  • mto: (6012.1.1 trunk)
  • mto: This revision was merged to the branch mainline in revision 6013.
  • Revision ID: v.ladeuil+lp@free.fr-20110706092200-7iai2mwzc0sqdsvf
MergingĀ inĀ trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
37
37
from bzrlib import (
38
38
    debug,
39
39
    errors,
 
40
    trace,
40
41
    )
41
42
import bzrlib
42
 
from bzrlib.trace import mutter
43
43
from bzrlib.transport.http import (
44
44
    ca_bundle,
45
45
    HttpTransportBase,
50
50
try:
51
51
    import pycurl
52
52
except ImportError, e:
53
 
    mutter("failed to import pycurl: %s", e)
 
53
    trace.mutter("failed to import pycurl: %s", e)
54
54
    raise errors.DependencyNotPresent('pycurl', e)
55
55
 
56
56
try:
65
65
    # reported by Alexander Belchenko, 2006-04-26
66
66
    pycurl.Curl()
67
67
except pycurl.error, e:
68
 
    mutter("failed to initialize pycurl: %s", e)
 
68
    trace.mutter("failed to initialize pycurl: %s", e)
69
69
    raise errors.DependencyNotPresent('pycurl', e)
70
70
 
71
71
 
282
282
                # error code and the headers are known to be available, we just
283
283
                # swallow the exception, leaving the upper levels handle the
284
284
                # 400+ error.
285
 
                mutter('got pycurl error in POST: %s, %s, %s, url: %s ',
286
 
                       e[0], e[1], e, abspath)
 
285
                trace.mutter('got pycurl error in POST: %s, %s, %s, url: %s ',
 
286
                             e[0], e[1], e, abspath)
287
287
            else:
288
288
                # Re-raise otherwise
289
289
                raise
301
301
        The URL and code are automatically included as appropriate.
302
302
 
303
303
        :param info: Extra information to include in the message.
304
 
        :param body: File-like object from which the body of the page can be read.
 
304
 
 
305
        :param body: File-like object from which the body of the page can be
 
306
            read.
305
307
        """
306
308
        code = curl.getinfo(pycurl.HTTP_CODE)
307
309
        url = curl.getinfo(pycurl.EFFECTIVE_URL)
321
323
            else:
322
324
                msg = ': ' + info
323
325
            raise errors.InvalidHttpResponse(
324
 
                url, 'Unable to handle http code %d%s: %s' 
 
326
                url, 'Unable to handle http code %d%s: %s'
325
327
                % (code, msg, plaintext_body))
326
328
 
327
329
    def _debug_cb(self, kind, text):
330
332
            self._report_activity(len(text), 'read')
331
333
            if (kind == pycurl.INFOTYPE_HEADER_IN
332
334
                and 'http' in debug.debug_flags):
333
 
                mutter('< %s' % text)
 
335
                trace.mutter('< %s' % (text.rstrip(),))
334
336
        elif kind in (pycurl.INFOTYPE_HEADER_OUT, pycurl.INFOTYPE_DATA_OUT,
335
337
                      pycurl.INFOTYPE_SSL_DATA_OUT):
336
338
            self._report_activity(len(text), 'write')
337
339
            if (kind == pycurl.INFOTYPE_HEADER_OUT
338
340
                and 'http' in debug.debug_flags):
339
 
                mutter('> %s' % text)
 
341
                lines = []
 
342
                for line in text.rstrip().splitlines():
 
343
                    # People are often told to paste -Dhttp output to help
 
344
                    # debug. Don't compromise credentials.
 
345
                    try:
 
346
                        header, details = line.split(':', 1)
 
347
                    except ValueError:
 
348
                        header = None
 
349
                    if header in ('Authorization', 'Proxy-Authorization'):
 
350
                        line = '%s: <masked>' % (header,)
 
351
                    lines.append(line)
 
352
                trace.mutter('> ' + '\n> '.join(lines))
340
353
        elif kind == pycurl.INFOTYPE_TEXT and 'http' in debug.debug_flags:
341
 
            mutter('* %s' % text)
 
354
            trace.mutter('* %s' % text.rstrip())
342
355
 
343
356
    def _set_curl_options(self, curl):
344
357
        """Set options for all requests"""
375
388
            curl.perform()
376
389
        except pycurl.error, e:
377
390
            url = curl.getinfo(pycurl.EFFECTIVE_URL)
378
 
            mutter('got pycurl error: %s, %s, %s, url: %s ',
379
 
                    e[0], e[1], e, url)
 
391
            trace.mutter('got pycurl error: %s, %s, %s, url: %s ',
 
392
                         e[0], e[1], e, url)
380
393
            if e[0] in (CURLE_COULDNT_RESOLVE_HOST,
381
394
                        CURLE_COULDNT_RESOLVE_PROXY,
382
395
                        CURLE_COULDNT_CONNECT,