Beispiel #1
0
    def _raise_curl_http_error(self, curl, info=None, body=None):
        """Common curl->bzrlib error translation.

        Some methods may choose to override this for particular cases.

        The URL and code are automatically included as appropriate.

        :param info: Extra information to include in the message.

        :param body: File-like object from which the body of the page can be
            read.
        """
        code = curl.getinfo(pycurl.HTTP_CODE)
        url = curl.getinfo(pycurl.EFFECTIVE_URL)
        if body is not None:
            response_body = body.read()
            plaintext_body = unhtml_roughly(response_body)
        else:
            response_body = None
            plaintext_body = ''
        if code == 403:
            raise errors.TransportError(
                'Server refuses to fulfill the request (403 Forbidden)'
                ' for %s: %s' % (url, plaintext_body))
        else:
            if info is None:
                msg = ''
            else:
                msg = ': ' + info
            raise errors.InvalidHttpResponse(
                url, 'Unable to handle http code %d%s: %s'
                % (code, msg, plaintext_body))
Beispiel #2
0
    def _raise_curl_http_error(self, curl, info=None, body=None):
        """Common curl->bzrlib error translation.

        Some methods may choose to override this for particular cases.

        The URL and code are automatically included as appropriate.

        :param info: Extra information to include in the message.

        :param body: File-like object from which the body of the page can be
            read.
        """
        code = curl.getinfo(pycurl.HTTP_CODE)
        url = curl.getinfo(pycurl.EFFECTIVE_URL)
        if body is not None:
            response_body = body.read()
            plaintext_body = unhtml_roughly(response_body)
        else:
            response_body = None
            plaintext_body = ''
        if code == 403:
            raise errors.TransportError(
                'Server refuses to fulfill the request (403 Forbidden)'
                ' for %s: %s' % (url, plaintext_body))
        else:
            if info is None:
                msg = ''
            else:
                msg = ': ' + info
            raise errors.InvalidHttpResponse(
                url, 'Unable to handle http code %d%s: %s'
                % (code, msg, plaintext_body))
Beispiel #3
0
 def test_truncation(self):
     fake_html = "<p>something!\n" * 1000
     result = http.unhtml_roughly(fake_html)
     self.assertEquals(len(result), 1000)
     self.assertStartsWith(result, " something!")
 def test_truncation(self):
     fake_html = "<p>something!\n" * 1000
     result = http.unhtml_roughly(fake_html)
     self.assertEqual(len(result), 1000)
     self.assertStartsWith(result, " something!")