liuyang1520 / django-command-extensions

Automatically exported from code.google.com/p/django-command-extensions
MIT License
0 stars 0 forks source link

runscript does not handle non-ascii encoding #118

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. My script file contains some accented characters
2.
3.

What is the expected output? What do you see instead?

[expected]
Thomas-SMETSs-MacBook-Pro:sportotop tsmets$ ./manage.py  runscript 1_Club
2010-06-14 00:28:43,010 - settings - DEBUG - Test debug message
2010-06-14 00:28:43,010 - settings - DEBUG - Project name : sportotop
2010-06-14 00:28:43,010 - settings - DEBUG - Root directory : 
/Users/tsmets/Documents/python/SportOTop/sportotop
2010-06-14 00:28:43,011 - settings - DEBUG - DB-file : 
/Users/tsmets/Documents/python/SportOTop/sportotop/db/sportotop.dbf
2010-06-14 00:28:43,011 - settings - DEBUG - Template dirs : 
/Users/tsmets/Documents/python/SportOTop/sportotop/templates 
2010-06-14 00:28:43,011 - settings - DEBUG - Modules are : sportotop.Base / 
sportotop.Sport / sportotop.AthleteFile / sportotop.InfoAndNews / 
sportotop.Health 
2010-06-14 00:28:43,011 - settings - DEBUG - __name__ =settings
2010-06-14 00:28:43,011 - settings - DEBUG - __file__ 
=/Users/tsmets/Documents/python/SportOTop/sportotop/settings.pyc
2010-06-14 00:28:43,011 - settings - DEBUG - debug message
2010-06-14 00:28:43,011 - settings - INFO - info message
2010-06-14 00:28:43,011 - settings - WARNING - warn message
2010-06-14 00:28:43,011 - settings - ERROR - error message
2010-06-14 00:28:43,012 - settings - CRITICAL - critical message
[/expected]

Trace is :
[trace]
homas-SMETSs-MacBook-Pro:sportotop tsmets$ ./manage.py  runscript 1_Club
2010-06-14 00:28:26,579 - settings - DEBUG - Test debug message
2010-06-14 00:28:26,579 - settings - DEBUG - Project name : sportotop
2010-06-14 00:28:26,579 - settings - DEBUG - Root directory : 
/Users/tsmets/Documents/python/SportOTop/sportotop
2010-06-14 00:28:26,579 - settings - DEBUG - DB-file : 
/Users/tsmets/Documents/python/SportOTop/sportotop/db/sportotop.dbf
2010-06-14 00:28:26,579 - settings - DEBUG - Template dirs : 
/Users/tsmets/Documents/python/SportOTop/sportotop/templates 
2010-06-14 00:28:26,579 - settings - DEBUG - Modules are : sportotop.Base / 
sportotop.Sport / sportotop.AthleteFile / sportotop.InfoAndNews / 
sportotop.Health 
2010-06-14 00:28:26,579 - settings - DEBUG - __name__ =settings
2010-06-14 00:28:26,580 - settings - DEBUG - __file__ 
=/Users/tsmets/Documents/python/SportOTop/sportotop/settings.pyc
2010-06-14 00:28:26,580 - settings - DEBUG - debug message
2010-06-14 00:28:26,580 - settings - INFO - info message
2010-06-14 00:28:26,580 - settings - WARNING - warn message
2010-06-14 00:28:26,580 - settings - ERROR - error message
2010-06-14 00:28:26,580 - settings - CRITICAL - critical message
Traceback (most recent call last):
  File "./manage.py", line 11, in <module>
    execute_manager(settings)
  File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/django/core/management/__init__.py", line 438, in execute_manager
    utility.execute()
  File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/django/core/management/__init__.py", line 379, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/django/core/management/base.py", line 191, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/django/core/management/base.py", line 218, in execute
    output = self.handle(*args, **options)
  File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/django_extensions/management/commands/runscript.py", line 119, in handle
    modules = find_modules_for_script(script)
  File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/django_extensions/management/commands/runscript.py", line 106, in find_modules_for_script
    mod = my_import(nn)
  File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/django_extensions/management/commands/runscript.py", line 76, in my_import
    t = __import__(mod, [], [], [" "])
  File "/Users/tsmets/Documents/python/SportOTop/sportotop/scripts/1_Club.py", line 15
SyntaxError: Non-ASCII character '\xc3' in file 
/Users/tsmets/Documents/python/SportOTop/sportotop/scripts/1_Club.py on line 
15, but no encoding declared; see http://www.python.org/peps/pep-0263.html for 
details

[/trace]

What version of the product are you using? On what operating system?
Python 2.6.4 (r264:75821M, Oct 27 2009, 19:48:32) 
[GCC 4.0.1 (Apple Inc. build 5493)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> import django_extensions
>>> django_extensions.VERSION
(0, '4.1')

Please provide any additional information below.

Original issue reported on code.google.com by tsm...@gmail.com on 13 Jun 2010 at 10:45

Attachments:

GoogleCodeExporter commented 8 years ago
This is not a django-extensions bug.

Whenever you have non-ASCII characters in your Python 2.x source, you have to 
define the encoding in the .py file. Insert this on the first line of the file:

-*- encoding: utf-8 -*-

Original comment by akaih...@gmail.com on 25 Nov 2010 at 12:06