Exemplo n.º 1
0
    async def main(path_list):
        from asks.sessions import Session

        if localhost is True:
            s = Session('http://bustime.mta.info', connections=5)
        else:
            s = Session('http://bustime.mta.info', connections=config.config['http_connections'])
        async with trio.open_nursery() as n:
            for path_bundle in path_list:
                for route_id,path in path_bundle.items():
                    n.start_soon(grabber, s, path, route_id )
Exemplo n.º 2
0
async def main():
    """Make cheeses."""
    async with open_nursery() as nursery:
        maker = CheeseMaker(nursery, Session(INDEX, connections=CONNECTIONS))
        for project_name in await maker.culture():
            if project_name in SKIP: continue
            maker.start_soon(maker.coagulate, project_name)
Exemplo n.º 3
0
async def test_session_stateful():
    from asks.sessions import Session
    s = Session(
        'https://google.ie', persist_cookies=True)
    async with create_task_group() as g:
        await g.spawn(hsession_t_stateful, s)
    assert 'www.google.ie' in s._cookie_tracker.domain_dict.keys()
Exemplo n.º 4
0
async def test_session_stateful():
    from asks.sessions import Session
    s = Session(
        'https://google.ie', persist_cookies=True)
    async with trio.open_nursery() as n:
        n.start_soon(hsession_t_stateful, s)
    assert 'www.google.ie' in s._cookie_tracker.domain_dict.keys()
Exemplo n.º 5
0
async def main(path_list):
    os.environ['SSLKEYLOGFILE'] = 'keylog.txt'
    from asks.sessions import Session
    s = Session('https://httpbin.org', connections=2)
    async with trio.open_nursery() as n:
        await trio.sleep(0)
        for path in path_list:
            n.start_soon(grabber, s, path)
Exemplo n.º 6
0
 async def test_session_stateful(self):
     from asks.sessions import Session
     s = Session(self.httpbin.url, persist_cookies=True)
     async with trio.open_nursery() as n:
         n.spawn(base_tests.hsession_t_stateful, s)
     domain = f'{self.httpbin.host}:{self.httpbin.port}'
     cookies = s._cookie_tracker_obj.domain_dict[domain]
     assert len(cookies) == 1
     assert cookies[0].name == 'cow'
     assert cookies[0].value == 'moo'
Exemplo n.º 7
0
 async def test_session_stateful(self):
     from asks.sessions import Session
     s = Session(self.httpbin.url, persist_cookies=True)
     async with curio.TaskGroup() as g:
         await g.spawn(base_tests.hsession_t_stateful(s))
     domain = '{}:{}'.format(self.httpbin.host, self.httpbin.port)
     cookies = s._cookie_tracker_obj.domain_dict[domain]
     assert len(cookies) == 1
     assert cookies[0].name == 'cow'
     assert cookies[0].value == 'moo'
Exemplo n.º 8
0
    def __init__(self, client_id: int, client_secret: str, redirect_uri: str):
        self.client_id = client_id
        self.client_secret = client_secret
        self.redirect_uri = redirect_uri

        self._oauth2_client = WebApplicationClient(
            client_id=self.client_id, redirect_url=self.redirect_uri)
        self.sess = Session(base_location=self.BASE, endpoint=self.API_BASE)

        #: A list of states that have been seen before.
        #: If the state was not seen, it will raise an invalid state error.
        self._states = collections.deque(maxlen=500)
Exemplo n.º 9
0
async def request(method, uri, **kwargs):
    '''Base function for one time http requests.

    Args:
        method (str): The http method to use. For example 'GET'
        uri (str): The url of the resource.
            Example: 'https://example.com/stuff'
        kwargs: Any number of arguments supported, found here:
            http://asks.rtfd.io/en/latest/overview-of-funcs-and-args.html

    Returns:
        Response (asks.Response): The Response object.
    '''
    c_interact = kwargs.pop('persist_cookies', None)
    async with Session(persist_cookies=c_interact) as s:
        r = await s.request(method, url=uri, **kwargs)
        return r
