summaryrefslogtreecommitdiff
path: root/pykolab/utils.py
diff options
context:
space:
mode:
authorJeroen van Meeuwen (Kolab Systems) <vanmeeuwen@kolabsys.com>2011-12-05 16:20:25 (GMT)
committerJeroen van Meeuwen (Kolab Systems) <vanmeeuwen@kolabsys.com>2011-12-05 16:20:25 (GMT)
commited14a87d9912f504cfe513b9db9765e4590aa52f (patch)
tree3d15cddc4a98cf57059d57bfdba56bd2aab08f09 /pykolab/utils.py
parenta6a58cb40175115da485afc5a605928d01403eac (diff)
downloadpykolab-ed14a87d9912f504cfe513b9db9765e4590aa52f.tar.gz
Use iconv to normalize/translate strings into their ascii representation
Diffstat (limited to 'pykolab/utils.py')
-rw-r--r--pykolab/utils.py25
1 files changed, 19 insertions, 6 deletions
diff --git a/pykolab/utils.py b/pykolab/utils.py
index 09a32fa..284ccd1 100644
--- a/pykolab/utils.py
+++ b/pykolab/utils.py
@@ -207,13 +207,26 @@ def pop_empty_from_list(_input_list):
def standard_root_dn(domain):
return 'dc=%s' %(',dc='.join(domain.split('.')))
-def translate(mystring):
- chars = ['Ä', 'Ü', 'Ö', 'ä', 'ü', 'ö', 'ß', 'ó']
- simple = ['Ae', 'Ue', 'Oe', 'ae', 'ue', 'oe', 'ss', 'o']
+def translate(mystring, locale_name='en_US'):
+ import locale
+ import subprocess
- for num in range(0, len(chars)):
- mystring = mystring.replace(chars[num], simple[num])
- return mystring
+ (locale_name,locale_charset) = locale.normalize(locale_name).split('.')
+
+ locale.setlocale(locale.LC_ALL, (locale_name,locale_charset))
+
+ command = [ '/usr/bin/iconv',
+ '-f', 'UTF-8',
+ '-t', 'ASCII//TRANSLIT',
+ '-s' ]
+
+ process = subprocess.Popen(command, stdout=subprocess.PIPE, stdin=subprocess.PIPE, stderr=subprocess.PIPE, env={'LANG': locale.normalize(locale_name)})
+
+ print >> process.stdin, mystring
+
+ result = process.communicate()[0].strip()
+
+ return result
def is_service(services):
"""