def _headers_encoding(self): content_type = self.headers.get('Content-Type') if content_type: m = self._ENCODING_RE.search(content_type) if m: encoding = m.group(1) if encoding_exists(encoding): return encoding
def _get_encoding(self, infer=False): enc = self._declared_encoding() if enc and not encoding_exists(enc): enc = None if not enc and infer: enc = self._body_inferred_encoding() if not enc: enc = self._DEFAULT_ENCODING return resolve_encoding(enc)
def test_encoding_exists(self): assert encoding_exists('latin1', self._ENCODING_ALIASES) assert encoding_exists('foo', self._ENCODING_ALIASES) assert not encoding_exists('bar', self._ENCODING_ALIASES) assert not encoding_exists('none', self._ENCODING_ALIASES)