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


Python helpers.TimerNoop方法代码示例

本文整理汇总了Python中aiohttp.helpers.TimerNoop方法的典型用法代码示例。如果您正苦于以下问题:Python helpers.TimerNoop方法的具体用法?Python helpers.TimerNoop怎么用?Python helpers.TimerNoop使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在aiohttp.helpers的用法示例。


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

示例1: HTTPResponse

# 需要导入模块: from aiohttp import helpers [as 别名]
# 或者: from aiohttp.helpers import TimerNoop [as 别名]
def HTTPResponse(*args, **kw):
    # Dynamically load package
    module = __import__(RESPONSE_PATH, fromlist=(RESPONSE_CLASS,))
    ClientResponse = getattr(module, RESPONSE_CLASS)

    # Return response instance
    return ClientResponse(
        *args,
        request_info=mock.Mock(),
        writer=mock.Mock(),
        continue100=None,
        timer=TimerNoop(),
        traces=[],
        loop=mock.Mock(),
        session=mock.Mock(),
        **kw
    ) 
开发者ID:h2non,项目名称:pook,代码行数:19,代码来源:aiohttp.py

示例2: registerEmptyUri

# 需要导入模块: from aiohttp import helpers [as 别名]
# 或者: from aiohttp.helpers import TimerNoop [as 别名]
def registerEmptyUri(self, uri, status):
        def cb():
            fut = asyncio.Future(loop=self._loop)
            resp = ClientResponse(
                'GET',
                yarl.URL('foo'),
                writer=Mock(),
                timer=TimerNoop(),
                continue100=None,
                request_info=Mock(),
                traces=[],
                loop=self._loop,
                session=Mock()
                )
            resp.status = status

            # setting this as aiohttp 3.5.4 is now checking if this value is not None
            # see aiohttp/client_reqrep.py:934
            resp.reason = http.client.responses[status]

            fut.set_result(resp)
            return fut
        self._callbacks[uri].append(cb) 
开发者ID:madedotcom,项目名称:atomicpuppy,代码行数:25,代码来源:fakehttp.py

示例3: test_iter_lines_generator

# 需要导入模块: from aiohttp import helpers [as 别名]
# 或者: from aiohttp.helpers import TimerNoop [as 别名]
def test_iter_lines_generator():
    """Test that lines are split correctly."""
    async def mock_iter_content(n):
        for chunk in [b'1\r\n2\r\n', b'3\r', b'\n4', b'\r\n5']:
            yield chunk

    response = ClientResponse(
        'get', ST_URL,
        request_info=Mock(),
        writer=Mock(),
        continue100=None,
        timer=TimerNoop(),
        traces=[],
        loop=Mock(),
        session=Mock(),
    )
    response._headers = {'Content-Type': 'application/json;charset=utf-8'}
    with patch.object(response, 'content', Mock(iter_chunked=mock_iter_content)):
        result = [
            line async for line in _iter_lines_generator(
                response=response, decode_unicode=True
            )
        ]
        assert result == ['1', '2', '3', '4', '5'] 
开发者ID:python-astrodynamics,项目名称:spacetrack,代码行数:26,代码来源:test_aio.py

示例4: _respkw

# 需要导入模块: from aiohttp import helpers [as 别名]
# 或者: from aiohttp.helpers import TimerNoop [as 别名]
def _respkw():
    from aiohttp.helpers import TimerNoop

    return {
        "request_info": None,
        "writer": None,
        "continue100": None,
        "timer": TimerNoop(),
        "traces": [],
        "loop": asyncio.get_event_loop(),
        "session": None,
    } 
开发者ID:loads,项目名称:molotov,代码行数:14,代码来源:support.py

示例5: _make_response

