How to use the multidict.CIMultiDict function in multidict

To help you get started, weโ€™ve selected a few multidict examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github aio-libs / aiohttp / tests / test_client_response.py View on Github external
def test_response_links_multiple_headers(loop, session) -> None:
    url = URL('http://def-cl-resp.org/')
    response = ClientResponse('get', url,
                              request_info=mock.Mock(),
                              writer=mock.Mock(),
                              continue100=None,
                              timer=TimerNoop(),
                              traces=[],
                              loop=loop,
                              session=session)
    response._headers = CIMultiDict([
        (
            "Link",
            '; rel=next'
        ),
        (
            "Link",
            '; rel=home'
        )
    ])
    assert (
        response.links ==
        {'next':
         {'url': URL('http://example.com/page/1.html'),
          'rel': 'next'},
         'home':
         {'url': URL('http://example.com/'),
github foglamp / FogLAMP / tests / unit / python / foglamp / plugins / south / http_south / test_http_south.py View on Github external
def mock_request(data, loop):
    payload = StreamReader(loop=loop)
    payload.feed_data(data.encode())
    payload.feed_eof()

    protocol = mock.Mock()
    app = mock.Mock()
    headers = CIMultiDict([('CONTENT-TYPE', 'application/json')])
    req = make_mocked_request('POST', '/sensor-reading', headers=headers,
                              protocol=protocol, payload=payload, app=app)
    return req
github Tygs / tygs / tests / test_components.py View on Github external
def factory(method="GET", url="/toto", headers=None):
        headers = CIMultiDict(headers or {})
        if "HOST" not in headers:  # noqa
            headers['HOST'] = "test.local"
        return RawRequestMessage(method, url, HttpVersion(1, 1),
                                 headers, [], False, False)
    return factory
github aio-libs / aiohttp / tests / test_web_request.py View on Github external
def test_single_forwarded_header_injection1() -> None:
    # We might receive a header like this if we're sitting behind a reverse
    # proxy that blindly appends a forwarded-element without checking
    # the syntax of existing field-values. We should be able to recover
    # the appended element anyway.
    header = 'for=_injected;by=", for=_real'
    req = make_mocked_request('GET', '/',
                              headers=CIMultiDict({'Forwarded': header}))
    assert len(req.forwarded) == 2
    assert 'by' not in req.forwarded[0]
    assert req.forwarded[1]['for'] == '_real'
github dianbaer / jupiter / firstaio-require-win / aiohttp / test_utils.py View on Github external
"""

    task = mock.Mock()
    loop = mock.Mock()
    loop.create_future.return_value = ()

    if version < HttpVersion(1, 1):
        closing = True

    if headers:
        headers = CIMultiDict(headers)
        raw_hdrs = tuple(
            (k.encode('utf-8'), v.encode('utf-8')) for k, v in headers.items())
    else:
        headers = CIMultiDict()
        raw_hdrs = ()

    chunked = 'chunked' in headers.get(hdrs.TRANSFER_ENCODING, '').lower()

    message = RawRequestMessage(
        method, path, version, headers,
        raw_hdrs, closing, False, False, chunked, URL(path))
    if app is None:
        app = _create_app_mock()

    if protocol is sentinel:
        protocol = mock.Mock()

    if transport is sentinel:
        transport = _create_transport(sslcontext)
github stephen-bunn / bethesda-structs / bethesda_structs / plugin / _common.py View on Github external
parsed_container = Container(
            value=value_structure.parse(subrecord_data),
            description=value_structure.docs,
        )

        return (parsed_container, working_record)


@attr.s
class BasePlugin(BaseFiletype, abc.ABC, Generic[T_BasePlugin]):
    """The base class all Plugins should subclass.
    """

    content = attr.ib(type=bytes, repr=False)
    filepath = attr.ib(type=str, default=None)
    record_registry = attr.ib(type=CIMultiDict, default=CIMultiDict(), repr=False)

    @abc.abstractproperty
    def plugin_struct(self) -> Construct:
        """The base plugin structure to use for parsing a plugin.

        Returns:
            Construct: The plugin structure
        """
        raise NotImplementedError

    @property
    def container(self) -> Container:
        if not hasattr(self, "_container"):
            self._container = self.plugin_struct.parse(self.content)
        return self._container
github dwpy / alita / alita / base.py View on Github external
def __init__(self, app, environ, headers=None):
        # Request state
        self.app = app
        self.environ = environ
        self.headers = CIMultiDict(headers or {})

        # Response state
        self._cookies = None
        self._cached_data = None
        self._parsed_content_type = None
        self.disconnected = False
        self.response_complete = False
        self.match_headers()
github mosquito / aiohttp-jsonrpc / aiohttp_jsonrpc / client.py View on Github external
elif kwargs:
            data["params"] = kwargs

        return data


class Notification(Method):
    def _create_request(self) -> dict:
        return {
            "method": str(self.name),
            "jsonrpc": "2.0",
        }


HeadersType = typing.Union[
    CIMultiDict,
    typing.Dict[str, str],
    typing.Iterable[typing.Tuple[str, str]],
]

ClientSessionType = typing.Union[
    aiohttp.client.ClientSession,
    aiohttp.test_utils.TestClient,
]


class ServerProxy(object):
    __slots__ = (
        "client", "url", "loop", "headers", "loads", "dumps", "client_owner",
    )

    USER_AGENT = "aiohttp JSON-RPC client (Python: {0}, version: {1})".format(