Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge unicode-command-line fixes

closes gh-310
  • Loading branch information...
commit 14b912502c9a21f6529abafbb8feb8005a3364ba 2 parents c1f30b6 + f71f71c
@minrk minrk authored
View
9 IPython/config/loader.py
@@ -365,7 +365,14 @@ def _add_arguments(self):
def _parse_args(self, args):
"""self.parser->self.parsed_data"""
- self.parsed_data, self.extra_args = self.parser.parse_known_args(args)
+ # decode sys.argv to support unicode command-line options
+ uargs = []
+ for a in args:
+ if isinstance(a, str):
+ # don't decode if we already got unicode
+ a = a.decode(sys.stdin.encoding)
+ uargs.append(a)
+ self.parsed_data, self.extra_args = self.parser.parse_known_args(uargs)
def _convert_to_config(self):
"""self.parsed_data->self.config"""
View
14 IPython/core/interactiveshell.py
@@ -158,7 +158,7 @@ class InteractiveShell(Configurable, Magic):
exit_now = CBool(False)
# Monotonically increasing execution counter
execution_count = Int(1)
- filename = Str("<ipython console>")
+ filename = Unicode("<ipython console>")
ipython_dir= Unicode('', config=True) # Set to get_ipython_dir() in __init__
# Input splitter, to split entire cells of input into either individual
@@ -166,13 +166,13 @@ class InteractiveShell(Configurable, Magic):
input_splitter = Instance('IPython.core.inputsplitter.IPythonInputSplitter',
(), {})
logstart = CBool(False, config=True)
- logfile = Str('', config=True)
- logappend = Str('', config=True)
+ logfile = Unicode('', config=True)
+ logappend = Unicode('', config=True)
object_info_string_level = Enum((0,1,2), default_value=0,
config=True)
pdb = CBool(False, config=True)
- profile = Str('', config=True)
+ profile = Unicode('', config=True)
prompt_in1 = Str('In [\\#]: ', config=True)
prompt_in2 = Str(' .\\D.: ', config=True)
prompt_out = Str('Out[\\#]: ', config=True)
@@ -1987,7 +1987,6 @@ def safe_execfile(self, fname, *where, **kw):
kw.setdefault('exit_ignore', False)
fname = os.path.abspath(os.path.expanduser(fname))
-
# Make sure we have a .py file
if not fname.endswith('.py'):
warn('File must end with .py to be run using execfile: <%s>' % fname)
@@ -2004,6 +2003,11 @@ def safe_execfile(self, fname, *where, **kw):
# behavior of running a script from the system command line, where
# Python inserts the script's directory into sys.path
dname = os.path.dirname(fname)
+
+ if isinstance(fname, unicode):
+ # execfile uses default encoding instead of filesystem encoding
+ # so unicode filenames will fail
+ fname = fname.encode(sys.getfilesystemencoding() or sys.getdefaultencoding())
with prepended_to_syspath(dname):
try:
View
8 IPython/frontend/qt/console/ipython_widget.py
@@ -19,7 +19,7 @@
from IPython.core.inputsplitter import IPythonInputSplitter, \
transform_ipy_prompt
from IPython.core.usage import default_gui_banner
-from IPython.utils.traitlets import Bool, Str
+from IPython.utils.traitlets import Bool, Str, Unicode
from frontend_widget import FrontendWidget
from styles import (default_light_style_sheet, default_light_syntax_style,
default_dark_style_sheet, default_dark_syntax_style,
@@ -57,19 +57,19 @@ class IPythonWidget(FrontendWidget):
# A command for invoking a system text editor. If the string contains a
# {filename} format specifier, it will be used. Otherwise, the filename will
# be appended to the end the command.
- editor = Str('default', config=True)
+ editor = Unicode('default', config=True)
# The editor command to use when a specific line number is requested. The
# string should contain two format specifiers: {line} and {filename}. If
# this parameter is not specified, the line number option to the %edit magic
# will be ignored.
- editor_line = Str(config=True)
+ editor_line = Unicode(config=True)
# A CSS stylesheet. The stylesheet can contain classes for:
# 1. Qt: QPlainTextEdit, QFrame, QWidget, etc
# 2. Pygments: .c, .k, .o, etc (see PygmentsHighlighter)
# 3. IPython: .error, .in-prompt, .out-prompt, etc
- style_sheet = Str(config=True)
+ style_sheet = Unicode(config=True)
# If not empty, use this Pygments style for syntax highlighting. Otherwise,
# the style sheet is queried for Pygments style information.
View
4 IPython/frontend/terminal/embed.py
@@ -33,7 +33,7 @@
from IPython.frontend.terminal.interactiveshell import TerminalInteractiveShell
from IPython.frontend.terminal.ipapp import load_default_config
-from IPython.utils.traitlets import Bool, Str, CBool
+from IPython.utils.traitlets import Bool, Str, CBool, Unicode
from IPython.utils.io import ask_yes_no
@@ -62,7 +62,7 @@ def kill_embedded(self,parameter_s=''):
class InteractiveShellEmbed(TerminalInteractiveShell):
dummy_mode = Bool(False)
- exit_msg = Str('')
+ exit_msg = Unicode('')
embedded = CBool(True)
embedded_active = CBool(True)
# Like the base class display_banner is not configurable, but here it
View
12 IPython/frontend/terminal/interactiveshell.py
@@ -31,7 +31,7 @@
from IPython.utils.process import abbrev_cwd
from IPython.utils.warn import warn
from IPython.utils.text import num_ini_spaces
-from IPython.utils.traitlets import Int, Str, CBool
+from IPython.utils.traitlets import Int, Str, CBool, Unicode
#-----------------------------------------------------------------------------
# Utilities
@@ -59,9 +59,9 @@ def get_default_editor():
class TerminalInteractiveShell(InteractiveShell):
autoedit_syntax = CBool(False, config=True)
- banner = Str('')
- banner1 = Str(default_banner, config=True)
- banner2 = Str('', config=True)
+ banner = Unicode('')
+ banner1 = Unicode(default_banner, config=True)
+ banner2 = Unicode('', config=True)
confirm_exit = CBool(True, config=True)
# This display_banner only controls whether or not self.show_banner()
# is called when mainloop/interact are called. The default is False
@@ -71,8 +71,8 @@ class TerminalInteractiveShell(InteractiveShell):
display_banner = CBool(False) # This isn't configurable!
embedded = CBool(False)
embedded_active = CBool(False)
- editor = Str(get_default_editor(), config=True)
- pager = Str('less', config=True)
+ editor = Unicode(get_default_editor(), config=True)
+ pager = Unicode('less', config=True)
screen_length = Int(0, config=True)
term_title = CBool(False, config=True)
Please sign in to comment.
Something went wrong with that request. Please try again.