MCPcopy Create free account
hub / github.com/EasyIME/PIME / HTTPHeaders

Class HTTPHeaders

python/python3/tornado/httputil.py:76–244  ·  view source on GitHub ↗

A dictionary that maintains ``Http-Header-Case`` for all keys. Supports multiple values per key via a pair of new methods, `add()` and `get_list()`. The regular dictionary interface returns a single value per key, with multiple values joined by a comma. >>> h = HTTPHeaders({"c

Source from the content-addressed store, hash-verified

74
75
76class HTTPHeaders(collections.abc.MutableMapping):
77 """A dictionary that maintains ``Http-Header-Case`` for all keys.
78
79 Supports multiple values per key via a pair of new methods,
80 `add()` and `get_list()`. The regular dictionary interface
81 returns a single value per key, with multiple values joined by a
82 comma.
83
84 >>> h = HTTPHeaders({"content-type": "text/html"})
85 >>> list(h.keys())
86 ['Content-Type']
87 >>> h["Content-Type"]
88 'text/html'
89
90 >>> h.add("Set-Cookie", "A=B")
91 >>> h.add("Set-Cookie", "C=D")
92 >>> h["set-cookie"]
93 'A=B,C=D'
94 >>> h.get_list("set-cookie")
95 ['A=B', 'C=D']
96
97 >>> for (k,v) in sorted(h.get_all()):
98 ... print('%s: %s' % (k,v))
99 ...
100 Content-Type: text/html
101 Set-Cookie: A=B
102 Set-Cookie: C=D
103 """
104
105 @typing.overload
106 def __init__(self, __arg: Mapping[str, List[str]]) -> None:
107 pass
108
109 @typing.overload # noqa: F811
110 def __init__(self, __arg: Mapping[str, str]) -> None:
111 pass
112
113 @typing.overload # noqa: F811
114 def __init__(self, *args: Tuple[str, str]) -> None:
115 pass
116
117 @typing.overload # noqa: F811
118 def __init__(self, **kwargs: str) -> None:
119 pass
120
121 def __init__(self, *args: typing.Any, **kwargs: str) -> None: # noqa: F811
122 self._dict = {} # type: typing.Dict[str, str]
123 self._as_list = {} # type: typing.Dict[str, typing.List[str]]
124 self._last_key = None # type: Optional[str]
125 if len(args) == 1 and len(kwargs) == 0 and isinstance(args[0], HTTPHeaders):
126 # Copy constructor
127 for k, v in args[0].get_all():
128 self.add(k, v)
129 else:
130 # Dict-style initialization
131 self.update(*args, **kwargs)
132
133 # new public methods

Callers 15

finishMethod · 0.90
handle_requestMethod · 0.90
test_header_reuseMethod · 0.90
respond_100Method · 0.90
respond_204Method · 0.90
test_copyMethod · 0.90
test_pickle_roundtripMethod · 0.90
test_setdefaultMethod · 0.90
test_stringMethod · 0.90
finishMethod · 0.90
finishMethod · 0.90

Calls

no outgoing calls

Tested by 13

finishMethod · 0.72
handle_requestMethod · 0.72
test_header_reuseMethod · 0.72
respond_100Method · 0.72
respond_204Method · 0.72
test_copyMethod · 0.72
test_pickle_roundtripMethod · 0.72
test_setdefaultMethod · 0.72
test_stringMethod · 0.72
finishMethod · 0.72
finishMethod · 0.72