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


Python multidict.CIMultiDict方法代码示例

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


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

示例1: __init__

# 需要导入模块: import multidict [as 别名]
# 或者: from multidict import CIMultiDict [as 别名]
def __init__(self, status, content, headers=None):
        self.status = status

        if headers is None:
            self.headers = CIMultiDict()
            if content is not None and type(content) == bytes:
                self.headers["Content-Type"] = "application/octet-stream"
            else:
                self.headers["Content-Type"] = "text/html"
        else:
            if type(headers) == str:
                self.headers = CIMultiDict([("Content-Type", headers)])
            else:
                self.headers = headers

        self.content = content 
开发者ID:manatlan,项目名称:wuy,代码行数:18,代码来源:wuy.py

示例2: Response

# 需要导入模块: import multidict [as 别名]
# 或者: from multidict import CIMultiDict [as 别名]
def Response(method="GET", status=200, body=b"***"):
    response = LoggedClientResponse(method, URL("/"), **_respkw())
    response.status = status
    response.reason = ""
    response.code = status
    response.should_close = False
    response._headers = CIMultiDict({})
    response._raw_headers = []

    class Body:
        async def read(self):
            return body

        def unread_data(self, data):
            if body == b"":
                err = AttributeError(
                    "'EmptyStreamReader' object has no " "attribute 'unread_data'"
                )
                raise err
            pass

    response.content = Body()
    response._content = body

    return response 
开发者ID:loads,项目名称:molotov,代码行数:27,代码来源:support.py

示例3: from_request

# 需要导入模块: import multidict [as 别名]
# 或者: from multidict import CIMultiDict [as 别名]
def from_request(cls, request, status_code, status_message, payload=None, headers=None):

        if not headers:
            headers = CIMultiDict()

        if 'Via' not in headers:
            headers['Via'] = request.headers['Via']

        return Response(
            status_code=status_code,
            status_message=status_message,
            cseq=request.cseq,
            method=request.method,
            headers=headers,
            from_details=request.from_details,
            to_details=request.to_details,
            contact_details=request.contact_details,
            payload=payload,
        ) 
开发者ID:Eyepea,项目名称:aiosip,代码行数:21,代码来源:message.py

示例4: fromRequestWillBeSent

# 需要导入模块: import multidict [as 别名]
# 或者: from multidict import CIMultiDict [as 别名]
def fromRequestWillBeSent (self, req):
        """ Set request data from Chrome Network.requestWillBeSent event """
        r = req['request']

        self.id = req['requestId']
        self.url = URL (r['url'])
        self.resourceType = req.get ('type')
        self._time = ReferenceTimestamp (req['timestamp'], req['wallTime'])

        assert self.request is None, req
        self.request = Request ()
        self.request.initiator = req['initiator']
        self.request.headers = CIMultiDict (self._unfoldHeaders (r['headers']))
        self.request.hasPostData = r.get ('hasPostData', False)
        self.request.method = r['method']
        self.request.timestamp = self._time (req['timestamp'])
        if self.request.hasPostData:
            postData = r.get ('postData')
            if postData is not None:
                self.request.body = UnicodeBody (postData) 
开发者ID:PromyLOPh,项目名称:crocoite,代码行数:22,代码来源:browser.py

示例5: test_parse_type_one_error

# 需要导入模块: import multidict [as 别名]
# 或者: from multidict import CIMultiDict [as 别名]
def test_parse_type_one_error(self):
        self.requested_name = 'something/'
        self.detection = {"type": 1}
        self.expected_content = None
        self.headers = multidict.CIMultiDict()
        self.status_code = 404

        async def test():
            (self.res1, self.res2, self.res3) = \
                await self.handler.parse_tanner_response(
                    self.requested_name, self.detection)

        self.loop.run_until_complete(test())
        real_result = [self.res1, self.res2, self.res3]
        expected_result = [self.expected_content, self.headers, self.status_code]
        self.assertCountEqual(real_result, expected_result) 
开发者ID:mushorg,项目名称:snare,代码行数:18,代码来源:test_tanner_handler_parse_tanner_response.py

示例6: test_parse_type_two_with_headers

