diff -r 614d8a1761f0 django/contrib/auth/management/commands/createsuperuser.py
a
|
b
|
|
3 | 3 | """ |
4 | 4 | |
5 | 5 | import getpass |
| 6 | import locale |
6 | 7 | import re |
7 | 8 | import sys |
| 9 | import unicodedata |
8 | 10 | from optparse import make_option |
9 | 11 | from django.contrib.auth.models import User |
10 | 12 | from django.core import exceptions |
… |
… |
|
58 | 60 | |
59 | 61 | # Try to determine the current system user's username to use as a default. |
60 | 62 | 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): |
63 | 69 | # KeyError will be raised by os.getpwuid() (called by getuser()) |
64 | 70 | # if there is no corresponding entry in the /etc/passwd file |
65 | 71 | # (a very restricted chroot environment, for example). |
| 72 | # UnicodeDecodeError - preventive treatment for non-latin Windows. |
66 | 73 | default_username = '' |
67 | 74 | |
68 | 75 | # Determine whether the default username is taken, so we don't display |