human
Complete the below
def _getCharacterEncoding(http_headers, xml_data):

    ''''Get the character encoding of the XML document
    http_headers is a dictionary
    xml_data is a raw string (not Unicode)
    This is so much trickier than it sounds, it\'s not even funny.
    According to RFC 3023 (\'XML Media Types\'), if the HTTP Content-Type
    is application/xml, application/*+xml,
    application/xml-external-parsed-entity, or application/xml-dtd,
    the encoding given in the charset parameter of the HTTP Content-Type
    takes precedence over the encoding given in the XML prefix within the
    document, and defaults to \'utf-8\' if neither are specified.  But, if
    the HTTP Content-Type is text/xml, text/*+xml, or
    text/xml-external-parsed-entity, the encoding given in the XML prefix
    within the document is ALWAYS IGNORED and only the encoding given in
    the charset parameter of the HTTP Content-Type header should be
    respected, and it defaults to \'us-ascii\' if not specified.
    Furthermore, discussion on the atom-syntax mailing list with the
    author of RFC 3023 leads me to the conclusion that any document
    served with a Content-Type of text/* and no charset parameter
    must be treated as us-ascii.  (We now do this.)  And also that it
    must always be flagged as non-well-formed.  (We now do this too.)
    If Content-Type is unspecified (input was local file or non-HTTP source)
    or unrecognized (server just got it totally wrong), then go by the
    encoding given in the XML prefix of the document and default to
    \'iso-8859-1\' as per the HTTP specification (RFC 2616).
    Then, assuming we didn\'t find a character encoding in the HTTP headers
    (and the HTTP Content-type allowed us to look in the body), we need
    to sniff the first few bytes of the XML data and try to determine
    whether the encoding is ASCII-compatible.  Section F of the XML
    specification shows the way here:
    http://www.w3.org/TR/REC-xml/#sec-guessing-no-ext-info
    If the sniffed encoding is not ASCII-compatible, we need to make it
    ASCII compatible so that we can...'''
assistant
#Here is Python code to find a character encoding in the HTTP headers
.
    def _parseHTTPContentType(content_type):
        "takes    HTTP    Content-Type    header    and    returns    (content    type,    charset)\n\n                                If    no    charset    is    specified,    returns    (content    type,    '')\n                                If    no    content    type    is    specified,    returns    ('',    '')\n                                Both    return    parameters    are    guaranteed    to    be    lowercase    strings\n                                "
        content_type = (content_type or '')
        (content_type, params) = cgi.parse_header(content_type)
        charset = params.get('charset', '').replace("'", '')
        if (not isinstance(charset, unicode)):
            charset = charset.decode('utf-8', 'ignore')
        return (content_type, charset)
    sniffed_xml_encoding = u''
    xml_encoding = u''
    true_encoding = u''
    (http_content_type, http_encoding) = _parseHTTPContentType(http_headers.get('content-type'))
    try:
        if (xml_data[:4] == _l2bytes([76, 111, 167, 148])):
            sniffed_xml_encoding = u'cp037'
            xml_data = xml_data.decode('cp037').encode('utf-8')
        elif (xml_data[:4] == _l2bytes([0, 60, 0, 63])):
            sniffed_xml_encoding = u'utf-16be'
            xml_data = unicode(xml_data, 'utf-16be').encode('utf-8')
        elif ((len(xml_data) >= 4) and (xml_data[:2] == _l2bytes([254, 255])) and (xml_data[2:4] != _l2bytes([0, 0]))):
            sniffed_xml_encoding = u'utf-16be'
            xml_data = unicode(xml_data[2:], 'utf-16be').encode('utf-8')
        elif (xml_data[:4] == _l2bytes([60, 0, 63, 0])):
            sniffed_xml_encoding = u'utf-16le'
            xml_data = unicode(xml_data, 'utf-16le').encode('utf-8')
        elif ((len(xml_data) >= 4) and (xml_data[:2] == _l2bytes([255, 254])) and (xml_data[2:4] != _l2bytes([0, 0]))):
            sniffed_xml_encoding = u'utf-16le'
            xml_data = unicode(xml_data[2:], 'utf-16le').encode('utf-8')
        elif (xml_data[:4] ==...