Fix unicode default input on py3

This commit is contained in:
Andrew Godwin 2014-01-19 17:14:31 +00:00
parent e802c97581
commit 1ea96acaf5
1 changed files with 8 additions and 2 deletions

View File

@ -3,7 +3,7 @@ import os
import sys import sys
from django.apps import apps from django.apps import apps
from django.utils import datetime_safe from django.utils import datetime_safe, six
from django.utils.six.moves import input from django.utils.six.moves import input
from .loader import MIGRATIONS_MODULE_NAME from .loader import MIGRATIONS_MODULE_NAME
@ -97,7 +97,13 @@ class InteractiveMigrationQuestioner(MigrationQuestioner):
print("Please enter the default value now, as valid Python") print("Please enter the default value now, as valid Python")
print("The datetime module is available, so you can do e.g. datetime.date.today()") print("The datetime module is available, so you can do e.g. datetime.date.today()")
while True: while True:
code = input(">>> ").decode(sys.stdin.encoding) if six.PY3:
# Six does not correctly abstract over the fact that
# py3 input returns a unicode string, while py2 raw_input
# returns a bytestring.
code = input(">>> ")
else:
code = input(">>> ").decode(sys.stdin.encoding)
if not code: if not code:
print("Please enter some code, or 'exit' (with no quotes) to exit.") print("Please enter some code, or 'exit' (with no quotes) to exit.")
elif code == "exit": elif code == "exit":