Ticket #18160: auth_invalid_encoding.diff

File auth_invalid_encoding.diff, 2.1 KB (added by mawe, 12 years ago)

Updated patch which fixes unknown as well as invalid (None) encodings

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

    diff --git a/django/contrib/auth/management/__init__.py b/django/contrib/auth/management/__init__.py
    index 66f54f1..b6e7989 100644
    a b  
    22Creates permissions for all installed apps that need permissions.
    33"""
    44import getpass
    5 import locale
    65import unicodedata
    76from django.contrib.auth import models as auth_app
    87from django.db.models import get_models, signals
    98from django.contrib.auth.models import User
     9from django.utils.encoding import DEFAULT_LOCALE_ENCODING
    1010
    1111
    1212def _get_permission_codename(action, opts):
    def get_system_username():  
    8282        username could not be determined.
    8383    """
    8484    try:
    85         return getpass.getuser().decode(locale.getdefaultlocale()[1])
     85        return getpass.getuser().decode(DEFAULT_LOCALE_ENCODING)
    8686    except (ImportError, KeyError, UnicodeDecodeError):
    8787        # KeyError will be raised by os.getpwuid() (called by getuser())
    8888        # if there is no corresponding entry in the /etc/passwd file
  • django/contrib/auth/tests/management.py

    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):  
    3030        management.get_system_username = lambda: u'J\xfalia'
    3131        self.assertEqual(management.get_default_username(), 'julia')
    3232
     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
    3347
    3448class ChangepasswordManagementCommandTestCase(TestCase):
    3549
Back to Top