# 需要导入模块: from aiohttp import helpers [as 别名]
# 或者: from aiohttp.helpers import TimerNoop [as 别名]
def _make_response(self, uri, filename=None, status=200):
        def cb():

            def read():
                fut = asyncio.Future(loop=self._loop)
                with open(filename) as f:
                    fut.set_result(f.read().encode('utf-8'))
                return fut

            resp = ClientResponse(
                'GET',
                yarl.URL(uri),
                writer=Mock(),
                timer=TimerNoop(),
                continue100=None,
                request_info=Mock(),
                traces=[],
                loop=self._loop,
                session=Mock()
            )
            resp._headers = {
                'Content-Type': 'application/json'
            }

            resp.status = status
            resp.reason = Mock()
            resp.content = Mock()
            resp.content.read.side_effect = read
            resp.close = Mock()
            fut = asyncio.Future(loop=self._loop)
            fut.set_result(resp)
            return fut
        return cb 
开发者ID:madedotcom,项目名称:atomicpuppy,代码行数:35,代码来源:fakehttp.py

示例6: test_iter_content_generator

# 需要导入模块: from aiohttp import helpers [as 别名]
# 或者: from aiohttp.helpers import TimerNoop [as 别名]
def test_iter_content_generator():
    """Test CRLF -> LF newline conversion."""
    async def mock_iter_content(n):
        for chunk in [b'1\r\n2\r\n', b'3\r', b'\n4', b'\r\n5']:
            yield chunk

    response = ClientResponse(
        'get', ST_URL,
        request_info=Mock(),
        writer=Mock(),
        continue100=None,
        timer=TimerNoop(),
        traces=[],
        loop=Mock(),
        session=Mock(),
    )
    response._headers = {'Content-Type': 'application/json;charset=utf-8'}
    with patch.object(response, 'content', Mock(iter_chunked=mock_iter_content)):
        result = [
            line async for line in _iter_content_generator(
                response=response, decode_unicode=True
            )
        ]
        assert result == ['1\n2\n', '3', '\n4', '\n5']

        result = [
            line async for line in _iter_content_generator(
                response=response, decode_unicode=False
            )
        ]
        assert result == [b'1\r\n2\r\n', b'3\r', b'\n4', b'\r\n5'] 
开发者ID:python-astrodynamics,项目名称:spacetrack,代码行数:33,代码来源:test_aio.py

示例7: test__raise_response_exceptions

# 需要导入模块: from aiohttp import helpers [as 别名]
# 或者: from aiohttp.helpers import TimerNoop [as 别名]
def test__raise_response_exceptions(self):
        loop = mock.Mock()
        request_info = mock.Mock()
        request_info.status.return_value = 428
        session = ClientSession()
        four_two_eight = MockedResponse(
            "get",
            URL("http://code404.tld"),
            request_info=request_info,
            writer=mock.Mock(),
            continue100=None,
            timer=TimerNoop(),
            traces=[],
            status=404,
            loop=loop,
            session=session,
        )

        try:
            _raise_response_exceptions(four_two_eight)
        except Exception as err:
            self.assertIsInstance(err, ClientError)
            self.assertNotIsInstance(err, AugustApiAIOHTTPError)

        ERROR_MAP = {
            422: "The operation failed because the bridge (connect) is offline.",
            423: "The operation failed because the bridge (connect) is in use.",
            408: "The operation timed out because the bridge (connect) failed to respond.",
        }

        for status_code in ERROR_MAP:
            mocked_response = MockedResponse(
                "get",
                URL("http://code.any.tld"),
                request_info=request_info,
                writer=mock.Mock(),
                continue100=None,
                timer=TimerNoop(),
                traces=[],
                status=status_code,
                loop=loop,
                session=session,
            )

            try:
                _raise_response_exceptions(mocked_response)
            except AugustApiAIOHTTPError as err:
                self.assertEqual(str(err), ERROR_MAP[status_code]) 
开发者ID:snjoetw,项目名称:py-august,代码行数:50,代码来源:test_api_async.py

示例8: test_authenticate

