Example #1
0
    def get(self):
        http_client = tornado.httpclient.AsyncHTTPClient()
        facts = tornalet.asyncify(http_client.fetch)(URL).body.split("%")

        fact = facts[random.randrange(len(facts))]

        self.write("<pre>%s</pre>" % (fact, ))
Example #2
0
    def send(self,
             request,
             stream=False,
             timeout=None,
             verify=True,
             cert=None,
             proxies=None):

        http_client = AsyncHTTPClient()
        # This where the magic happens, tornalet.asyncify wraps the parent
        # call in a greenlet that can be swapped out the same as any
        # aync tornado IO handler call.
        resp = asyncify(http_client.fetch)(request=request.url,
                                           method=request.method,
                                           body=request.body,
                                           headers=request.headers,
                                           validate_cert=verify)

        # We probably don't get this from any of the tornado adaptors, so
        # we stub it out as Unknown
        resp.reason = 'Unknown'
        resp.content = resp.body
        r = self.build_response(request, resp)
        # Reset the code and content as they're not parsed by build_response
        r.status_code = resp.code
        r._content = resp.content
        return r
Example #3
0
    def get(self):
        http_client = tornado.httpclient.AsyncHTTPClient()
        facts = tornalet.asyncify(http_client.fetch)(URL).body.split("%")

        fact = facts[random.randrange(len(facts))]

        self.write("<pre>%s</pre>" % (fact, ))
Example #4
0
    def get(self, path):
        url = urljoin(options.url, path)

        http_client = tornado.httpclient.AsyncHTTPClient()
        body = tornalet.asyncify(http_client.fetch)(url).body

        self.write(body)
Example #5
0
    def get(self, path):
        url = urljoin(options.url, path)

        http_client = tornado.httpclient.AsyncHTTPClient()
        body = tornalet.asyncify(http_client.fetch)(url).body

        self.write(body)
Example #6
0
    def send(self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None):

        http_client = AsyncHTTPClient()
        # This where the magic happens, tornalet.asyncify wraps the parent
        # call in a greenlet that can be swapped out the same as any
        # aync tornado IO handler call.
        resp = asyncify(http_client.fetch)(
            request=request.url, method=request.method, body=request.body, headers=request.headers
        )

        # We probably don't get this from any of the tornado adaptors, so
        # we stub it out as Unknown
        resp.reason = "Unknown"
        resp.content = resp.body
        r = self.build_response(request, resp)
        # Reset the code and content as they're not parsed by build_response
        r.status_code = resp.code
        r._content = resp.content
        return r
Example #7
0
def test_asyncify(callback=None):
    http_client = AsyncHTTPClient()
    # This where the magic happens, tornalet.asyncify wraps the parent
    # call in a greenlet that can be swapped out the same as any
    # aync tornado IO handler call.
    resp = asyncify(http_client.fetch)(request="http://localhost/",callback=callback)