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


Python client.ClientSession类代码示例

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


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

示例1: test_close

    def test_close(self):
        conn = self.make_open_connector()
        session = ClientSession(loop=self.loop, connector=conn)

        session.close()
        self.assertIsNone(session.connector)
        self.assertTrue(conn.closed)
开发者ID:morgan-del,项目名称:aiohttp,代码行数:7,代码来源:test_client_session.py

示例2: test_init_cookies_with_list_of_tuples

 def test_init_cookies_with_list_of_tuples(self):
     session = ClientSession(
         cookies=[("c1", "cookie1"),
                  ("c2", "cookie2")],
         loop=self.loop)
     self.assertEqual(set(session.cookies), {'c1', 'c2'})
     self.assertEqual(session.cookies['c1'].value, 'cookie1')
     self.assertEqual(session.cookies['c2'].value, 'cookie2')
     session.close()
开发者ID:morgan-del,项目名称:aiohttp,代码行数:9,代码来源:test_client_session.py

示例3: test_detach

 def test_detach(self):
     session = ClientSession(loop=self.loop)
     conn = session.connector
     self.assertFalse(conn.closed)
     session.detach()
     self.assertIsNone(session.connector)
     self.assertTrue(session.closed)
     self.assertFalse(conn.closed)
     conn.close()
开发者ID:morgan-del,项目名称:aiohttp,代码行数:9,代码来源:test_client_session.py

示例4: test_init_cookies_with_simple_dict

 def test_init_cookies_with_simple_dict(self):
     session = ClientSession(
         cookies={
             "c1": "cookie1",
             "c2": "cookie2"
         }, loop=self.loop)
     self.assertEqual(set(session.cookies), {'c1', 'c2'})
     self.assertEqual(session.cookies['c1'].value, 'cookie1')
     self.assertEqual(session.cookies['c2'].value, 'cookie2')
     session.close()
开发者ID:morgan-del,项目名称:aiohttp,代码行数:10,代码来源:test_client_session.py

示例5: test_init_headers_simple_dict

 def test_init_headers_simple_dict(self):
     session = ClientSession(
         headers={
             "h1": "header1",
             "h2": "header2"
         }, loop=self.loop)
     self.assertEqual(
         sorted(session._default_headers.items()),
         ([("H1", "header1"),
           ("H2", "header2")]))
     session.close()
开发者ID:morgan-del,项目名称:aiohttp,代码行数:11,代码来源:test_client_session.py

示例6: test_merge_headers_with_multi_dict

 def test_merge_headers_with_multi_dict(self):
     session = ClientSession(
         headers={
             "h1": "header1",
             "h2": "header2"
         }, loop=self.loop)
     headers = session._prepare_headers(MultiDict([("h1", "h1")]))
     self.assertIsInstance(headers, CIMultiDict)
     self.assertEqual(headers, CIMultiDict([
         ("h1", "h1"),
         ("h2", "header2")
     ]))
开发者ID:TigorC,项目名称:aiohttp,代码行数:12,代码来源:test_client_session.py

示例7: test_init_headers_list_of_tuples

 def test_init_headers_list_of_tuples(self):
     session = ClientSession(
         headers=[("h1", "header1"),
                  ("h2", "header2"),
                  ("h3", "header3")],
         loop=self.loop)
     self.assertEqual(
         session._default_headers,
         CIMultiDict([("h1", "header1"),
                      ("h2", "header2"),
                      ("h3", "header3")]))
     session.close()
开发者ID:morgan-del,项目名称:aiohttp,代码行数:12,代码来源:test_client_session.py

示例8: test_init_headers_MultiDict

 def test_init_headers_MultiDict(self):
     session = ClientSession(
         headers=MultiDict(
             [("h1", "header1"),
              ("h2", "header2"),
              ("h3", "header3")]),
         loop=self.loop)
     self.assertEqual(
         session._default_headers,
         CIMultiDict([("H1", "header1"),
                      ("H2", "header2"),
                      ("H3", "header3")]))
     session.close()
开发者ID:morgan-del,项目名称:aiohttp,代码行数:13,代码来源:test_client_session.py

