当前位置: 首页>>代码示例>>Python>>正文


Python simple_httpclient.SimpleAsyncHTTPClient类代码示例

本文整理汇总了Python中tornado.simple_httpclient.SimpleAsyncHTTPClient的典型用法代码示例。如果您正苦于以下问题:Python SimpleAsyncHTTPClient类的具体用法?Python SimpleAsyncHTTPClient怎么用?Python SimpleAsyncHTTPClient使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了SimpleAsyncHTTPClient类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: HostnameMappingTestCase

class HostnameMappingTestCase(AsyncHTTPTestCase):
    def setUp(self):
        super(HostnameMappingTestCase, self).setUp()
        self.http_client = SimpleAsyncHTTPClient(
            self.io_loop,
            hostname_mapping={
                'www.example.com': '127.0.0.1',
                ('foo.example.com', 8000): ('127.0.0.1', self.get_http_port()),
            })

    def get_app(self):
        return Application([url("/hello", HelloWorldHandler), ])

    def test_hostname_mapping(self):
        self.http_client.fetch(
            'http://www.example.com:%d/hello' % self.get_http_port(), self.stop)
        response = self.wait()
        response.rethrow()
        self.assertEqual(response.body, b'Hello world!')

    def test_port_mapping(self):
        self.http_client.fetch('http://foo.example.com:8000/hello', self.stop)
        response = self.wait()
        response.rethrow()
        self.assertEqual(response.body, b'Hello world!')
开发者ID:ArthurGarnier,项目名称:SickRage,代码行数:25,代码来源:simple_httpclient_test.py

示例2: BaseSSLTest

class BaseSSLTest(AsyncHTTPTestCase, LogTrapTestCase):
    def get_ssl_version(self):
        raise NotImplementedError()

    def setUp(self):
        super(BaseSSLTest, self).setUp()
        # Replace the client defined in the parent class.
        # Some versions of libcurl have deadlock bugs with ssl,
        # so always run these tests with SimpleAsyncHTTPClient.
        self.http_client = SimpleAsyncHTTPClient(io_loop=self.io_loop,
                                                 force_instance=True)

    def get_app(self):
        return Application([('/', HelloWorldRequestHandler,
                             dict(protocol="https"))])

    def get_httpserver_options(self):
        # Testing keys were generated with:
        # openssl req -new -keyout tornado/test/test.key -out tornado/test/test.crt -nodes -days 3650 -x509
        test_dir = os.path.dirname(__file__)
        return dict(ssl_options=dict(
                certfile=os.path.join(test_dir, 'test.crt'),
                keyfile=os.path.join(test_dir, 'test.key'),
                ssl_version=self.get_ssl_version()))

    def fetch(self, path, **kwargs):
        self.http_client.fetch(self.get_url(path).replace('http', 'https'),
                               self.stop,
                               validate_cert=False,
                               **kwargs)
        return self.wait()
开发者ID:AM7000000,项目名称:TornadoOSCWSStream,代码行数:31,代码来源:httpserver_test.py

示例3: test_connection_limit

    def test_connection_limit(self):
        client = SimpleAsyncHTTPClient(self.io_loop, max_clients=2,
                                       force_instance=True)
        self.assertEqual(client.max_clients, 2)
        seen = []
        # Send 4 requests.  Two can be sent immediately, while the others
        # will be queued
        for i in range(4):
            client.fetch(self.get_url("/trigger"),
                         lambda response, i=i: (seen.append(i), self.stop()))
        self.wait(condition=lambda: len(self.triggers) == 2)
        self.assertEqual(len(client.queue), 2)

        # Finish the first two requests and let the next two through
        self.triggers.popleft()()
        self.triggers.popleft()()
        self.wait(condition=lambda: (len(self.triggers) == 2 and
                                     len(seen) == 2))
        self.assertEqual(set(seen), set([0, 1]))
        self.assertEqual(len(client.queue), 0)

        # Finish all the pending requests
        self.triggers.popleft()()
        self.triggers.popleft()()
        self.wait(condition=lambda: len(seen) == 4)
        self.assertEqual(set(seen), set([0, 1, 2, 3]))
        self.assertEqual(len(self.triggers), 0)
开发者ID:CoolCold,项目名称:tornado,代码行数:27,代码来源:simple_httpclient_test.py

示例4: fetch

 def fetch(self, request, callback, **kwargs):
     self.request_queue.append((request, callback, kwargs))
     while self.available_requests > 0 and len(self.request_queue) > 0:
         request, callback, kwargs = self.request_queue.popleft()
         SimpleAsyncHTTPClient.fetch(self, request, callback, **kwargs)
         self.available_requests -= 1
         yield gen.Task(self.io_loop.add_timeout, self.period)
         self.available_requests += 1
