From be8a1f612dde1bff3dcdab05c3a916f27946dd31 Mon Sep 17 00:00:00 2001 From: Russell Keith-Magee Date: Thu, 18 Mar 2010 13:24:11 +0000 Subject: [PATCH] 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 --- django/core/management/base.py | 45 +++++++++++++++++----------------- django/utils/termcolors.py | 1 - 2 files changed, 23 insertions(+), 23 deletions(-) diff --git a/django/core/management/base.py b/django/core/management/base.py index 76b9c0967c..0e1c961105 100644 --- a/django/core/management/base.py +++ b/django/core/management/base.py @@ -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 = '' @@ -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 = '