示例9: test_merge_headers_with_list_of_tuples_duplicated_names

 def test_merge_headers_with_list_of_tuples_duplicated_names(self):
     session = ClientSession(
         headers={
             "h1": "header1",
             "h2": "header2"
         }, loop=self.loop)
     headers = session._prepare_headers([("h1", "v1"),
                                         ("h1", "v2")])
     self.assertIsInstance(headers, CIMultiDict)
     self.assertEqual(headers, CIMultiDict([
         ("H2", "header2"),
         ("H1", "v1"),
         ("H1", "v2"),
     ]))
     session.close()
开发者ID:flying-sheep,项目名称:aiohttp,代码行数:15,代码来源:test_client_session.py

示例10: test_merge_headers

 def test_merge_headers(self):
     # Check incoming simple dict
     session = ClientSession(
         headers={
             "h1": "header1",
             "h2": "header2"
         }, loop=self.loop)
     headers = session._prepare_headers({
         "h1": "h1"
     })
     self.assertIsInstance(headers, CIMultiDict)
     self.assertEqual(headers, CIMultiDict([
         ("h1", "h1"),
         ("h2", "header2")
     ]))
开发者ID:TigorC,项目名称:aiohttp,代码行数:15,代码来源:test_client_session.py

示例11: go

        def go():
            err = OSError(1, "permission error")
            req = mock.Mock()
            req_factory = mock.Mock(return_value=req)
            req.send = mock.Mock(side_effect=err)
            session = ClientSession(loop=self.loop, request_class=req_factory)

            @asyncio.coroutine
            def create_connection(req):
                # return self.transport, self.protocol
                return mock.Mock(), mock.Mock()
            session._connector._create_connection = create_connection

            with self.assertRaises(aiohttp.ClientOSError) as ctx:
                yield from session.request('get', 'http://example.com')
            e = ctx.exception
            self.assertEqual(e.errno, err.errno)
            self.assertEqual(e.strerror, err.strerror)
开发者ID:flying-sheep,项目名称:aiohttp,代码行数:18,代码来源:test_client_session.py

示例12: __init__

    def __init__(self, rest_service_name='GenericService', spec=None, plugins=None, config=None,
                 parser=None, serializer=None, base_path='', loop=None, logger=None):
        self._plugins = []

        self.logger = logger or logging.getLogger('serviceClient.{}'.format(rest_service_name))
        self.rest_service_name = rest_service_name
        self.spec = spec or {}
        self.add_plugins(plugins or [])
        self.config = config or {}
        self.parser = parser or (lambda x, *args, **kwargs: x)
        self.serializer = serializer or (lambda x, *args, **kwargs: x)
        self.base_path = base_path
        self.loop = loop or get_event_loop()

        self.connector = TCPConnector(loop=self.loop, **self.config.get('connector', {}))
        self.session = ClientSession(connector=self.connector, loop=self.loop)
开发者ID:davinirjr,项目名称:aio-service-client,代码行数:16,代码来源:__init__.py

示例13: fetch

 async def fetch(self, request: Request, session: ClientSession):
     if self.use_proxy:
         # method, url, *,
         # params = None,
         # data = None,
         # json = None,
         # headers = None,
         # skip_auto_headers = None,
         # auth = None,
         # allow_redirects = True,
         # max_redirects = 10,
         # compress = None,
         # chunked = None,
         pass
     try:
         biu = session.request(request.method, request.url,
                               headers=request.header,
                               data=request.body)
         async with biu as req:
             text = await req.text()
             return Response(request, text, req.status)
     except Exception:
         pass
开发者ID:LooEv,项目名称:learning-python,代码行数:23,代码来源:spider_engine.py

示例14: test_close

 def test_close(self):
     session = ClientSession(loop=self.loop)
     session._connector = mock.Mock(BaseConnector)
     session.close()
     session._connector.close.assert_called_once_with()
开发者ID:TigorC,项目名称:aiohttp,代码行数:5,代码来源:test_client_session.py

示例15: test_borrow_connector_loop

def test_borrow_connector_loop(connector, create_session, loop):
    session = ClientSession(connector=connector, loop=None)
    try:
        assert session._loop, loop
    finally:
        session.close()
开发者ID:elastic-coders,项目名称:aiohttp,代码行数:6,代码来源:test_client_session.py


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