예제 #1
0
def detect(bytestring):
    try:
        from cchardet import detect as implementation
    except ImportError:
        from chardet import detect as implementation
        return implementation(bytestring)
    else:
        ans = implementation(bytestring)
        enc = ans.get('encoding')
        if enc:
            ans['encoding'] = enc.lower()
        return ans
예제 #2
0
def detect(bytestring):
    from cchardet import detect as implementation
    ans = implementation(bytestring)
    enc = ans.get('encoding')
    if enc:
        ans['encoding'] = enc.lower()
    elif enc is None:
        ans['encoding'] = ''
    if ans.get('confidence') is None:
        ans['confidence'] = 0
    return ans