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


Python HTTPHeaderMap.get方法代码示例

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


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

示例1: DummyResponse

# 需要导入模块: from hyper.common.headers import HTTPHeaderMap [as 别名]
# 或者: from hyper.common.headers.HTTPHeaderMap import get [as 别名]
class DummyResponse(object):
    def __init__(self, headers):
        self.headers = HTTPHeaderMap(headers.items())

    def read(self):
        ctype = self.headers.get('content-type')
        if ctype is not None:
            if 'json' in ctype[0].decode('utf-8'):
                return b'{"data": "dummy"}'
        return b'<html>dummy</html>'

    def getheader(self, name):
        return self.headers.get(name)

    def getheaders(self):
        return self.headers
开发者ID:AvivC,项目名称:hyper,代码行数:18,代码来源:test_cli.py

示例2: test_actual_get

# 需要导入模块: from hyper.common.headers import HTTPHeaderMap [as 别名]
# 或者: from hyper.common.headers.HTTPHeaderMap import get [as 别名]
    def test_actual_get(self):
        h = HTTPHeaderMap()
        h['k1'] = 'v1, v2'
        h['k2'] = 'v3'
        h['k1'] = 'v4'

        assert h.get('k1') == [b'v1', b'v2', b'v4']
开发者ID:AvivC,项目名称:hyper,代码行数:9,代码来源:test_headers.py

示例3: Stream

# 需要导入模块: from hyper.common.headers import HTTPHeaderMap [as 别名]
# 或者: from hyper.common.headers.HTTPHeaderMap import get [as 别名]
class Stream(object):
    """
    A single HTTP/2 stream.

    A stream is an independent, bi-directional sequence of HTTP headers and
    data. Each stream is identified by a single integer. From a HTTP
    perspective, a stream _approximately_ matches a single request-response
    pair.
    """
    def __init__(self,
                 logger,
                 config,
                 connection,
                 ip,
                 stream_id,
                 task,
                 send_cb,
                 close_cb,
                 encoder,
                 decoder,
                 receive_window_manager,
                 remote_window_size,
                 max_frame_size):

        self.logger = logger
        self.config = config
        self.connection = connection
        self.ip = ip
        self.stream_id = stream_id
        self.task = task
        self.state = STATE_IDLE
        self.get_head_time = None

        # There are two flow control windows: one for data we're sending,
        # one for data being sent to us.
        self.receive_window_manager = receive_window_manager
        self.remote_window_size = remote_window_size
        self.max_frame_size = max_frame_size

        # This is the callback handed to the stream by its parent connection.
        # It is called when the stream wants to send data. It expects to
        # receive a list of frames that will be automatically serialized.
        self._send_cb = send_cb

        # This is the callback to be called when the stream is closed.
        self._close_cb = close_cb

        # A reference to the header encoder and decoder objects belonging to
        # the parent connection.
        self._encoder = encoder
        self._decoder = decoder

        self.request_headers = HTTPHeaderMap()

        # Convert the body to bytes if needed.
        self.request_body = to_bytestring(self.task.body)

        # request body not send blocked by send window
        # the left body will send when send window opened.
        self.request_body_left = len(self.request_body)
        self.request_body_sended = False

        # data list before decode
        self.response_header_datas = []

        # Set to a key-value set of the response headers once their
        # HEADERS..CONTINUATION frame sequence finishes.
        self.response_headers = None

        # Unconsumed response data chunks
        self.response_body = []
        self.response_body_len = 0

    def start_request(self):
        """
        Open the stream. Does this by encoding and sending the headers: no more
        calls to ``add_header`` are allowed after this method is called.
        The `end` flag controls whether this will be the end of the stream, or
        whether data will follow.
        """
        # Strip any headers invalid in H2.
        #headers = h2_safe_headers(self.request_headers)

        host = self.connection.get_host(self.task.host)

        self.add_header(":method", self.task.method)
        self.add_header(":scheme", "https")
        self.add_header(":authority", host)
        self.add_header(":path", self.task.path)

        default_headers = (':method', ':scheme', ':authority', ':path')
        #headers = h2_safe_headers(self.task.headers)
        for name, value in self.task.headers.items():
            is_default = to_native_string(name) in default_headers
            self.add_header(name, value, replace=is_default)

        # Encode the headers.
        encoded_headers = self._encoder(self.request_headers)

        # It's possible that there is a substantial amount of data here. The
#.........这里部分代码省略.........
开发者ID:liivin,项目名称:XX-Net,代码行数:103,代码来源:http2_stream.py

示例4: test_doesnt_split_set_cookie

# 需要导入模块: from hyper.common.headers import HTTPHeaderMap [as 别名]
# 或者: from hyper.common.headers.HTTPHeaderMap import get [as 别名]
 def test_doesnt_split_set_cookie(self):
     h = HTTPHeaderMap()
     h['Set-Cookie'] = 'v1, v2'
     assert h['set-cookie'] == [b'v1, v2']
     assert h.get(b'set-cookie') == [b'v1, v2']
开发者ID:AvivC,项目名称:hyper,代码行数:7,代码来源:test_headers.py

示例5: test_empty_get

# 需要导入模块: from hyper.common.headers import HTTPHeaderMap [as 别名]
# 或者: from hyper.common.headers.HTTPHeaderMap import get [as 别名]
 def test_empty_get(self):
     h = HTTPHeaderMap()
     assert h.get('nonexistent', 'hi there') == 'hi there'
开发者ID:AvivC,项目名称:hyper,代码行数:5,代码来源:test_headers.py


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