[py3] Replaced raw_input by input

The six addition has been borrowed from:
https://bitbucket.org/gutworth/six/changeset/733ef740
This commit is contained in:
Claude Paroz 2012-08-08 19:08:05 +02:00
parent b1517a310a
commit b8e49d70f2
9 changed files with 20 additions and 11 deletions

View File

@ -9,6 +9,7 @@ import unicodedata
from django.contrib.auth import models as auth_app from django.contrib.auth import models as auth_app
from django.db.models import get_models, signals from django.db.models import get_models, signals
from django.contrib.auth.models import User from django.contrib.auth.models import User
from django.utils.six.moves import input
def _get_permission_codename(action, opts): def _get_permission_codename(action, opts):
@ -66,10 +67,10 @@ def create_superuser(app, created_models, verbosity, db, **kwargs):
msg = ("\nYou just installed Django's auth system, which means you " msg = ("\nYou just installed Django's auth system, which means you "
"don't have any superusers defined.\nWould you like to create one " "don't have any superusers defined.\nWould you like to create one "
"now? (yes/no): ") "now? (yes/no): ")
confirm = raw_input(msg) confirm = input(msg)
while 1: while 1:
if confirm not in ('yes', 'no'): if confirm not in ('yes', 'no'):
confirm = raw_input('Please enter either "yes" or "no": ') confirm = input('Please enter either "yes" or "no": ')
continue continue
if confirm == 'yes': if confirm == 'yes':
call_command("createsuperuser", interactive=True, database=db) call_command("createsuperuser", interactive=True, database=db)

View File

@ -12,6 +12,7 @@ from django.contrib.auth.management import get_default_username
from django.core import exceptions from django.core import exceptions
from django.core.management.base import BaseCommand, CommandError from django.core.management.base import BaseCommand, CommandError
from django.db import DEFAULT_DB_ALIAS from django.db import DEFAULT_DB_ALIAS
from django.utils.six.moves import input
from django.utils.translation import ugettext as _ from django.utils.translation import ugettext as _
RE_VALID_USERNAME = re.compile('[\w.@+-]+$') RE_VALID_USERNAME = re.compile('[\w.@+-]+$')
@ -76,7 +77,7 @@ class Command(BaseCommand):
input_msg = 'Username' input_msg = 'Username'
if default_username: if default_username:
input_msg += ' (leave blank to use %r)' % default_username input_msg += ' (leave blank to use %r)' % default_username
username = raw_input(input_msg + ': ') username = input(input_msg + ': ')
if default_username and username == '': if default_username and username == '':
username = default_username username = default_username
if not RE_VALID_USERNAME.match(username): if not RE_VALID_USERNAME.match(username):
@ -94,7 +95,7 @@ class Command(BaseCommand):
# Get an email # Get an email
while 1: while 1:
if not email: if not email:
email = raw_input('E-mail address: ') email = input('E-mail address: ')
try: try:
is_valid_email(email) is_valid_email(email)
except exceptions.ValidationError: except exceptions.ValidationError:

View File