Exemplo n.º 10
0
async def main(paths, rate_limit):

    s = Session(connections=3)

    # mutual exclusion for getter worker
    mut_ex = trio.Semaphore(1)
    interval = 1 / rate_limit

    async def tick():
        await trio.sleep(interval)
        mut_ex.release()

    async def getter(session, path):
        await mut_ex.acquire()
        n.start_soon(tick)

        logging.info(f'Sending to {path}. Current responses: {len(results)}')
        resp = await session.get(path)
        # we do not raise_for_status() here; process the batch afterwards
        results.append(resp)

    async with trio.open_nursery() as n:
        for path in path_list:
            n.start_soon(getter, s, path)
Exemplo n.º 11
0
async def test_Session_smallpool():
    from asks.sessions import Session
    s = Session(connections=2)
    for _ in range(10):
        await curio.spawn(session_t_smallpool(s))
Exemplo n.º 12
0
async def test_hsession_smallpool():
    from asks.sessions import Session
    s = Session('http://httpbin.org', connections=2)
    async with curio.TaskGroup() as g:
        for _ in range(10):
            await g.spawn(hsession_t_smallpool(s))
Exemplo n.º 13
0
 async def test_hsession_smallpool(self):
     from asks.sessions import Session
     s = Session(self.httpbin.url, connections=2)
     async with curio.TaskGroup() as g:
         for _ in range(10):
             await g.spawn(base_tests.hsession_t_smallpool(s))
Exemplo n.º 14
0
 async def test_Session_smallpool(self):
     from asks.sessions import Session
     s = Session(connections=2)
     async with trio.open_nursery() as n:
         for _ in range(10):
             n.spawn(base_tests.session_t_smallpool, s, self.httpbin)
Exemplo n.º 15
0
 async def test_session_stateful_double(self):
     from asks.sessions import Session
     s = Session(self.httpbin.url, persist_cookies=True)
     async with trio.open_nursery() as n:
         for _ in range(4):
             n.spawn(base_tests.hsession_t_stateful, s)
Exemplo n.º 16
0
 async def test_session_stateful_double(self):
     from asks.sessions import Session
     s = Session(self.httpbin.url, persist_cookies=True)
     async with curio.TaskGroup() as g:
         for _ in range(4):
             await g.spawn(base_tests.hsession_t_stateful(s))
Exemplo n.º 17
0
async def test_hsession_smallpool():
    from asks.sessions import Session
    s = Session('http://httpbin.org', connections=2)
    async with trio.open_nursery() as n:
        for _ in range(10):
            n.spawn(hsession_t_smallpool, s)
Exemplo n.º 18
0
async def test_Session_smallpool():
    from asks.sessions import Session
    s = Session(connections=2)
    async with create_task_group() as g:
        for _ in range(10):
            await g.spawn(session_t_smallpool, s)
Exemplo n.º 19
0
async def test_session_stateful_double():
    from asks.sessions import Session
    s = Session('https://google.ie', persist_cookies=True)
    async with create_task_group() as g:
        for _ in range(4):
            await g.spawn(session_t_stateful_double_worker, s)
Exemplo n.º 20
0
 async def test_Session_smallpool(self):
     from asks.sessions import Session
     s = Session(connections=2)
     for _ in range(10):
         await curio.spawn(base_tests.session_t_smallpool(s, self.httpbin))
Exemplo n.º 21
0
def test_instantiate_session_outside_of_event_loop():
    from asks.sessions import Session
    try:
        Session()
    except RuntimeError:
        pytest.fail("Could not instantiate Session outside of event loop")
Exemplo n.º 22
0
async def test_Session_smallpool():
    from asks.sessions import Session
    s = Session(connections=2)
    async with trio.open_nursery() as n:
        for _ in range(10):
            n.start_soon(session_t_smallpool, s)
Exemplo n.º 23
0
async def test_session_stateful_double():
    from asks.sessions import Session
    s = Session('https://google.ie', persist_cookies=True)
    async with trio.open_nursery() as n:
        for _ in range(4):
            n.start_soon(session_t_stateful_double_worker, s)
Exemplo n.º 24
0
 async def test_hsession_smallpool(self):
     from asks.sessions import Session
     s = Session(self.httpbin.url, connections=2)
     async with trio.open_nursery() as n:
         for _ in range(10):
             n.start_soon(base_tests.hsession_t_smallpool, s)