~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: v.ladeuil+lp at free
  • Date: 2006-10-13 08:53:34 UTC
  • mto: (2145.1.1 keepalive)
  • mto: This revision was merged to the branch mainline in revision 2146.
  • Revision ID: v.ladeuil+lp@free.fr-20061013085334-e216654a3e842ff9
Fix bug #57644 by issuing an explicit error message.

* bzrlib/tests/test_http.py:
Fix some doc strings.
(TestForbiddenServer, TestForbiddenServer_urllib,
TestForbiddenServer_pycurl): Tests for correct handling of 403
error code.

* bzrlib/transport/http/_urllib2_wrappers.py:
Cleanup errors import and uses.
(HTTPDefaultErrorHandler.http_error_default): Handles 403 error code.

* bzrlib/transport/http/_pycurl.py:
(PyCurlTransport._raise_curl_http_error): Handles 403 error code.

* bzrlib/tests/HTTPTestUtil.py:
(ForbiddenRequestHandler): New class. An http server where
everything is forbidden.

Show diffs side-by-side

added added

removed removed

Lines of Context:
57
57
import sys
58
58
 
59
59
from bzrlib import __version__ as bzrlib_version
60
 
from bzrlib.errors import (
61
 
    BzrError,
62
 
    ConnectionError,
63
 
    InvalidHttpResponse,
64
 
    NoSuchFile,
65
 
    )
 
60
from bzrlib import errors
66
61
 
67
62
 
68
63
# We define our own Response class to keep our httplib pipe clean
220
215
        if not host:
221
216
            # Just a bit of paranoia here, this should have been
222
217
            # handled in the higher levels
223
 
            raise InvalidURL(request.get_full_url(), 'no host given.')
 
218
            raise errors.InvalidURL(request.get_full_url(), 'no host given.')
224
219
 
225
220
        # We create a connection (but it will not connect yet)
226
221
        connection = http_connection_class(host)
331
326
            convert_to_addinfourl = True
332
327
        except (httplib.BadStatusLine, httplib.UnknownProtocol), exception:
333
328
            # A bogus server was encountered
334
 
            raise InvalidHttpResponse(request.get_full_url(),
335
 
                                      'Bad status line received',
336
 
                                      orig_error=exception)
 
329
            raise errors.InvalidHttpResponse(request.get_full_url(),
 
330
                                             'Bad status line received',
 
331
                                             orig_error=exception)
337
332
        except (socket.error, httplib.HTTPException), exception:
338
333
            # httplib.HTTPException should indicate a bug in the
339
334
            # urllib implementation, somewhow the httplib
365
360
                response = self.do_open(http_class, request, False)
366
361
                convert_to_addinfourl = False
367
362
            else:
368
 
                my_exception = ConnectionError(msg= 'while sending %s %s:'
369
 
                                               % (request.get_method(),
370
 
                                                  request.get_selector()),
371
 
                                               orig_error=exception)
 
363
                my_exception = errors.ConnectionError(
 
364
                    msg= 'while sending %s %s:' % (request.get_method(),
 
365
                                                   request.get_selector()),
 
366
                    orig_error=exception)
372
367
                if self._debuglevel > 0:
373
368
                    print 'On connection: [%r]' % request.connection
374
369
                    method = request.get_method()
620
615
 
621
616
    def http_error_default(self, req, fp, code, msg, hdrs):
622
617
        if code == 404:
623
 
            raise NoSuchFile(req.get_selector(),
624
 
                             extra=HTTPError(req.get_full_url(), code, msg,
625
 
                                             hdrs, fp))
 
618
            raise errors.NoSuchFile(req.get_selector(),
 
619
                                    extra=HTTPError(req.get_full_url(),
 
620
                                                    code, msg,
 
621
                                                    hdrs, fp))
 
622
        elif code == 403:
 
623
            raise errors.TransportError('Server refuses to fullfil the request')
626
624
        else:
627
625
            # TODO: A test is needed to exercise that code path
628
 
            raise InvalidHttpResponse(req.get_full_url(),
629
 
                                      'Unable to handle http code %d: %s'
630
 
                                      % (code, msg))
 
626
            raise errors.InvalidHttpResponse(req.get_full_url(),
 
627
                                             'Unable to handle http code %d: %s'
 
628
                                             % (code, msg))
631
629
 
632
630
class Opener(object):
633
631
    """A wrapper around urllib2.build_opener