Fixed #12849 -- Corrected the way strings are encoded for display by the colorizer so that they work with unicode. Thanks to jype for the report, and frasern for his work on the issue.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@12803 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
7471dab660
commit
be8a1f612d
|
@ -11,6 +11,7 @@ from optparse import make_option, OptionParser
|
|||
import django
|
||||
from django.core.exceptions import ImproperlyConfigured
|
||||
from django.core.management.color import color_style
|
||||
from django.utils.encoding import smart_str
|
||||
|
||||
try:
|
||||
set
|
||||
|
@ -28,7 +29,7 @@ class CommandError(Exception):
|
|||
result, raising this exception (with a sensible description of the
|
||||
error) is the preferred way to indicate that something has gone
|
||||
wrong in the execution of a command.
|
||||
|
||||
|
||||
"""
|
||||
pass
|
||||
|
||||
|
@ -37,7 +38,7 @@ def handle_default_options(options):
|
|||
Include any default options that all commands should accept here
|
||||
so that ManagementUtility can handle them before searching for
|
||||
user commands.
|
||||
|
||||
|
||||
"""
|
||||
if options.settings:
|
||||
os.environ['DJANGO_SETTINGS_MODULE'] = options.settings
|
||||
|
@ -83,7 +84,7 @@ class BaseCommand(object):
|
|||
specialized methods as needed.
|
||||
|
||||
Several attributes affect behavior at various steps along the way:
|
||||
|
||||
|
||||
``args``
|
||||
A string listing the arguments accepted by the command,
|
||||
suitable for use in help messages; e.g., a command which takes
|
||||
|
@ -117,7 +118,7 @@ class BaseCommand(object):
|
|||
rather than all applications' models, call
|
||||
``self.validate(app)`` from ``handle()``, where ``app`` is the
|
||||
application's Python module.
|
||||
|
||||
|
||||
"""
|
||||
# Metadata about this command.
|
||||
option_list = (
|
||||
|
@ -147,7 +148,7 @@ class BaseCommand(object):
|
|||
Return the Django version, which should be correct for all
|
||||
built-in Django commands. User-supplied commands should
|
||||
override this method.
|
||||
|
||||
|
||||
"""
|
||||
return django.get_version()
|
||||
|
||||
|
@ -155,7 +156,7 @@ class BaseCommand(object):
|
|||
"""
|
||||
Return a brief description of how to use this command, by
|
||||
default from the attribute ``self.help``.
|
||||
|
||||
|
||||
"""
|
||||
usage = '%%prog %s [options] %s' % (subcommand, self.args)
|
||||
if self.help:
|
||||
|
@ -167,7 +168,7 @@ class BaseCommand(object):
|
|||
"""
|
||||
Create and return the ``OptionParser`` which will be used to
|
||||
parse the arguments to this command.
|
||||
|
||||
|
||||
"""
|
||||
return OptionParser(prog=prog_name,
|
||||
usage=self.usage(subcommand),
|
||||
|
@ -178,7 +179,7 @@ class BaseCommand(object):
|
|||
"""
|
||||
Print the help message for this command, derived from
|
||||
``self.usage()``.
|
||||
|
||||
|
||||
"""
|
||||
parser = self.create_parser(prog_name, subcommand)
|
||||
parser.print_help()
|
||||
|
@ -187,7 +188,7 @@ class BaseCommand(object):
|
|||
"""
|
||||
Set up any environment changes requested (e.g., Python path
|
||||
and Django settings), then run this command.
|
||||
|
||||
|
||||
"""
|
||||
parser = self.create_parser(argv[0], argv[1])
|
||||
options, args = parser.parse_args(argv[2:])
|
||||
|
@ -201,7 +202,7 @@ class BaseCommand(object):
|
|||
``self.requires_model_validation``). If the command raises a
|
||||
``CommandError``, intercept it and print it sensibly to
|
||||
stderr.
|
||||
|
||||
|
||||
"""
|
||||
# Switch to English, because django-admin.py creates database content
|
||||
# like permissions, and those shouldn't contain any translations.
|
||||
|
@ -214,7 +215,7 @@ class BaseCommand(object):
|
|||
except ImportError, e:
|
||||
# If settings should be available, but aren't,
|
||||
# raise the error and quit.
|
||||
sys.stderr.write(self.style.ERROR(str('Error: %s\n' % e)))
|
||||
sys.stderr.write(smart_str(self.style.ERROR('Error: %s\n' % e)))
|
||||
sys.exit(1)
|
||||
try:
|
||||
if self.requires_model_validation:
|
||||
|
@ -230,15 +231,15 @@ class BaseCommand(object):
|
|||
if self.output_transaction:
|
||||
print self.style.SQL_KEYWORD("COMMIT;")
|
||||
except CommandError, e:
|
||||
sys.stderr.write(self.style.ERROR(str('Error: %s\n' % e)))
|
||||
sys.stderr.write(smart_str(self.style.ERROR('Error: %s\n' % e)))
|
||||
sys.exit(1)
|
||||
|
||||
def validate(self, app=None, display_num_errors=False):
|
||||
"""
|
||||
Validates the given app, raising CommandError for any errors.
|
||||
|
||||
|
||||
If app is None, then this will validate all installed apps.
|
||||
|
||||
|
||||
"""
|
||||
from django.core.management.validation import get_validation_errors
|
||||
try:
|
||||
|
@ -258,7 +259,7 @@ class BaseCommand(object):
|
|||
"""
|
||||
The actual logic of the command. Subclasses must implement
|
||||
this method.
|
||||
|
||||
|
||||
"""
|
||||
raise NotImplementedError()
|
||||
|
||||
|
@ -269,7 +270,7 @@ class AppCommand(BaseCommand):
|
|||
|
||||
Rather than implementing ``handle()``, subclasses must implement
|
||||
``handle_app()``, which will be called once for each application.
|
||||
|
||||
|
||||
"""
|
||||
args = '<appname appname ...>'
|
||||
|
||||
|
@ -293,7 +294,7 @@ class AppCommand(BaseCommand):
|
|||
Perform the command's actions for ``app``, which will be the
|
||||
Python module corresponding to an application name given on
|
||||
the command line.
|
||||
|
||||
|
||||
"""
|
||||
raise NotImplementedError()
|
||||
|
||||
|
@ -308,7 +309,7 @@ class LabelCommand(BaseCommand):
|
|||
|
||||
If the arguments should be names of installed applications, use
|
||||
``AppCommand`` instead.
|
||||
|
||||
|
||||
"""
|
||||
args = '<label label ...>'
|
||||
label = 'label'
|
||||
|
@ -328,7 +329,7 @@ class LabelCommand(BaseCommand):
|
|||
"""
|
||||
Perform the command's actions for ``label``, which will be the
|
||||
string as given on the command line.
|
||||
|
||||
|
||||
"""
|
||||
raise NotImplementedError()
|
||||
|
||||
|
@ -341,7 +342,7 @@ class NoArgsCommand(BaseCommand):
|
|||
no arguments are passed to the command.
|
||||
|
||||
Attempting to pass arguments will raise ``CommandError``.
|
||||
|
||||
|
||||
"""
|
||||
args = ''
|
||||
|
||||
|
@ -353,7 +354,7 @@ class NoArgsCommand(BaseCommand):
|
|||
def handle_noargs(self, **options):
|
||||
"""
|
||||
Perform this command's actions.
|
||||
|
||||
|
||||
"""
|
||||
raise NotImplementedError()
|
||||
|
||||
|
@ -419,7 +420,7 @@ def _make_writeable(filename):
|
|||
"""
|
||||
Make sure that the file is writeable. Useful if our source is
|
||||
read-only.
|
||||
|
||||
|
||||
"""
|
||||
import stat
|
||||
if sys.platform.startswith('java'):
|
||||
|
|
|
@ -38,7 +38,6 @@ def colorize(text='', opts=(), **kwargs):
|
|||
print colorize('and so should this')
|
||||
print 'this should not be red'
|
||||
"""
|
||||
text = str(text)
|
||||
code_list = []
|
||||
if text == '' and len(opts) == 1 and opts[0] == 'reset':
|
||||
return '\x1b[%sm' % RESET
|
||||
|
|
Loading…
Reference in New Issue