From 7b526cffafc75b02c4a00bd34ba5bbdf4b221335 Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Sun, 20 Jan 2013 08:26:54 -0500 Subject: [PATCH] Convert sys.argv to Unicode (using a configurable encoding) In Python 3, sys.argv is already Unicode, but there's no clean way to do this automatically in Python 2 [1]. If your system doesn't use UTF-8 for it's argv encoding, you should set system.argv-encoding in your ~/.mutt-ldap.rc. For example, if your system uses UTF-16, try: [system] argv-encoding = utf-16 [1]: http://bugs.python.org/issue2128 --- mutt-ldap.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/mutt-ldap.py b/mutt-ldap.py index 0348276..d0f674a 100755 --- a/mutt-ldap.py +++ b/mutt-ldap.py @@ -64,8 +64,13 @@ CONFIG.add_section('cache') CONFIG.set('cache', 'enable', 'yes') # enable caching by default CONFIG.set('cache', 'path', '~/.mutt-ldap.cache') # cache results here #CONFIG.set('cache', 'longevity_days', '14') # TODO: cache results for 14 days by default +CONFIG.add_section('system') +# HACK: Python 2.x support, see http://bugs.python.org/issue2128 +CONFIG.set('system', 'argv-encoding', 'utf-8') + CONFIG.read(os.path.expanduser('~/.mutt-ldap.rc')) + def connect(): protocol = 'ldap' if CONFIG.getboolean('connection', 'ssl'): @@ -167,6 +172,10 @@ def cache_persist(query, addresses): if __name__ == '__main__': import sys + # HACK: convert sys.argv to Unicode (not needed in Python 3) + argv_encoding = CONFIG.get('system', 'argv-encoding') + sys.argv = [unicode(arg, argv_encoding) for arg in sys.argv] + if len(sys.argv) < 2: sys.stderr.write('{0}: no search string given\n'.format(sys.argv[0])) sys.exit(1) -- 2.26.2