Exemplo n.º 1
0
    def request(self, method, uri, headers=None, params=None, body=None):
        """
        """
        if headers is not None:
            headers = self._create_headers(headers)

        body_producer = None
        if params is not None:
            body_producer = _SynchronousProducer(urlencode(params))
        if body is not None:
            body_producer = _SynchronousProducer(body)

        method = ensure_utf8_bytes(method)
        uri = ensure_utf8_bytes('/'.join([self.base_url, uri.strip('/')]))
        response = yield self.mem_agent.request(method, uri, headers,
                                                body_producer)
        content = yield readBody(response)
        response.content = content.decode(self.encoding)
        response.getHeaders = response.headers.getRawHeaders
        defer.returnValue(response)
Exemplo n.º 2
0
 def test_ensure_utf8_bytes(self):
     self.assertEqual(ensure_utf8_bytes(u"abc"), "abc")
     self.assertEqual(ensure_utf8_bytes(u"\u2202"), "\xe2\x88\x82")
     self.assertEqual(ensure_utf8_bytes("\xe2\x88\x82"), "\xe2\x88\x82")
Exemplo n.º 3
0
 def test_ensure_utf8_bytes(self):
     self.assertEqual(ensure_utf8_bytes(u"abc"), b"abc")
     self.assertEqual(ensure_utf8_bytes(u"\u2202"), b"\xe2\x88\x82")
     self.assertEqual(ensure_utf8_bytes(b"\xe2\x88\x82"), b"\xe2\x88\x82")