# 需要导入模块: from aiohttp import helpers [as 别名]
# 或者: from aiohttp.helpers import TimerNoop [as 别名]
def test_authenticate():
    st = AsyncSpaceTrackClient('identity', 'wrongpassword')

    loop = asyncio.get_event_loop()
    response = ClientResponse(
        'post', ST_URL / 'ajaxauth/login',
        request_info=Mock(),
        writer=Mock(),
        continue100=None,
        timer=TimerNoop(),
        traces=[],
        loop=loop,
        session=st.session,
    )

    response.status = 200
    response.json = Mock()

    async def mock_post(url, data):
        response.json.return_value = asyncio.Future()
        if data['password'] == 'wrongpassword':
            response.json.return_value.set_result({'Login': 'Failed'})
        elif data['password'] == 'unknownresponse':
            # Space-Track doesn't respond like this, but make sure anything
            # other than {'Login': 'Failed'} doesn't raise AuthenticationError
            response.json.return_value.set_result({'Login': 'Successful'})
        else:
            response.json.return_value.set_result('')
        return response

    async with st:
        with patch.object(st.session, 'post', mock_post):
            with pytest.raises(AuthenticationError):
                await st.authenticate()

            assert response.json.call_count == 1

            st.password = 'password'
            await st.authenticate()

            # This shouldn't make a HTTP request since we're already authenticated.
            await st.authenticate()

    assert response.json.call_count == 2

    st = AsyncSpaceTrackClient('identity', 'unknownresponse')

    async with st:
        with patch.object(st.session, 'post', mock_post):
            await st.authenticate()

    response.close() 
开发者ID:python-astrodynamics,项目名称:spacetrack,代码行数:54,代码来源:test_aio.py

示例9: _build_response

# 需要导入模块: from aiohttp import helpers [as 别名]
# 或者: from aiohttp.helpers import TimerNoop [as 别名]
def _build_response(self, url: 'Union[URL, str]',
                        method: str = hdrs.METH_GET,
                        request_headers: Dict = None,
                        status: int = 200,
                        body: str = '',
                        content_type: str = 'application/json',
                        payload: Dict = None,
                        headers: Dict = None,
                        response_class: 'ClientResponse' = None,
                        reason: Optional[str] = None) -> ClientResponse:
        if response_class is None:
            response_class = ClientResponse
        if payload is not None:
            body = json.dumps(payload)
        if not isinstance(body, bytes):
            body = str.encode(body)
        if request_headers is None:
            request_headers = {}
        kwargs = {}
        if AIOHTTP_VERSION >= StrictVersion('3.1.0'):
            loop = Mock()
            loop.get_debug = Mock()
            loop.get_debug.return_value = True
            kwargs['request_info'] = Mock(
                url=url,
                method=method,
                headers=CIMultiDictProxy(CIMultiDict(**request_headers)),
            )
            kwargs['writer'] = Mock()
            kwargs['continue100'] = None
            kwargs['timer'] = TimerNoop()
            if AIOHTTP_VERSION < StrictVersion('3.3.0'):
                kwargs['auto_decompress'] = True
            kwargs['traces'] = []
            kwargs['loop'] = loop
            kwargs['session'] = None
        else:
            loop = None
        # We need to initialize headers manually
        _headers = CIMultiDict({hdrs.CONTENT_TYPE: content_type})
        if headers:
            _headers.update(headers)
        raw_headers = self._build_raw_headers(_headers)
        resp = response_class(method, url, **kwargs)

        for hdr in _headers.getall(hdrs.SET_COOKIE, ()):
            resp.cookies.load(hdr)

        if AIOHTTP_VERSION >= StrictVersion('3.3.0'):
            # Reified attributes
            resp._headers = _headers
            resp._raw_headers = raw_headers
        else:
            resp.headers = _headers
            resp.raw_headers = raw_headers
        resp.status = status
        resp.reason = reason
        resp.content = stream_reader_factory(loop)
        resp.content.feed_data(body)
        resp.content.feed_eof()
        return resp 
开发者ID:pnuckowski,项目名称:aioresponses,代码行数:63,代码来源:core.py


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