开发者ID:alekstorm,项目名称:etsy-tornado,代码行数:8,代码来源:throttled_httpclient.py

示例5: test_redirect_connection_limit

 def test_redirect_connection_limit(self):
     # following redirects should not consume additional connections
     client = SimpleAsyncHTTPClient(self.io_loop, max_clients=1,
                                    force_instance=True)
     client.fetch(self.get_url('/countdown/3'), self.stop,
                  max_redirects=3)
     response = self.wait()
     response.rethrow()
开发者ID:CoolCold,项目名称:tornado,代码行数:8,代码来源:simple_httpclient_test.py

示例6: raw_fetch

 def raw_fetch(self, headers, body):
     client = SimpleAsyncHTTPClient(self.io_loop)
     conn = RawRequestHTTPConnection(
         self.io_loop, client, httpclient.HTTPRequest(self.get_url("/")), None, self.stop, 1024 * 1024
     )
     conn.set_request(b("\r\n").join(headers + [utf8("Content-Length: %d\r\n" % len(body))]) + b("\r\n") + body)
     response = self.wait()
     client.close()
     response.rethrow()
     return response
开发者ID:trawor,项目名称:tornado,代码行数:10,代码来源:httpserver_test.py

示例7: setUp

 def setUp(self):
     super(SSLTest, self).setUp()
     # Replace the client defined in the parent class.
     # Some versions of libcurl have deadlock bugs with ssl,
     # so always run these tests with SimpleAsyncHTTPClient.
     self.http_client = SimpleAsyncHTTPClient(io_loop=self.io_loop,
                                              force_instance=True)
开发者ID:nixon,项目名称:tornado,代码行数:7,代码来源:httpserver_test.py

示例8: setUp

 def setUp(self):
     super(HostnameMappingTestCase, self).setUp()
     self.http_client = SimpleAsyncHTTPClient(
         hostname_mapping={
             'www.example.com': '127.0.0.1',
             ('foo.example.com', 8000): ('127.0.0.1', self.get_http_port()),
         })
开发者ID:alexdxy,项目名称:tornado,代码行数:7,代码来源:simple_httpclient_test.py

示例9: SSLTest

class SSLTest(AsyncHTTPTestCase, LogTrapTestCase):
    def setUp(self):
        super(SSLTest, self).setUp()
        # Replace the client defined in the parent class.
        # Some versions of libcurl have deadlock bugs with ssl,
        # so always run these tests with SimpleAsyncHTTPClient.
        self.http_client = SimpleAsyncHTTPClient(io_loop=self.io_loop,
                                                 force_instance=True)

    def get_app(self):
        return Application([('/', HelloWorldRequestHandler, 
                             dict(protocol="https"))])

    def get_httpserver_options(self):
        # Testing keys were generated with:
        # openssl req -new -keyout tornado/test/test.key -out tornado/test/test.crt -nodes -days 3650 -x509
        test_dir = os.path.dirname(__file__)
        return dict(ssl_options=dict(
                certfile=os.path.join(test_dir, 'test.crt'),
                keyfile=os.path.join(test_dir, 'test.key')))

    def fetch(self, path, **kwargs):
        self.http_client.fetch(self.get_url(path).replace('http', 'https'),
                               self.stop,
                               validate_cert=False,
                               **kwargs)
        return self.wait()

    def test_ssl(self):
        response = self.fetch('/')
        self.assertEqual(response.body, b("Hello world"))

    def test_large_post(self):
        response = self.fetch('/',
                              method='POST',
                              body='A'*5000)
        self.assertEqual(response.body, b("Got 5000 bytes in POST"))

    def test_non_ssl_request(self):
        # Make sure the server closes the connection when it gets a non-ssl
        # connection, rather than waiting for a timeout or otherwise
        # misbehaving.
        self.http_client.fetch(self.get_url("/"), self.stop,
                               request_timeout=3600,
                               connect_timeout=3600)
        response = self.wait()
        self.assertEqual(response.code, 599)
开发者ID:dhruvg,项目名称:tornado,代码行数:47,代码来源:httpserver_test.py

