From a758d0aec2b3a36a03fb312bad35a0a54219309a Mon Sep 17 00:00:00 2001 From: hparfr Date: Mon, 19 Feb 2018 11:03:26 +0100 Subject: [PATCH] Geodis Don't send utf8 in EDI anymore Because, experience prove they don't know how to handle utf8 --- CHANGELOG.md | 2 ++ VERSION | 2 +- .../carriers/geodis/geodis_transport_edi.py | 32 +++++++++++++++++-- 3 files changed, 33 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8fd9379..7892ddc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,8 @@ Roadmap / TODO: - Support additionnal methods of api - Write tests +# 0.3.3 2018-02-19 + - Geodis force ASCII conversion for EDI. # 0.3.2 2018-02-06 - Geodis fix missing CTA segment diff --git a/VERSION b/VERSION index d15723f..1c09c74 100755 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.3.2 +0.3.3 diff --git a/roulier/carriers/geodis/geodis_transport_edi.py b/roulier/carriers/geodis/geodis_transport_edi.py index 76b51f6..2db8074 100644 --- a/roulier/carriers/geodis/geodis_transport_edi.py +++ b/roulier/carriers/geodis/geodis_transport_edi.py @@ -53,7 +53,7 @@ def parse_lines(lines): return "\n".join([parse_segment(segment) for segment in lines]) def sanitize(token): - # replace escapable chars by space + # remove accents and replace escapable chars by space # because, replacing "'" by "?'" # increase length of the token # which is limited by 35 @@ -63,7 +63,35 @@ def sanitize(token): .replace("'", " ") .replace("+", " ") .replace(":", " ") - ) + # quick and dirty replacement + # of common accentued chars in french + # because geodis don't handle well utf8 + # TODO: put it in api coerce + .replace(u"é", "e") + .replace(u"è", "e") + .replace(u"ë", "e") + .replace(u"ê", "e") + .replace(u"ô", "o") + .replace(u"ï", "i") + .replace(u"ö", "o") + .replace(u"à", "a") + .replace(u"â", "a") + .replace(u"ç", "c") + .replace(u"û", "u") + .replace(u"ù", "u") + .replace(u"É", "E") + .replace(u"È", "E") + .replace(u"Ë", "E") + .replace(u"Ê", "E") + .replace(u"Ô", "O") + .replace(u"Ï", "I") + .replace(u"Ö", "O") + .replace(u"À", "A") + .replace(u"Â", "A") + .replace(u"Ç", "C") + .replace(u"Û", "U") + .replace(u"Ù", "U") + ).encode('ascii', 'ignore') # cut remaining chars return sanitized return parse_lines(arr)