/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 08:58:15 UTC
  • mfrom: (5609.48.2 2.3)
  • mto: (6012.1.1 trunk)
  • mto: This revision was merged to the branch mainline in revision 6013.
  • Revision ID: v.ladeuil+lp@free.fr-20110706085815-6leauod52jq2u43d
MergingĀ inĀ 2.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006 Canonical Ltd
 
1
# Copyright (C) 2006-2010 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
44
44
    ca_bundle,
45
45
    HttpTransportBase,
46
46
    response,
 
47
    unhtml_roughly,
47
48
    )
48
49
 
49
50
try:
128
129
            self._set_connection(connection, auth)
129
130
        return connection
130
131
 
 
132
    def disconnect(self):
 
133
        connection = self._get_connection()
 
134
        if connection is not None:
 
135
            connection.close()
 
136
 
131
137
    def has(self, relpath):
132
138
        """See Transport.has()"""
133
139
        # We set NO BODY=0 in _get_full, so it should be safe
287
293
        return code, response.handle_response(abspath, code, msg, data)
288
294
 
289
295
 
290
 
    def _raise_curl_http_error(self, curl, info=None):
 
296
    def _raise_curl_http_error(self, curl, info=None, body=None):
 
297
        """Common curl->bzrlib error translation.
 
298
 
 
299
        Some methods may choose to override this for particular cases.
 
300
 
 
301
        The URL and code are automatically included as appropriate.
 
302
 
 
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.
 
305
        """
291
306
        code = curl.getinfo(pycurl.HTTP_CODE)
292
307
        url = curl.getinfo(pycurl.EFFECTIVE_URL)
293
 
        # Some error codes can be handled the same way for all
294
 
        # requests
 
308
        if body is not None:
 
309
            response_body = body.read()
 
310
            plaintext_body = unhtml_roughly(response_body)
 
311
        else:
 
312
            response_body = None
 
313
            plaintext_body = ''
295
314
        if code == 403:
296
315
            raise errors.TransportError(
297
316
                'Server refuses to fulfill the request (403 Forbidden)'
298
 
                ' for %s' % url)
 
317
                ' for %s: %s' % (url, plaintext_body))
299
318
        else:
300
319
            if info is None:
301
320
                msg = ''
302
321
            else:
303
322
                msg = ': ' + info
304
323
            raise errors.InvalidHttpResponse(
305
 
                url, 'Unable to handle http code %d%s' % (code,msg))
 
324
                url, 'Unable to handle http code %d%s: %s' 
 
325
                % (code, msg, plaintext_body))
306
326
 
307
327
    def _debug_cb(self, kind, text):
308
328
        if kind in (pycurl.INFOTYPE_HEADER_IN, pycurl.INFOTYPE_DATA_IN,