[patch] small user_encoding fix

John A Meinel john at arbash-meinel.com
Mon Feb 20 17:02:03 GMT 2006


Marien Zwart wrote:
> 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.)
> 
> 

+1 from me, since I just found that doing "LANG=US-ASCII bzr st" will
fail with:
locale.Error: unsupported locale setting

I actually don't think spawning a sub-process would be all that bad. It
used to be the way that "run_bzr" worked. We stopped doing that because
it is really expensive to spawn bzr that many times, but just doing it a
couple of times would be good for testing.

John
=:->

> 
> ------------------------------------------------------------------------
> 
> === 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: signature.asc
Type: application/pgp-signature
Size: 249 bytes
Desc: OpenPGP digital signature
Url : https://lists.ubuntu.com/archives/bazaar/attachments/20060220/24ff8a0e/attachment.pgp 


More information about the bazaar mailing list