# 需要导入模块: import multidict [as 别名]
# 或者: from multidict import CIMultiDict [as 别名]
def test_parse_type_two_with_headers(self):
        self.detection = {
            "type": 2,
            "payload": {
                "page": "",
                "value": "test.png",
                "headers": {
                    "content-type": "multipart/form-data",
                },
            },
        }
        self.expected_content = b'test.png'
        self.content_type = 'image/png'
        self.headers = multidict.CIMultiDict([("Content-Type", "multipart/form-data")])

        async def test():
            (self.res1, self.res2, self.res3) = \
                await self.handler.parse_tanner_response(
                    self.requested_name, self.detection)

        self.loop.run_until_complete(test())
        real_result = [self.res1, self.res2, self.res3]
        expected_result = [self.expected_content, self.headers, self.status_code]

        self.assertCountEqual(real_result, expected_result) 
开发者ID:mushorg,项目名称:snare,代码行数:27,代码来源:test_tanner_handler_parse_tanner_response.py

示例7: test_parse_type_three

# 需要导入模块: import multidict [as 别名]
# 或者: from multidict import CIMultiDict [as 别名]
def test_parse_type_three(self):
        self.detection = {
            "type": 3,
            "payload": {
                "page": "/index.html",
                "value": "test",
                "status_code": 200,
            },
        }
        self.expected_content = None
        self.headers = multidict.CIMultiDict()

        async def test():
            (self.res1, self.res2, self.res3) = \
                await self.handler.parse_tanner_response(
                    self.requested_name, self.detection)

        self.loop.run_until_complete(test())
        real_result = [self.res1, self.res2, self.res3]
        expected_result = [self.expected_content, self.headers, self.status_code]
        self.assertCountEqual(real_result, expected_result) 
开发者ID:mushorg,项目名称:snare,代码行数:23,代码来源:test_tanner_handler_parse_tanner_response.py

示例8: __init__

# 需要导入模块: import multidict [as 别名]
# 或者: from multidict import CIMultiDict [as 别名]
def __init__(self, *,
                 status: int=200,
                 reason: Optional[str]=None,
                 headers: Optional[LooseHeaders]=None) -> None:
        self._body = None
        self._keep_alive = None  # type: Optional[bool]
        self._chunked = False
        self._compression = False
        self._compression_force = None  # type: Optional[ContentCoding]
        self._cookies = SimpleCookie()

        self._req = None  # type: Optional[BaseRequest]
        self._payload_writer = None  # type: Optional[AbstractStreamWriter]
        self._eof_sent = False
        self._body_length = 0
        self._state = {}  # type: Dict[str, Any]

        if headers is not None:
            self._headers = CIMultiDict(headers)  # type: CIMultiDict[str]
        else:
            self._headers = CIMultiDict()  # type: CIMultiDict[str]

        self.set_status(status, reason) 
开发者ID:TouwaStar,项目名称:Galaxy_Plugin_Bethesda,代码行数:25,代码来源:web_response.py

示例9: _prepare_headers

# 需要导入模块: import multidict [as 别名]
# 或者: from multidict import CIMultiDict [as 别名]
def _prepare_headers(
            self,
            headers: Optional[LooseHeaders]) -> 'CIMultiDict[str]':
        """ Add default headers and transform it to CIMultiDict
        """
        # Convert headers to MultiDict
        result = CIMultiDict(self._default_headers)
        if headers:
            if not isinstance(headers, (MultiDictProxy, MultiDict)):
                headers = CIMultiDict(headers)
            added_names = set()  # type: Set[str]
            for key, value in headers.items():
                if key in added_names:
                    result.add(key, value)
                else:
                    result[key] = value
                    added_names.add(key)
        return result 
开发者ID:TouwaStar,项目名称:Galaxy_Plugin_Bethesda,代码行数:20,代码来源:client.py

示例10: on_headers_complete

# 需要导入模块: import multidict [as 别名]
# 或者: from multidict import CIMultiDict [as 别名]
def on_headers_complete(self):
        remote_addr = self.transport.get_extra_info('peername')
        if remote_addr:
            self.headers.append(('Remote-Addr', '%s:%s' % remote_addr))

        #
        # 构建 HTTP 请求
        #
        self.request = Request(
            url_bytes=self.url,
            headers=CIMultiDict(self.headers),
            version=self.parser.get_http_version(),
            method=self.parser.get_method().decode()
        )

    #
    # HTTP 请求: 写入 body 部分
    # 
开发者ID:hhstore,项目名称:annotated-py-projects,代码行数:20,代码来源:server.py

示例11: do_parser

