[patch] small user_encoding fix

Marien Zwart marienz at gentoo.org
Mon Feb 20 16:06:40 GMT 2006


Attached is a small patch to make "LC_CTYPE=foobar python -c 'import
bzrlib'" not explode with a locale.Error. If someone has some
straightforward suggestions on how to unittest this I'll do that too
(only way I can think of at the moment involves spawning a subprocess
with a different LC_CTYPE set that imports bzr, but that's rather ugly).

(and LC_CTYPE=foobar is not the only way to trigger it, an otherwise
valid but simply not installed locale works great too.)

-- 
Marien.
-------------- next part --------------
=== modified file 'bzrlib/__init__.py'
--- bzrlib/__init__.py	
+++ bzrlib/__init__.py	
@@ -85,7 +85,10 @@
     sys.platform = 'darwin'
 else:
     import locale
-user_encoding = locale.getpreferredencoding() or 'ascii'
+try:
+    user_encoding = locale.getpreferredencoding() or 'ascii'
+except locale.Error:
+    user_encoding = 'ascii'
 del locale
 
 __copyright__ = "Copyright 2005,06 Canonical Development Ltd."

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 191 bytes
Desc: not available
Url : https://lists.ubuntu.com/archives/bazaar/attachments/20060220/60673ec7/attachment.pgp 


More information about the bazaar mailing list