@ -2,6 +2,7 @@ from django.contrib.contenttypes.models import ContentType
from django.db.models import get_apps, get_models, signals from django.db.models import get_apps, get_models, signals
from django.utils.encoding import smart_text from django.utils.encoding import smart_text
from django.utils import six from django.utils import six
from django.utils.six.moves import input
def update_contenttypes(app, created_models, verbosity=2, **kwargs): def update_contenttypes(app, created_models, verbosity=2, **kwargs):
""" """
@ -49,7 +50,7 @@ def update_contenttypes(app, created_models, verbosity=2, **kwargs):
' %s | %s' % (ct.app_label, ct.model) ' %s | %s' % (ct.app_label, ct.model)
for ct in to_remove for ct in to_remove
]) ])
ok_to_delete = raw_input("""The following content types are stale and need to be deleted: ok_to_delete = input("""The following content types are stale and need to be deleted:
%s %s

View File

@ -8,6 +8,7 @@ from django.core.files.storage import FileSystemStorage
from django.core.management.base import CommandError, NoArgsCommand from django.core.management.base import CommandError, NoArgsCommand
from django.utils.encoding import smart_text from django.utils.encoding import smart_text
from django.utils.datastructures import SortedDict from django.utils.datastructures import SortedDict
from django.utils.six.moves import input
from django.contrib.staticfiles import finders, storage from django.contrib.staticfiles import finders, storage
@ -148,7 +149,7 @@ class Command(NoArgsCommand):
clear_display = 'This will overwrite existing files!' clear_display = 'This will overwrite existing files!'
if self.interactive: if self.interactive:
confirm = raw_input(""" confirm = input("""
You have requested to collect static files at the destination You have requested to collect static files at the destination
location as specified in your settings%s location as specified in your settings%s

View File

@ -7,6 +7,7 @@ from django.core.management.base import NoArgsCommand, CommandError
from django.core.management.color import no_style from django.core.management.color import no_style
from django.core.management.sql import sql_flush, emit_post_sync_signal from django.core.management.sql import sql_flush, emit_post_sync_signal
from django.utils.importlib import import_module from django.utils.importlib import import_module
from django.utils.six.moves import input
class Command(NoArgsCommand): class Command(NoArgsCommand):
@ -45,7 +46,7 @@ class Command(NoArgsCommand):
sql_list = sql_flush(self.style, connection, only_django=True, reset_sequences=reset_sequences) sql_list = sql_flush(self.style, connection, only_django=True, reset_sequences=reset_sequences)
if interactive: if interactive:
confirm = raw_input("""You have requested a flush of the database. confirm = input("""You have requested a flush of the database.
This will IRREVERSIBLY DESTROY all data currently in the %r database, This will IRREVERSIBLY DESTROY all data currently in the %r database,
and return each table to the state it was in after syncdb. and return each table to the state it was in after syncdb.
Are you sure you want to do this? Are you sure you want to do this?

View File

@ -3,6 +3,7 @@ import time
from django.conf import settings from django.conf import settings
from django.db.utils import load_backend from django.db.utils import load_backend
from django.utils.six.moves import input
# The prefix to put on the default database name when creating # The prefix to put on the default database name when creating
# the test database. # the test database.
@ -330,7 +331,7 @@ class BaseDatabaseCreation(object):
sys.stderr.write( sys.stderr.write(
"Got an error creating the test database: %s\n" % e) "Got an error creating the test database: %s\n" % e)
if not autoclobber: if not autoclobber:
confirm = raw_input( confirm = input(
"Type 'yes' if you would like to try deleting the test " "Type 'yes' if you would like to try deleting the test "
"database '%s', or 'no' to cancel: " % test_database_name) "database '%s', or 'no' to cancel: " % test_database_name)
if autoclobber or confirm == 'yes': if autoclobber or confirm == 'yes':

View File

@ -1,6 +1,7 @@
import sys import sys
import time import time
from django.db.backends.creation import BaseDatabaseCreation from django.db.backends.creation import BaseDatabaseCreation
from django.utils.six.moves import input
TEST_DATABASE_PREFIX = 'test_' TEST_DATABASE_PREFIX = 'test_'
PASSWORD = 'Im_a_lumberjack' PASSWORD = 'Im_a_lumberjack'
@ -65,7 +66,7 @@ class DatabaseCreation(BaseDatabaseCreation):
except Exception as e: except Exception as e:
sys.stderr.write("Got an error creating the test database: %s\n" % e) sys.stderr.write("Got an error creating the test database: %s\n" % e)
if not autoclobber: if not autoclobber:
confirm = raw_input("It appears the test database, %s, already exists. Type 'yes' to delete it, or 'no' to cancel: " % TEST_NAME) confirm = input("It appears the test database, %s, already exists. Type 'yes' to delete it, or 'no' to cancel: " % TEST_NAME)
if autoclobber or confirm == 'yes': if autoclobber or confirm == 'yes':
try: try:
if verbosity >= 1: if verbosity >= 1:
@ -87,7 +88,7 @@ class DatabaseCreation(BaseDatabaseCreation):
except Exception as e: except Exception as e:
sys.stderr.write("Got an error creating the test user: %s\n" % e) sys.stderr.write("Got an error creating the test user: %s\n" % e)
if not autoclobber: if not autoclobber:
confirm = raw_input("It appears the test user, %s, already exists. Type 'yes' to delete it, or 'no' to cancel: " % TEST_USER) confirm = input("It appears the test user, %s, already exists. Type 'yes' to delete it, or 'no' to cancel: " % TEST_USER)
if autoclobber or confirm == 'yes': if autoclobber or confirm == 'yes':
try: try:
if verbosity >= 1: if verbosity >= 1:

View File

@ -1,6 +1,7 @@
import os import os
import sys import sys
from django.db.backends.creation import BaseDatabaseCreation from django.db.backends.creation import BaseDatabaseCreation
from django.utils.six.moves import input
class DatabaseCreation(BaseDatabaseCreation): class DatabaseCreation(BaseDatabaseCreation):
# SQLite doesn't actually support most of these types, but it "does the right # SQLite doesn't actually support most of these types, but it "does the right
@ -53,7 +54,7 @@ class DatabaseCreation(BaseDatabaseCreation):
print("Destroying old test database '%s'..." % self.connection.alias) print("Destroying old test database '%s'..." % self.connection.alias)
if os.access(test_database_name, os.F_OK): if os.access(test_database_name, os.F_OK):
if not autoclobber: if not autoclobber:
confirm = raw_input("Type 'yes' if you would like to try deleting the test database '%s', or 'no' to cancel: " % test_database_name) confirm = input("Type 'yes' if you would like to try deleting the test database '%s', or 'no' to cancel: " % test_database_name)
if autoclobber or confirm == 'yes': if autoclobber or confirm == 'yes':
try: try:
os.remove(test_database_name) os.remove(test_database_name)

View File

@ -113,6 +113,7 @@ class _MovedItems(types.ModuleType):
_moved_attributes = [ _moved_attributes = [
MovedAttribute("cStringIO", "cStringIO", "io", "StringIO"), MovedAttribute("cStringIO", "cStringIO", "io", "StringIO"),
MovedAttribute("filter", "itertools", "builtins", "ifilter", "filter"), MovedAttribute("filter", "itertools", "builtins", "ifilter", "filter"),
MovedAttribute("input", "__builtin__", "builtins", "raw_input", "input"),
MovedAttribute("map", "itertools", "builtins", "imap", "map"), MovedAttribute("map", "itertools", "builtins", "imap", "map"),
MovedAttribute("reload_module", "__builtin__", "imp", "reload"), MovedAttribute("reload_module", "__builtin__", "imp", "reload"),
MovedAttribute("reduce", "__builtin__", "functools"), MovedAttribute("reduce", "__builtin__", "functools"),