[gest_crans] encodage correct des messages d'erreurs pour diminuer le nombre de crashes

darcs-hash:20110902081727-ffbb2-088627e2bfec99425459dc38ec882fe287ed78b4.gz
This commit is contained in:
Nicolas Dandrimont 2011-09-02 10:17:27 +02:00
parent 350eddd113
commit ef1ebd1ac2
2 changed files with 26 additions and 23 deletions

View file

@ -106,16 +106,19 @@ OK = coul('OK', 'vert')
WARNING = coul('WARNING', 'jaune')
ERREUR = coul('ERREUR', 'rouge')
def to_encoding(txt, enc=encoding):
if type(txt) == unicode:
return txt.encode(enc, 'ignore')
def to_unicode(txt, enc=encoding):
if isinstance(txt, unicode):
return txt
else:
# On suppose d'abord que le texte est en UTF-8
try:
return txt.decode("UTF-8").encode(enc, 'ignore')
return txt.decode("UTF-8")
except:
# Sinon c'est surement de l'iso
return txt.decode("ISO8859-15").encode(enc, 'ignore')
return txt.decode("ISO8859-15")
def to_encoding(txt, enc=encoding):
return to_unicode(txt).encode(enc, 'ignore')
def cprint(txt, col='blanc', newline=True):
t = coul(to_encoding(txt), col)