summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeroen van Meeuwen (Kolab Systems) <vanmeeuwen@kolabsys.com>2015-12-28 15:52:39 +0100
committerJeroen van Meeuwen (Kolab Systems) <vanmeeuwen@kolabsys.com>2015-12-28 15:52:39 +0100
commitaf442599eb21b502372f18f049b2d65a95cc0027 (patch)
treea79d73b30cd20cf78478d3bdf49467ba7bbabfb5
parent5acc4665f1b11a1cc750ceae6e7903ddcf43a1b7 (diff)
downloadpykolab-af442599eb21b502372f18f049b2d65a95cc0027.tar.gz
Test transliteration dictionary lookup keys exist before using values
-rw-r--r--pykolab/translit.py27
1 files changed, 18 insertions, 9 deletions
diff --git a/pykolab/translit.py b/pykolab/translit.py
index 593c0ec..0ff042d 100644
--- a/pykolab/translit.py
+++ b/pykolab/translit.py
@@ -98,24 +98,33 @@ translit_map = {
}
def transliterate(_input, lang, _output_expected=None):
- _translit_name = locale_translit_map[lang]
+ if locale_translit_map.has_key(lang):
+ _translit_name = locale_translit_map[lang]
+ else:
+ _translit_name = lang
_output = ''
if not isinstance(_input, unicode):
for char in _input.decode('utf-8'):
- if translit_map[_translit_name].has_key(char):
- _output += translit_map[_translit_name][char]
- elif char in [repr(x) for x in translit_map[_translit_name].keys()]:
- _output += translit_map[_translit_name][[char in [raw(x) for x in translit_map[_translit_name].keys()]][0]]
+ if translit_map.has_key(_translit_name):
+ if translit_map[_translit_name].has_key(char):
+ _output += translit_map[_translit_name][char]
+ elif char in [repr(x) for x in translit_map[_translit_name].keys()]:
+ _output += translit_map[_translit_name][[char in [raw(x) for x in translit_map[_translit_name].keys()]][0]]
+ else:
+ _output += char
else:
_output += char
else:
for char in _input:
- if translit_map[_translit_name].has_key(char):
- _output += translit_map[_translit_name][char]
- elif char in [repr(x) for x in translit_map[_translit_name].keys()]:
- _output += translit_map[_translit_name][[char in [raw(x) for x in translit_map[_translit_name].keys()]][0]]
+ if translit_map.has_key(_translit_name):
+ if translit_map[_translit_name].has_key(char):
+ _output += translit_map[_translit_name][char]
+ elif char in [repr(x) for x in translit_map[_translit_name].keys()]:
+ _output += translit_map[_translit_name][[char in [raw(x) for x in translit_map[_translit_name].keys()]][0]]
+ else:
+ _output += char
else:
_output += char