Update requests lib
This commit is contained in:
@@ -30,3 +30,37 @@ def detect(aBuf):
|
||||
u.feed(aBuf)
|
||||
u.close()
|
||||
return u.result
|
||||
|
||||
def _description_of(path):
|
||||
"""Return a string describing the probable encoding of a file."""
|
||||
from charade.universaldetector import UniversalDetector
|
||||
|
||||
u = UniversalDetector()
|
||||
for line in open(path, 'rb'):
|
||||
u.feed(line)
|
||||
u.close()
|
||||
result = u.result
|
||||
if result['encoding']:
|
||||
return '%s: %s with confidence %s' % (path,
|
||||
result['encoding'],
|
||||
result['confidence'])
|
||||
else:
|
||||
return '%s: no result' % path
|
||||
|
||||
|
||||
def charade_cli():
|
||||
"""
|
||||
Script which takes one or more file paths and reports on their detected
|
||||
encodings
|
||||
|
||||
Example::
|
||||
|
||||
% chardetect.py somefile someotherfile
|
||||
somefile: windows-1252 with confidence 0.5
|
||||
someotherfile: ascii with confidence 1.0
|
||||
|
||||
"""
|
||||
from sys import argv
|
||||
for path in argv[1:]:
|
||||
print(_description_of(path))
|
||||
|
||||
Reference in New Issue
Block a user