Example #1
0
    def test_traceback_info(self):
        # LaunchpadFormatter inherits from zope.exceptions.log.Formatter, so
        # __traceback_info__ annotations are included in formatted exceptions.

        traceback_info("Captain Kirk")

        try:
            0 / 0
        except ZeroDivisionError:
            info = exc_info()

        self.assertThat(
            LaunchpadFormatter().formatException(info),
            DocTestMatches(
                flags=DOCTEST_FLAGS, example="""
                    Traceback (most recent call last):
                    ...
                    __traceback_info__: Captain Kirk
                    ZeroDivisionError: ...
                    """))
    def test_traceback_info(self):
        # LaunchpadFormatter inherits from zope.exceptions.log.Formatter, so
        # __traceback_info__ annotations are included in formatted exceptions.

        traceback_info("Captain Kirk")

        try:
            0/0
        except ZeroDivisionError:
            info = exc_info()

        self.assertThat(
            LaunchpadFormatter().formatException(info),
            DocTestMatches(
                flags=DOCTEST_FLAGS, example="""
                    Traceback (most recent call last):
                    ...
                    __traceback_info__: Captain Kirk
                    ZeroDivisionError: ...
                    """))
Example #3
0
    def request(self, host, handler, request_body, verbose=0):
        """Make an XMLRPC request.

        Uses the configured proxy server to make the connection.
        """
        url = urlunparse((self.scheme, host, handler, '', '', ''))
        headers = {'Content-type': 'text/xml'}
        request = Request(url, request_body, headers)
        try:
            response = self.opener.open(request, timeout=self.timeout).read()
        except HTTPError as he:
            raise ProtocolError(
                request.get_full_url(), he.code, he.msg, he.hdrs)
        else:
            traceback_info(response)
            # In Python2.6 the api is self._parse_response, in 2.7 it is
            # self.parse_response and no longer takes the 'sock' argument
            parse = getattr(self, '_parse_response', None)
            if parse is not None:
                # Compatibility with python 2.6
                return parse(StringIO(response), None)
            return self.parse_response(StringIO(response))
Example #4
0
    def request(self, host, handler, request_body, verbose=0):
        """Make an XMLRPC request.

        Uses the configured proxy server to make the connection.
        """
        url = urlunparse((self.scheme, host, handler, '', '', ''))
        headers = {'Content-type': 'text/xml'}
        request = Request(url, request_body, headers)
        try:
            response = self.opener.open(request, timeout=self.timeout).read()
        except HTTPError as he:
            raise ProtocolError(request.get_full_url(), he.code, he.msg,
                                he.hdrs)
        else:
            traceback_info(response)
            # In Python2.6 the api is self._parse_response, in 2.7 it is
            # self.parse_response and no longer takes the 'sock' argument
            parse = getattr(self, '_parse_response', None)
            if parse is not None:
                # Compatibility with python 2.6
                return parse(StringIO(response), None)
            return self.parse_response(StringIO(response))
Example #5
0
    def request(self, host, handler, request_body, verbose=0):
        """Make an XMLRPC request.

        Uses the configured proxy server to make the connection.
        """
        url = urlunparse((self.scheme, host, handler, '', '', ''))
        # httplib can raise a UnicodeDecodeError when using a Unicode
        # URL, a non-ASCII body and a proxy. http://bugs.python.org/issue12398
        url = six.ensure_binary(url)
        try:
            with override_timeout(self.timeout):
                response = urlfetch(
                    url, method='POST', headers={'Content-Type': 'text/xml'},
                    data=request_body, cookies=self.cookie_jar,
                    hooks={'response': repost_on_redirect_hook},
                    use_proxy=True)
        except requests.HTTPError as e:
            raise ProtocolError(
                url.decode('utf-8'), e.response.status_code, e.response.reason,
                e.response.headers)
        else:
            traceback_info(response.text)
            return self.parse_response(BytesIO(response.content))
Example #6
0
 def test(self):
     # `traceback_info` sets the local variable __traceback_info__ in the
     # caller's frame.
     self.assertEqual(None, locals().get("__traceback_info__"))
     traceback_info("Pugwash")
     self.assertEqual("Pugwash", locals().get("__traceback_info__"))
Example #7
0
 def test(self):
     # `traceback_info` sets the local variable __traceback_info__ in the
     # caller's frame.
     self.assertEqual(None, locals().get("__traceback_info__"))
     traceback_info("Pugwash")
     self.assertEqual("Pugwash", locals().get("__traceback_info__"))