def getEncodingOfFile(sourcefile):
    """Get encoding of source file. If no encoding found, returns _DEFAULTENCODING."""
    myfile = file(sourcefile)
    line = myfile.readline()

    #try line 1
    encoding = parseEncoding(line)

    #encoding found?
    if encoding != "":
        return encoding

    #if not - try line two
    line = myfile.readline()
    encoding = parseEncoding(line)

    #encoding found?
    if encoding != "":
        return encoding

    #if not - try BOM
    if myfile.encoding != None:
        return myfile.encoding

    #if not - return default encoding
    return _DEFAULTENCODING
Get encoding of source file. If no encoding found, returns _DEFAULTENCODING.
recipes/Python/442482_Python_source_to_XHTML_colorizer/recipe-442482.py