示例10: raw_fetch

 def raw_fetch(self, headers, body):
     client = SimpleAsyncHTTPClient(self.io_loop)
     conn = RawRequestHTTPConnection(
         self.io_loop, client,
         httpclient._RequestProxy(
             httpclient.HTTPRequest(self.get_url("/")),
             dict(httpclient.HTTPRequest._DEFAULTS)),
         None, self.stop,
         1024 * 1024, Resolver(io_loop=self.io_loop))
     conn.set_request(
         b"\r\n".join(headers +
                      [utf8("Content-Length: %d\r\n" % len(body))]) +
         b"\r\n" + body)
     response = self.wait()
     client.close()
     response.rethrow()
     return response
开发者ID:good1111,项目名称:pj-redis,代码行数:17,代码来源:httpserver_test.py

示例11: __init__

 def __init__(self, link: str, loop: IOLoop = None, timeout: int = 50):
     self.link = link
     self.client = SimpleAsyncHTTPClient(loop)
     self.timeout = timeout
     if loop is None:
         self.loop = IOLoop.current(False)
     else:
         self.loop = loop
     self.header_only = False
开发者ID:paulnaoki,项目名称:DomainFinderSrcUniversal,代码行数:9,代码来源:NonBlockingRequest.py

示例12: setUp

 def setUp(self):
     super(HostnameMappingTestCase, self).setUp()
     self.http_client = SimpleAsyncHTTPClient(
         self.io_loop,
         hostname_mapping={
             "www.example.com": "127.0.0.1",
             ("foo.example.com", 8000): ("127.0.0.1", self.get_http_port()),
         },
     )
开发者ID:RyanWarm,项目名称:ZUtils,代码行数:9,代码来源:simple_httpclient_test.py

示例13: estimate

    def estimate(self, source, destination, force_refresh=False):
        self._count += 1

        self.debug('Estimating (Total {0} requested so far)'.format(
            self._count))

        estimate = self._get_cache(source, destination)
        if estimate:
            raise gen.Return(estimate)

        data = {
            'startX': source[0],
            'startY': source[1],
            'endX': destination[0],
            'endY': destination[1],
            'reqCoordType': 'WGS84GEO',
            'resCoordType': 'WGS84GEO',
            'speed': int(self.speed),
        }
        headers = {
            'accept': 'application/json',
            'appkey': settings.TMAP_API_KEY,
        }
        body = urllib.urlencode(data)
        client = SimpleAsyncHTTPClient()
        request = HTTPRequest(self.url, method='POST', headers=headers,
                              body=body)

        r = yield client.fetch(request)

        data = json.loads(r.body)
        error = data.get('error')
        if error:
            raise TmapException(error)

        prop = data['features'][0]['properties']
        estimate = Estimate(int(prop['totalDistance']), int(prop['totalTime']))

        self._set_cache(source, destination, estimate)

        raise gen.Return(estimate)
开发者ID:bossjones,项目名称:cabbie-backend,代码行数:41,代码来源:estimate.py

示例14: main

def main():
    parse_command_line()
    app = Application([('/', ChunkHandler)])
    app.listen(options.port, address='127.0.0.1')
    def callback(response):
        response.rethrow()
        assert len(response.body) == (options.num_chunks * options.chunk_size)
        logging.warning("fetch completed in %s seconds", response.request_time)
        IOLoop.instance().stop()

    logging.warning("Starting fetch with curl client")
    curl_client = CurlAsyncHTTPClient()
    curl_client.fetch('http://localhost:%d/' % options.port,
                      callback=callback)
    IOLoop.instance().start()

    logging.warning("Starting fetch with simple client")
    simple_client = SimpleAsyncHTTPClient()
    simple_client.fetch('http://localhost:%d/' % options.port,
                        callback=callback)
    IOLoop.instance().start()
开发者ID:08opt,项目名称:tornado,代码行数:21,代码来源:chunk_benchmark.py

示例15: test_ip

def test_ip(ip):
    hostname = APP_ID + '.appspot.com'
    url = 'https://' + hostname + '/2'
    request = HTTPRequest(url, request_timeout=5)

    try:
        client = SimpleAsyncHTTPClient(force_instance=True,
                hostname_mapping={hostname: ip})

        res = yield client.fetch(request, raise_error=False)
        if isinstance(res.error, OSError):
            if res.error.errno == errno.EMFILE:
                warning_msg = ("Too many open files. You should increase the"
                        " maximum allowed number of network connections in you"
                        " system or decrease the CONCURRENCY setting.")
                warnings.warn(warning_msg)
        if res.code == 200:
            return True
        else:
            return False
    finally:
        client.close()
开发者ID:kawing-chiu,项目名称:search_google_ip,代码行数:22,代码来源:search_google_ip.py


注:本文中的tornado.simple_httpclient.SimpleAsyncHTTPClient类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。