On Wed, Nov 09, 2011 at 04:21:55PM +0000, Tom Evans wrote:
> On Wed, Nov 9, 2011 at 4:03 PM, Niels <[email protected]> wrote:
> > Worse:
> >>>> locale.getdefaultlocale()
> > (None, None)
> >
> > Still i'd say this should be handled better than bailing out with an error.
> > Something like .. .decode(locale.getdefaultlocale()[1] or 'ascii', 'ignore')
> >
> 
> You simply need to set an appropriate LANG in your environment:
> 
> > $ env LANG=nl_NL.UTF-8 /usr/local/bin/python
> Python 2.7.1 (r271:86832, Dec 13 2010, 15:52:15)
> [GCC 4.2.1 20070719  [FreeBSD]] on freebsd8
> Type "help", "copyright", "credits" or "license" for more information.
> >>> import locale
> >>> locale.getdefaultlocale()
> ('nl_NL', 'UTF-8')

Absolutely right, still, why not guard django against > locale
LANG=
LC_CTYPE="C"
LC_COLLATE="C"
LC_TIME="C"
LC_NUMERIC="C"
LC_MONETARY="C"
LC_MESSAGES="C"
LC_ALL=

which is perfectly okay for a plain ascii router/server box.

Index: django/contrib/auth/management/__init__.py
===================================================================
--- django/contrib/auth/management/__init__.py  (revision 17077)
+++ django/contrib/auth/management/__init__.py  (working copy)
@@ -82,7 +82,9 @@
         username could not be determined.
     """
     try:
-        return getpass.getuser().decode(locale.getdefaultlocale()[1])
+        return getpass.getuser().decode(
+            locale.getdefaultlocale()[1] or 'ascii',
+            'ignore' )
     except (ImportError, KeyError, UnicodeDecodeError):
         # KeyError will be raised by os.getpwuid() (called by getuser())
         # if there is no corresponding entry in the /etc/passwd file

works for me.

Cheers :-)

--

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to