# 需要导入模块: import multidict [as 别名]
# 或者: from multidict import CIMultiDict [as 别名]
def do_parser(body, body_bytes, resp_headers, url, crawler):
    if len(body) > int(config.read('Multiprocess', 'ParseInBurnerSize')):
        stats.stats_sum('parser in burner thread', 1)
        # headers is a multidict.CIMultiDictProxy case-blind dict
        # and the Proxy form of it doesn't pickle, so convert to one that does
        resp_headers = multidict.CIMultiDict(resp_headers)
        links, embeds, sha1, facets, base = await crawler.burner.burn(
            partial(do_burner_work_html, body, body_bytes, resp_headers,
                    burn_prefix='burner ', url=url),
            url=url)
    else:
        stats.stats_sum('parser in main thread', 1)
        # no coroutine state because this is a burn, not an await
        links, embeds, sha1, facets, base = do_burner_work_html(
            body, body_bytes, resp_headers, burn_prefix='main ', url=url)

    return links, embeds, sha1, facets, base 
开发者ID:cocrawler,项目名称:cocrawler,代码行数:19,代码来源:parse.py

示例12: __init__

# 需要导入模块: import multidict [as 别名]
# 或者: from multidict import CIMultiDict [as 别名]
def __init__(self, *, status=200, reason=None, headers=None):
        self._body = None
        self._keep_alive = None
        self._chunked = False
        self._compression = False
        self._compression_force = False
        self._cookies = SimpleCookie()

        self._req = None
        self._payload_writer = None
        self._eof_sent = False
        self._body_length = 0

        if headers is not None:
            self._headers = CIMultiDict(headers)
        else:
            self._headers = CIMultiDict()

        self.set_status(status, reason) 
开发者ID:skylander86,项目名称:lambda-text-extractor,代码行数:21,代码来源:web_response.py

示例13: _prepare_headers

# 需要导入模块: import multidict [as 别名]
# 或者: from multidict import CIMultiDict [as 别名]
def _prepare_headers(self, headers):
        """ Add default headers and transform it to CIMultiDict
        """
        # Convert headers to MultiDict
        result = CIMultiDict(self._default_headers)
        if headers:
            if not isinstance(headers, (MultiDictProxy, MultiDict)):
                headers = CIMultiDict(headers)
            added_names = set()
            for key, value in headers.items():
                if key in added_names:
                    result.add(key, value)
                else:
                    result[key] = value
                    added_names.add(key)
        return result 
开发者ID:skylander86,项目名称:lambda-text-extractor,代码行数:18,代码来源:client.py

示例14: __init__

# 需要导入模块: import multidict [as 别名]
# 或者: from multidict import CIMultiDict [as 别名]
def __init__(
        self,
        application,
        use_cookies: bool = True,
        timeout: Optional[Union[int, float]] = None,
        headers: Optional[Union[dict, CIMultiDict]] = None,
        scope: Optional[dict] = None,
    ):
        self.application = guarantee_single_callable(application)
        self.cookie_jar: Optional[
            SimpleCookie
        ] = SimpleCookie() if use_cookies else None
        self.timeout = timeout
        self.headers = headers or {}
        self._scope = scope or {}
        self._lifespan_input_queue: asyncio.Queue[dict] = asyncio.Queue()
        self._lifespan_output_queue: asyncio.Queue[dict] = asyncio.Queue() 
开发者ID:vinissimus,项目名称:async-asgi-testclient,代码行数:19,代码来源:testing.py

示例15: __init__

# 需要导入模块: import multidict [as 别名]
# 或者: from multidict import CIMultiDict [as 别名]
def __init__(self, *, body: Optional[Union[bytes, str]] = None, status: int = 200, reason: Optional[str] = None, headers: Optional[Union[Dict, CIMultiDict, CIMultiDictProxy]] = None, content_type: Optional[str] = None, charset: Optional[str] = None) -> None:
        if headers is None:
            headers = CIMultiDict()
        elif not isinstance(headers, (CIMultiDict, CIMultiDictProxy)):
            headers = CIMultiDict(headers)

        self._body = body
        self._status = status
        self._reason = reason
        self._headers = headers
        self.content_type = content_type if hdrs.CONTENT_TYPE not in headers else None
        self.charset = charset if hdrs.CONTENT_TYPE not in headers else None

        self.missing_content_type = hdrs.CONTENT_TYPE not in headers and not content_type and not charset 
开发者ID:kalaspuff,项目名称:tomodachi,代码行数:16,代码来源:http.py


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