[affich-tools] On evite de mourir pour une erreur d'encodage
darcs-hash:20090114114827-ffbb2-f440d23772724939fe41750b5547717c8b74c39e.gz
This commit is contained in:
parent
6d8c542a6b
commit
09662b7e57
1 changed files with 3 additions and 3 deletions
|
@ -105,14 +105,14 @@ ERREUR = coul('ERREUR', 'rouge')
|
||||||
|
|
||||||
def to_encoding(txt, enc=encoding):
|
def to_encoding(txt, enc=encoding):
|
||||||
if type(txt) == unicode:
|
if type(txt) == unicode:
|
||||||
return txt.encode(enc)
|
return txt.encode(enc, 'ignore')
|
||||||
else:
|
else:
|
||||||
# On suppose d'abord que le texte est en UTF-8
|
# On suppose d'abord que le texte est en UTF-8
|
||||||
try:
|
try:
|
||||||
return txt.decode("UTF-8").encode(enc)
|
return txt.decode("UTF-8").encode(enc, 'ignore')
|
||||||
except:
|
except:
|
||||||
# Sinon c'est surement de l'iso
|
# Sinon c'est surement de l'iso
|
||||||
return txt.decode("ISO8859-15").encode(enc)
|
return txt.decode("ISO8859-15").encode(enc, 'ignore')
|
||||||
|
|
||||||
def cprint(txt, col='blanc', newline=True):
|
def cprint(txt, col='blanc', newline=True):
|
||||||
t = coul(to_encoding(txt), col)
|
t = coul(to_encoding(txt), col)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue