(encoding, warn=True)
return encoding
Checks encoding name, repairs common misspellings and adjusts to
    proper namings used in codecs module

    >>> checkCharEncoding('iso-8858', False)
    'iso8859-1'
    >>> checkCharEncoding('en_us', False)
    'utf8'
Checks encoding name, repairs common misspellings and adjusts to
    proper namings used in codecs module
Checks encoding name repairs common misspellings and adjusts to proper namings used in codecs module
def checkCharEncoding(encoding, warn=True):
    """
    Checks encoding name, repairs common misspellings and adjusts to
    proper namings used in codecs module

    >>> checkCharEncoding('iso-8858', False)
    'iso8859-1'
    >>> checkCharEncoding('en_us', False)
    'utf8'
    """

    if encoding:
        encoding = encoding.lower()
    else:
        return encoding

    # Reference: http://www.destructor.de/charsets/index.htm
    translate = {"windows-874": "iso-8859-11", "en_us": "utf8", "macintosh": "iso-8859-1", "euc_tw": "big5_tw", "th": "tis-620", "unicode": "utf8",  "utc8": "utf8", "ebcdic": "ebcdic-cp-be", "iso-8859": "iso8859-1", "ansi": "ascii", "gbk2312": "gbk", "windows-31j": "cp932"}

    for delimiter in (';', ',', '('):
        if delimiter in encoding:
            encoding = encoding[:encoding.find(delimiter)].strip()

    # popular typos/errors
    if "8858" in encoding:
        encoding = encoding.replace("8858", "8859")  # iso-8858 -> iso-8859
    elif "8559" in encoding:
        encoding = encoding.replace("8559", "8859")  # iso-8559 -> iso-8859
    elif "5889" in encoding:
        encoding = encoding.replace("5889", "8859")  # iso-5889 -> iso-8859
    elif "5589" in encoding:
        encoding = encoding.replace("5589", "8859")  # iso-5589 -> iso-8859
    elif "2313" in encoding:
        encoding = encoding.replace("2313", "2312")  # gb2313 -> gb2312
    elif encoding.startswith("x-"):
        encoding = encoding[len("x-"):]              # x-euc-kr -> euc-kr  /  x-mac-turkish -> mac-turkish
    elif "windows-cp" in encoding:
        encoding = encoding.replace("windows-cp", "windows")  # windows-cp-1254 -> windows-1254

    # name adjustment for compatibility
    if encoding.startswith("8859"):
        encoding = "iso-%s" % encoding
    elif encoding.startswith("cp-"):
        encoding = "cp%s" % encoding[3:]
    elif encoding.startswith("euc-"):
        encoding = "euc_%s" % encoding[4:]
    elif encoding.startswith("windows") and not encoding.startswith("windows-"):
        encoding = "windows-%s" % encoding[7:]
    elif encoding.find("iso-88") > 0:
        encoding = encoding[encoding.find("iso-88"):]
    elif encoding.startswith("is0-"):
        encoding = "iso%s" % encoding[4:]
    elif encoding.find("ascii") > 0:
        encoding = "ascii"
    elif encoding.find("utf8") > 0:
        encoding = "utf8"

    # Reference: http://philip.html5.org/data/charsets-2.html
    if encoding in translate:
        encoding = translate[encoding]
    elif encoding in ("null", "{charset}", "*") or not re.search(r"\w", encoding):
        return None

    # Reference: http://www.iana.org/assignments/character-sets
    # Reference: http://docs.python.org/library/codecs.html
    try:
        codecs.lookup(encoding.encode(UNICODE_ENCODING) if isinstance(encoding, unicode) else encoding)
    except LookupError:
        if warn:
            warnMsg = "unknown web page charset '%s'. " % encoding
            warnMsg += "Please report by e-mail to 'dev@sqlmap.org'"
            singleTimeLogMessage(warnMsg, logging.WARN, encoding)
        encoding = None

    return encoding
def checkCharEncoding ( encoding , warn = True ) : if encoding : encoding = encoding . lower ( ) else : return encoding # Reference: http://www.destructor.de/charsets/index.htm translate = { "windows-874" : "iso-8859-11" , "en_us" : "utf8" , "macintosh" : "iso-8859-1" , "euc_tw" : "big5_tw" , "th" : "tis-620" , "unicode" : "utf8" , "utc8" : "utf8" , "ebcdic" : "ebcdic-cp-be" , "iso-8859" : "iso8859-1" , "ansi" : "ascii" , "gbk2312" : "gbk" , "windows-31j" : "cp932" } for delimiter in ( ';' , ',' , '(' ) : if delimiter in encoding : encoding = encoding [ : encoding . find ( delimiter ) ] . strip ( ) # popular typos/errors if "8858" in encoding : encoding = encoding . replace ( "8858" , "8859" ) # iso-8858 -> iso-8859 elif "8559" in encoding : encoding = encoding . replace ( "8559" , "8859" ) # iso-8559 -> iso-8859 elif "5889" in encoding : encoding = encoding . replace ( "5889" , "8859" ) # iso-5889 -> iso-8859 elif "5589" in encoding : encoding = encoding . replace ( "5589" , "8859" ) # iso-5589 -> iso-8859 elif "2313" in encoding : encoding = encoding . replace ( "2313" , "2312" ) # gb2313 -> gb2312 elif encoding . startswith ( "x-" ) : encoding = encoding [ len ( "x-" ) : ] # x-euc-kr -> euc-kr  /  x-mac-turkish -> mac-turkish elif "windows-cp" in encoding : encoding = encoding . replace ( "windows-cp" , "windows" ) # windows-cp-1254 -> windows-1254 # name adjustment for compatibility if encoding . startswith ( "8859" ) : encoding = "iso-%s" % encoding elif encoding . startswith ( "cp-" ) : encoding = "cp%s" % encoding [ 3 : ] elif encoding . startswith ( "euc-" ) : encoding = "euc_%s" % encoding [ 4 : ] elif encoding . startswith ( "windows" ) and not encoding . startswith ( "windows-" ) : encoding = "windows-%s" % encoding [ 7 : ] elif encoding . find ( "iso-88" ) > 0 : encoding = encoding [ encoding . find ( "iso-88" ) : ] elif encoding . startswith ( "is0-" ) : encoding = "iso%s" % encoding [ 4 : ] elif encoding . find ( "ascii" ) > 0 : encoding = "ascii" elif encoding . find ( "utf8" ) > 0 : encoding = "utf8" # Reference: http://philip.html5.org/data/charsets-2.html if encoding in translate : encoding = translate [ encoding ] elif encoding in ( "null" , "{charset}" , "*" ) or not re . search ( r"\w" , encoding ) : return None # Reference: http://www.iana.org/assignments/character-sets # Reference: http://docs.python.org/library/codecs.html try : codecs . lookup ( encoding . encode ( UNICODE_ENCODING ) if isinstance ( encoding , unicode ) else encoding ) except LookupError : if warn : warnMsg = "unknown web page charset '%s'. " % encoding warnMsg += "Please report by e-mail to 'dev@sqlmap.org'" singleTimeLogMessage ( warnMsg , logging . WARN , encoding ) encoding = None return encoding