[darcs_send_changes] ISO-8859-15 safety
darcs-hash:20090420044640-ffbb2-bc068c43f58d48a124b8ac08aaa6c4cdd9a7c5ab.gz
This commit is contained in:
parent
17b40bd612
commit
276a0ad791
1 changed files with 12 additions and 9 deletions
|
@ -51,21 +51,24 @@ CONF_PATH = "_darcs/third-party/darcs-send-changes"
|
||||||
DATE_FILE = CONF_PATH + "/date-last-send"
|
DATE_FILE = CONF_PATH + "/date-last-send"
|
||||||
ID_FILE = CONF_PATH + "/id"
|
ID_FILE = CONF_PATH + "/id"
|
||||||
|
|
||||||
def to_utf8(str):
|
def to_utf8(input):
|
||||||
""" Decode un str ou un unicode vers un str en UTF-8. """
|
""" Decode un str ou un unicode vers un str en UTF-8. """
|
||||||
if isinstance(str, unicode):
|
if not isinstance(input, basestring):
|
||||||
return str.encode("UTF-8")
|
return input
|
||||||
|
|
||||||
|
if isinstance(input, unicode):
|
||||||
|
return input.encode("UTF-8")
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
# Si c'est une chaine brute, on commend par essayer
|
# Si c'est une chaine brute, on commend par essayer
|
||||||
# de la décoder comme une chaine en UTF-8
|
# de la décoder comme une chaine en UTF-8
|
||||||
str.decode("UTF-8")
|
input.decode("UTF-8")
|
||||||
return str
|
return input
|
||||||
except:
|
except UnicodeDecodeError:
|
||||||
try:
|
try:
|
||||||
return str.decode(encoding).encode("UTF-8")
|
return input.decode("ISO-8859-15").encode("UTF-8")
|
||||||
except:
|
except (UnicodeDecodeError, UnicodeEncodeError):
|
||||||
return str
|
return input.decode("ascii", "replace").encode("UTF-8")
|
||||||
|
|
||||||
def darcs(args):
|
def darcs(args):
|
||||||
""" Invoque darcs et renvoie sa sortie. """
|
""" Invoque darcs et renvoie sa sortie. """
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue