[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:
parent
350eddd113
commit
ef1ebd1ac2
2 changed files with 26 additions and 23 deletions
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue