diff --git a/django/contrib/auth/management/__init__.py b/django/contrib/auth/management/__init__.py
index 66f54f1..b6e7989 100644
a
|
b
|
|
2 | 2 | Creates permissions for all installed apps that need permissions. |
3 | 3 | """ |
4 | 4 | import getpass |
5 | | import locale |
6 | 5 | import unicodedata |
7 | 6 | from django.contrib.auth import models as auth_app |
8 | 7 | from django.db.models import get_models, signals |
9 | 8 | from django.contrib.auth.models import User |
| 9 | from django.utils.encoding import DEFAULT_LOCALE_ENCODING |
10 | 10 | |
11 | 11 | |
12 | 12 | def _get_permission_codename(action, opts): |
… |
… |
def get_system_username():
|
82 | 82 | username could not be determined. |
83 | 83 | """ |
84 | 84 | try: |
85 | | return getpass.getuser().decode(locale.getdefaultlocale()[1]) |
| 85 | return getpass.getuser().decode(DEFAULT_LOCALE_ENCODING) |
86 | 86 | except (ImportError, KeyError, UnicodeDecodeError): |
87 | 87 | # KeyError will be raised by os.getpwuid() (called by getuser()) |
88 | 88 | # if there is no corresponding entry in the /etc/passwd file |
diff --git a/django/contrib/auth/tests/management.py b/django/contrib/auth/tests/management.py
index 81ab0aa..8d2e6fb 100644
a
|
b
|
class GetDefaultUsernameTestCase(TestCase):
|
30 | 30 | management.get_system_username = lambda: u'J\xfalia' |
31 | 31 | self.assertEqual(management.get_default_username(), 'julia') |
32 | 32 | |
| 33 | def test_unknown_encoding(self): |
| 34 | import locale |
| 35 | _getdefaultlocale = locale.getdefaultlocale |
| 36 | locale.getdefaultlocale = lambda: ("en_US", "UNKNOWN ENCODING STRING") |
| 37 | management.get_default_username() |
| 38 | locale.getdefaultlocale = _getdefaultlocale |
| 39 | |
| 40 | def test_none_encoding(self): |
| 41 | import locale |
| 42 | _getdefaultlocale = locale.getdefaultlocale |
| 43 | locale.getdefaultlocale = lambda: None, None |
| 44 | management.get_default_username() |
| 45 | locale.getdefaultlocale = _getdefaultlocale |
| 46 | |
33 | 47 | |
34 | 48 | class ChangepasswordManagementCommandTestCase(TestCase): |
35 | 49 | |