MCPcopy
hub / github.com/encode/httpx / encoding

Method encoding

httpx/_models.py:167–189  ·  view source on GitHub ↗

Header encoding is mandated as ascii, but we allow fallbacks to utf-8 or iso-8859-1.

(self)

Source from the content-addressed store, hash-verified

165
166 @property
167 def encoding(self) -> str:
168 """
169 Header encoding is mandated as ascii, but we allow fallbacks to utf-8
170 or iso-8859-1.
171 """
172 if self._encoding is None:
173 for encoding in ["ascii", "utf-8"]:
174 for key, value in self.raw:
175 try:
176 key.decode(encoding)
177 value.decode(encoding)
178 except UnicodeDecodeError:
179 break
180 else:
181 # The else block runs if 'break' did not occur, meaning
182 # all values fitted the encoding.
183 self._encoding = encoding
184 break
185 else:
186 # The ISO-8859-1 encoding covers all 256 code points in a byte,
187 # so will never raise decode errors.
188 self._encoding = "iso-8859-1"
189 return self._encoding
190
191 @encoding.setter
192 def encoding(self, value: str) -> None:

Callers

nothing calls this directly

Calls 1

decodeMethod · 0.45

Tested by

no test coverage detected