Skip to content

Commit

Permalink
Fix unicode default input on py3
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewgodwin committed Jan 19, 2014
1 parent e802c97 commit 1ea96ac
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions django/db/migrations/questioner.py
Expand Up @@ -3,7 +3,7 @@
import sys

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 .loader import MIGRATIONS_MODULE_NAME
Expand Down Expand Up @@ -97,7 +97,13 @@ def ask_not_null_addition(self, field_name, model_name):
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()")
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:
print("Please enter some code, or 'exit' (with no quotes) to exit.")
elif code == "exit":
Expand Down

0 comments on commit 1ea96ac

Please sign in to comment.