r"""Guess encoding from xml header declaration.

        :param content: xml content
        :rtype: str or None
546539
def guess_xml_encoding(self, content):
        
        """
        matchobj = self.__regex['xml_encoding'].match(content)
        return matchobj and matchobj.group(1).lower()
224335
def parse_content_type(content_type):
    
    if '; charset=' in content_type:
        return tuple(content_type.split('; charset='))
    else:
        if 'text' in content_type:
            encoding = 'ISO-8859-1'
        else:
            try:
                format = formats.find_by_content_type(content_type)
            except formats.UnknownFormat:
                encoding = 'ISO-8859-1'
            else:
                encoding = format.default_encoding or 'ISO-8859-1'

        return (content_type, encoding)
390464
def xml_filter(self, content):
        
        """
        content = utils.strip_whitespace(content, True) if self.__options['strip'] else content.strip()

        if not self.__options['encoding']:
            encoding = self.guess_xml_encoding(content) or self.__encoding
            self.set_options(encoding=encoding)

        if self.__options['encoding'].lower() != self.__encoding:
            # 编码转换去除xml头
            content = self.strip_xml_header(content.decode(self.__options['encoding'], errors=self.__options['errors']))

        if self.__options['unescape']:
            content = utils.html_entity_decode(content)
        return content
808390
def content_type(self, value=None):
		
		content_type = self.normalize_name('Content-Type')
		if value is not None:
			self.replace_headers(content_type, value)
		if content_type in self.__headers.keys():
			return self.__headers[content_type][0]
237447
def guess_encoding(request):
    
    ctype = request.headers.get('content-type')
    if not ctype:
        # we don't have a content-type, somehow, so...
        LOGGER.warning("%s: no content-type; headers are %s",
                       request.url, request.headers)
        return 'utf-8'

    # explicit declaration
    match = re.search(r'charset=([^ ;]*)(;| |$)', ctype)
    if match:
        return match[1]

    # html default
    if ctype.startswith('text/html'):
        return 'iso-8859-1'

    # everything else's default
    return 'utf-8'
949510
def get_encoding_from_headers(headers):
    

    content_type = headers.get('content-type')

    if not content_type:
        return None

    content_type, params = _parse_content_type_header(content_type)

    if 'charset' in params:
        return params['charset'].strip("'\"")

    if 'text' in content_type:
        return 'ISO-8859-1'
651641
def header(self, content):
        
        header = Element("Header", ns=envns)
        header.append(content)
        return header
171411
function parseContentTypeHeader ( str ) {
	if ( /charset=$/.test(str) ) {
		str = `${str}utf8`;
	}
	return contentType.parse(str);
}
1117393
def clear_content(self, content):
        
        content = _unicode(content)
        return self.wrapper_match.sub("", content)
1268408
def charset(self):
        """"""
        header = self.environ.get('CONTENT_TYPE')
        if header:
            ct, options = parse_options_header(header)
            charset = options.get('charset')
            if charset:
                if is_known_charset(charset):
                    return charset
                return self.unknown_charset(charset)
        return self.default_charset
367598
def _decode_content(self, content):
        
        content = smart_unicode(content)
        uri, _, content = content.partition(u'|')
        if content == self.NONE:
            content = None
        return uri or None, content
869542
def content_transfer_encoding(self) \
            -> Optional[ContentTransferEncodingHeader]:
        """"""
        try:
            return cast(ContentTransferEncodingHeader,
                        self[b'content-transfer-encoding'][0])
        except (KeyError, IndexError):
            return None
692492
def guess_file_encoding(fh, default=DEFAULT_ENCODING):
    """"""
    start = fh.tell()
    detector = chardet.UniversalDetector()
    while True:
        data = fh.read(1024 * 10)
        if not data:
            detector.close()
            break
        detector.feed(data)
        if detector.done:
            break

    fh.seek(start)
    return normalize_result(detector.result, default=default)
756068
def _has_xml_encode(self, content):
        """"""

        encode = None

        m = RE_XML_START.match(content)
        if m:
            if m.group(1):
                m2 = RE_XML_ENCODE.match(m.group(1))

                if m2:
                    enc = m2.group(2).decode('ascii')

                    try:
                        codecs.getencoder(enc)
                        encode = enc
                    except LookupError:
                        pass
            else:
                if m.group(2):
                    enc = 'utf-32-be'
                    text = m.group(2)
                elif m.group(3):
                    enc = 'utf-32-le'
                    text = m.group(3)
                elif m.group(4):
                    enc = 'utf-16-be'
                    text = m.group(4)
                elif m.group(5):
                    enc = 'utf-16-le'
                    text = m.group(5)
                try:
                    m2 = RE_XML_ENCODE_U.match(text.decode(enc))
                except Exception:  # pragma: no cover
                    m2 = None

                if m2:
                    enc = m2.group(2)

                    try:
                        codecs.getencoder(enc)
                        encode = enc
                    except Exception:
                        pass

        return encode
1183012
def contents(self):
        """"""
        if not IS_PY2 and isinstance(self.byte_contents, bytes):
            return self.byte_contents.decode(
                self.encoding or locale.getpreferredencoding(False),
                errors=self.errors)
        return self.byte_contents
915466
def smart_content_encoding(self):
        """"""
        encoding = self.content_encoding
        if not encoding:
            base_list = self.basename.split('.')
            while (not encoding) and len(base_list) > 1:
                _, encoding = mimetypes.guess_type('.'.join(base_list))
                base_list.pop()

        return encoding
461393
def content_id(self) -> Optional[UnstructuredHeader]:
        """"""
        try:
            return cast(UnstructuredHeader, self[b'content-id'][0])
        except (KeyError, IndexError):
            return None