コード例 #1
0
ファイル: application.py プロジェクト: norpadon/vk_async
    def __init__(self, app_id, username, password, max_requests_per_second=3,
                 default_timeout=20, api_version='5.28'):
        """Create new application object

        Args:
            app_id: id of VK application.
            username: user's phone number or email.
            password: user's password.
            max_requests_per_second: maximum number of requests that
                application can send per one second.
                Depends on number of users. Default value is 3.
            default_timeout: default timeout for ip requests.
            api_version: version of VK API used.
        """
        self.last_requests = deque([datetime.min] * max_requests_per_second)
        self.max_requests_per_second = max_requests_per_second

        self.app_id = app_id
        self.username = username
        self.password = password

        self.api_version = api_version

        self.default_timeout = default_timeout

        self.client_session = Session(AsyncHTTPClient)
        self.queue_lock = Lock()

        IOLoop.current().run_sync(self.get_access_token)
コード例 #2
0
import tornado.testing
import tornado.web
from tornado.ioloop import IOLoop

from httpclient_session import Session

session = Session()


class AsyncHTTPTestCase(tornado.testing.AsyncHTTPTestCase):
    def __init__(self, methodName='runTest', **kwargs):
        super(AsyncHTTPTestCase, self).__init__(methodName, **kwargs)

    def get_app(self):
        return app

    def get_new_ioloop(self):
        return IOLoop.current()

    def get_http_client(self):
        return session


class CookieHandler(tornado.web.RequestHandler):
    def get(self):
        if not self.get_cookie('key'):
            self.set_cookie('key', 'value')
        self.write('ok')


app = tornado.web.Application(
コード例 #3
0
import tornado.testing
import tornado.web
from tornado.ioloop import IOLoop

from httpclient_session import Session

session = Session(io_loop=IOLoop.current())


class AsyncHTTPTestCase(tornado.testing.AsyncHTTPTestCase):
    def __init__(self, methodName='runTest', **kwargs):
        super(AsyncHTTPTestCase, self).__init__(methodName, **kwargs)

    def get_app(self):
        return app

    def get_new_ioloop(self):
        return IOLoop.current()

    def get_http_client(self):
        return session


class CookieHandler(tornado.web.RequestHandler):
    def get(self):
        if not self.get_cookie('key'):
            self.set_cookie('key', 'value')
        self.write('ok')


app = tornado.web.Application(