Ticket #15778: createsuperuser.diff

File createsuperuser.diff, 1.5 KB (added by hynekcer, 4 years ago)
  • django/contrib/auth/management/commands/createsuperuser.py

    diff -r 614d8a1761f0 django/contrib/auth/management/commands/createsuperuser.py
    a b  
    33"""
    44
    55import getpass
     6import locale
    67import re
    78import sys
     9import unicodedata
    810from optparse import make_option
    911from django.contrib.auth.models import User
    1012from django.core import exceptions
     
    5860
    5961        # Try to determine the current system user's username to use as a default.
    6062        try:
    61             default_username = getpass.getuser().replace(' ', '').lower()
    62         except (ImportError, KeyError):
     63            default_username = getpass.getuser().decode(locale.getdefaultlocale()[1])
     64            default_username = unicodedata.normalize('NFKD', default_username) \
     65                                    .encode('ascii', 'ignore').replace(' ', '').lower()
     66            if not RE_VALID_USERNAME.match(default_username):
     67                default_username = ''
     68        except (ImportError, KeyError, UnicodeDecodeError):
    6369            # KeyError will be raised by os.getpwuid() (called by getuser())
    6470            # if there is no corresponding entry in the /etc/passwd file
    6571            # (a very restricted chroot environment, for example).
     72            # UnicodeDecodeError - preventive treatment for non-latin Windows.
    6673            default_username = ''
    6774
    6875        # Determine whether the default username is taken, so we don't display
Back to Top