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

Method parse_line

python/python3/tornado/httputil.py:162–182  ·  view source on GitHub ↗

Updates the dictionary with a single header line. >>> h = HTTPHeaders() >>> h.parse_line("Content-Type: text/html") >>> h.get('content-type') 'text/html'

(self, line: str)

Source from the content-addressed store, hash-verified

160 yield (name, value)
161
162 def parse_line(self, line: str) -> None:
163 """Updates the dictionary with a single header line.
164
165 >>> h = HTTPHeaders()
166 >>> h.parse_line("Content-Type: text/html")
167 >>> h.get('content-type')
168 'text/html'
169 """
170 if line[0].isspace():
171 # continuation of a multi-line header
172 if self._last_key is None:
173 raise HTTPInputError("first header line cannot start with whitespace")
174 new_part = " " + line.lstrip()
175 self._as_list[self._last_key][-1] += new_part
176 self._dict[self._last_key] += new_part
177 else:
178 try:
179 name, value = line.split(":", 1)
180 except ValueError:
181 raise HTTPInputError("no colon in header line")
182 self.add(name, value.strip())
183
184 @classmethod
185 def parse(cls, headers: str) -> "HTTPHeaders":

Callers 2

_curl_header_callbackMethod · 0.80
parseMethod · 0.80

Calls 3

addMethod · 0.95
HTTPInputErrorClass · 0.85
splitMethod · 0.80

Tested by

no test coverage detected