1
# Copyright (C) 2006 Canonical Ltd
1
# Copyright (C) 2006-2010 Canonical Ltd
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
128
129
self._set_connection(connection, auth)
129
130
return connection
132
def disconnect(self):
133
connection = self._get_connection()
134
if connection is not None:
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)
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.
299
Some methods may choose to override this for particular cases.
301
The URL and code are automatically included as appropriate.
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.
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
309
response_body = body.read()
310
plaintext_body = unhtml_roughly(response_body)
296
315
raise errors.TransportError(
297
316
'Server refuses to fulfill the request (403 Forbidden)'
317
' for %s: %s' % (url, plaintext_body))
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))
307
327
def _debug_cb(self, kind, text):
308
328
if kind in (pycurl.INFOTYPE_HEADER_IN, pycurl.INFOTYPE_DATA_IN,