move guess_encoding into weboob.tools.misc
This commit is contained in:
parent
bca7a35d4a
commit
a33d26558b
2 changed files with 14 additions and 12 deletions
|
|
@ -19,6 +19,7 @@
|
|||
|
||||
|
||||
from time import time, sleep
|
||||
import locale
|
||||
import os
|
||||
import sys
|
||||
import traceback
|
||||
|
|
@ -92,6 +93,17 @@ def to_unicode(text):
|
|||
return unicode(text, 'windows-1252', 'replace')
|
||||
|
||||
|
||||
def guess_encoding(stdio):
|
||||
try:
|
||||
encoding = stdio.encoding or locale.getpreferredencoding()
|
||||
except AttributeError:
|
||||
encoding = None
|
||||
# ASCII or ANSII is most likely a user mistake
|
||||
if not encoding or encoding.lower() == 'ascii' or encoding.lower().startswith('ansi'):
|
||||
encoding = 'UTF-8'
|
||||
return encoding
|
||||
|
||||
|
||||
def limit(iterator, lim):
|
||||
count = 0
|
||||
iterator = iter(iterator)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue