Ticket #16017: 16017.diff

File 16017.diff, 1.4 KB (added by Preston Timmons, 14 years ago)

Patch to call decode only if default locale is found.

  • django/contrib/auth/management/__init__.py

    diff --git a/django/contrib/auth/management/__init__.py b/django/contrib/auth/management/__init__.py
    index 9966849..1e1aaa0 100644
    a b def get_system_username():  
    8383    :returns: The username as a unicode string, or an empty string if the
    8484        username could not be determined.
    8585    """
    86     try:
    87         return getpass.getuser().decode(locale.getdefaultlocale()[1])
    88     except (ImportError, KeyError, UnicodeDecodeError):
    89         # KeyError will be raised by os.getpwuid() (called by getuser())
    90         # if there is no corresponding entry in the /etc/passwd file
    91         # (a very restricted chroot environment, for example).
    92         # UnicodeDecodeError - preventive treatment for non-latin Windows.
    93         return u''
     86    default_locale = locale.getdefaultlocale()[1]
     87    if default_locale:
     88        try:
     89            return getpass.getuser().decode(default_locale)
     90        except (ImportError, KeyError, UnicodeDecodeError):
     91            # KeyError will be raised by os.getpwuid() (called by getuser())
     92            # if there is no corresponding entry in the /etc/passwd file
     93            # (a very restricted chroot environment, for example).
     94            # UnicodeDecodeError - preventive treatment for non-latin Windows.
     95            pass
     96    return u''
    9497
    9598
    9699def get_default_username(check_db=True):
Back to Top