##// END OF EJS Templates
Merge pull request #10574 from srinivasreddy/cast_unicode_py2...
Thomas Kluyver -
r23672:00c5fbc9 merge
parent child Browse files
Show More
@@ -139,7 +139,6 b' from IPython.core.latex_symbols import latex_symbols, reverse_latex_symbol'
139 from IPython.utils import generics
139 from IPython.utils import generics
140 from IPython.utils.dir2 import dir2, get_real_method
140 from IPython.utils.dir2 import dir2, get_real_method
141 from IPython.utils.process import arg_split
141 from IPython.utils.process import arg_split
142 from IPython.utils.py3compat import cast_unicode_py2
143 from traitlets import Bool, Enum, observe, Int
142 from traitlets import Bool, Enum, observe, Int
144
143
145 try:
144 try:
@@ -665,7 +664,7 b' class Completer(Configurable):'
665 for word in shortened.keys():
664 for word in shortened.keys():
666 if word[:n] == text and word != "__builtins__":
665 if word[:n] == text and word != "__builtins__":
667 match_append(shortened[word])
666 match_append(shortened[word])
668 return [cast_unicode_py2(m) for m in matches]
667 return matches
669
668
670 def attr_matches(self, text):
669 def attr_matches(self, text):
671 """Compute matches when text contains a dot.
670 """Compute matches when text contains a dot.
@@ -729,7 +728,7 b' def get__all__entries(obj):'
729 except:
728 except:
730 return []
729 return []
731
730
732 return [cast_unicode_py2(w) for w in words if isinstance(w, str)]
731 return [w for w in words if isinstance(w, str)]
733
732
734
733
735 def match_dict_keys(keys: List[str], prefix: str, delims: str):
734 def match_dict_keys(keys: List[str], prefix: str, delims: str):
@@ -1125,7 +1124,7 b' class IPCompleter(Completer):'
1125 text = os.path.expanduser(text)
1124 text = os.path.expanduser(text)
1126
1125
1127 if text == "":
1126 if text == "":
1128 return [text_prefix + cast_unicode_py2(protect_filename(f)) for f in self.glob("*")]
1127 return [text_prefix + protect_filename(f) for f in self.glob("*")]
1129
1128
1130 # Compute the matches from the filesystem
1129 # Compute the matches from the filesystem
1131 if sys.platform == 'win32':
1130 if sys.platform == 'win32':
@@ -1152,7 +1151,7 b' class IPCompleter(Completer):'
1152 protect_filename(f) for f in m0]
1151 protect_filename(f) for f in m0]
1153
1152
1154 # Mark directories in input list by appending '/' to their names.
1153 # Mark directories in input list by appending '/' to their names.
1155 return [cast_unicode_py2(x+'/') if os.path.isdir(x) else x for x in matches]
1154 return [x+'/' if os.path.isdir(x) else x for x in matches]
1156
1155
1157 def magic_matches(self, text):
1156 def magic_matches(self, text):
1158 """Match magics"""
1157 """Match magics"""
@@ -1180,7 +1179,7 b' class IPCompleter(Completer):'
1180 if not text.startswith(pre2):
1179 if not text.startswith(pre2):
1181 comp += [ pre+m for m in line_magics if matches(m)]
1180 comp += [ pre+m for m in line_magics if matches(m)]
1182
1181
1183 return [cast_unicode_py2(c) for c in comp]
1182 return comp
1184
1183
1185 def magic_config_matches(self, text):
1184 def magic_config_matches(self, text):
1186 """ Match class names and attributes for %config magic """
1185 """ Match class names and attributes for %config magic """
@@ -1637,12 +1636,12 b' class IPCompleter(Completer):'
1637 res = c(event)
1636 res = c(event)
1638 if res:
1637 if res:
1639 # first, try case sensitive match
1638 # first, try case sensitive match
1640 withcase = [cast_unicode_py2(r) for r in res if r.startswith(text)]
1639 withcase = [r for r in res if r.startswith(text)]
1641 if withcase:
1640 if withcase:
1642 return withcase
1641 return withcase
1643 # if none, then case insensitive ones are ok too
1642 # if none, then case insensitive ones are ok too
1644 text_low = text.lower()
1643 text_low = text.lower()
1645 return [cast_unicode_py2(r) for r in res if r.lower().startswith(text_low)]
1644 return [r for r in res if r.lower().startswith(text_low)]
1646 except TryNext:
1645 except TryNext:
1647 pass
1646 pass
1648
1647
@@ -13,7 +13,6 b' import io as _io'
13 import tokenize
13 import tokenize
14
14
15 from traitlets.config.configurable import Configurable
15 from traitlets.config.configurable import Configurable
16 from IPython.utils.py3compat import cast_unicode_py2
17 from traitlets import Instance, Float
16 from traitlets import Instance, Float
18 from warnings import warn
17 from warnings import warn
19
18
@@ -87,7 +86,7 b' class DisplayHook(Configurable):'
87 # do not print output if input ends in ';'
86 # do not print output if input ends in ';'
88
87
89 try:
88 try:
90 cell = cast_unicode_py2(self.shell.history_manager.input_hist_parsed[-1])
89 cell = self.shell.history_manager.input_hist_parsed[-1]
91 except IndexError:
90 except IndexError:
92 # some uses of ipshellembed may fail here
91 # some uses of ipshellembed may fail here
93 return False
92 return False
@@ -24,7 +24,6 b' from IPython.core.magic_arguments import (argument, magic_arguments,'
24 parse_argstring)
24 parse_argstring)
25 from IPython.testing.skipdoctest import skip_doctest
25 from IPython.testing.skipdoctest import skip_doctest
26 from IPython.utils import io
26 from IPython.utils import io
27 from IPython.utils.py3compat import cast_unicode_py2
28
27
29 #-----------------------------------------------------------------------------
28 #-----------------------------------------------------------------------------
30 # Magics class implementation
29 # Magics class implementation
@@ -214,7 +213,7 b' class HistoryMagics(Magics):'
214 inline = "\n... ".join(inline.splitlines()) + "\n..."
213 inline = "\n... ".join(inline.splitlines()) + "\n..."
215 print(inline, file=outfile)
214 print(inline, file=outfile)
216 if get_output and output:
215 if get_output and output:
217 print(cast_unicode_py2(output), file=outfile)
216 print(output, file=outfile)
218
217
219 if close_at_end:
218 if close_at_end:
220 outfile.close()
219 outfile.close()
@@ -328,7 +328,6 b' def fix_frame_records_filenames(records):'
328 # Look inside the frame's globals dictionary for __file__,
328 # Look inside the frame's globals dictionary for __file__,
329 # which should be better. However, keep Cython filenames since
329 # which should be better. However, keep Cython filenames since
330 # we prefer the source filenames over the compiled .so file.
330 # we prefer the source filenames over the compiled .so file.
331 filename = py3compat.cast_unicode_py2(filename, "utf-8")
332 if not filename.endswith(('.pyx', '.pxd', '.pxi')):
331 if not filename.endswith(('.pyx', '.pxd', '.pxi')):
333 better_fn = frame.f_globals.get('__file__', None)
332 better_fn = frame.f_globals.get('__file__', None)
334 if isinstance(better_fn, str):
333 if isinstance(better_fn, str):
@@ -652,9 +651,9 b' class ListTB(TBTools):'
652 list = []
651 list = []
653 for filename, lineno, name, line in extracted_list[:-1]:
652 for filename, lineno, name, line in extracted_list[:-1]:
654 item = ' File %s"%s"%s, line %s%d%s, in %s%s%s\n' % \
653 item = ' File %s"%s"%s, line %s%d%s, in %s%s%s\n' % \
655 (Colors.filename, py3compat.cast_unicode_py2(filename, "utf-8"), Colors.Normal,
654 (Colors.filename, filename, Colors.Normal,
656 Colors.lineno, lineno, Colors.Normal,
655 Colors.lineno, lineno, Colors.Normal,
657 Colors.name, py3compat.cast_unicode_py2(name, "utf-8"), Colors.Normal)
656 Colors.name, name, Colors.Normal)
658 if line:
657 if line:
659 item += ' %s\n' % line.strip()
658 item += ' %s\n' % line.strip()
660 list.append(item)
659 list.append(item)
@@ -662,9 +661,9 b' class ListTB(TBTools):'
662 filename, lineno, name, line = extracted_list[-1]
661 filename, lineno, name, line = extracted_list[-1]
663 item = '%s File %s"%s"%s, line %s%d%s, in %s%s%s%s\n' % \
662 item = '%s File %s"%s"%s, line %s%d%s, in %s%s%s%s\n' % \
664 (Colors.normalEm,
663 (Colors.normalEm,
665 Colors.filenameEm, py3compat.cast_unicode_py2(filename, "utf-8"), Colors.normalEm,
664 Colors.filenameEm, filename, Colors.normalEm,
666 Colors.linenoEm, lineno, Colors.normalEm,
665 Colors.linenoEm, lineno, Colors.normalEm,
667 Colors.nameEm, py3compat.cast_unicode_py2(name, "utf-8"), Colors.normalEm,
666 Colors.nameEm, name, Colors.normalEm,
668 Colors.Normal)
667 Colors.Normal)
669 if line:
668 if line:
670 item += '%s %s%s\n' % (Colors.line, line.strip(),
669 item += '%s %s%s\n' % (Colors.line, line.strip(),
@@ -15,7 +15,7 b' from IPython.utils.process import find_cmd, FindCmdError'
15 from traitlets.config import get_config
15 from traitlets.config import get_config
16 from traitlets.config.configurable import SingletonConfigurable
16 from traitlets.config.configurable import SingletonConfigurable
17 from traitlets import List, Bool, Unicode
17 from traitlets import List, Bool, Unicode
18 from IPython.utils.py3compat import cast_unicode, cast_unicode_py2 as u
18 from IPython.utils.py3compat import cast_unicode
19
19
20
20
21 class LaTeXTool(SingletonConfigurable):
21 class LaTeXTool(SingletonConfigurable):
@@ -161,20 +161,20 b' def genelatex(body, wrap):'
161 """Generate LaTeX document for dvipng backend."""
161 """Generate LaTeX document for dvipng backend."""
162 lt = LaTeXTool.instance()
162 lt = LaTeXTool.instance()
163 breqn = wrap and lt.use_breqn and kpsewhich("breqn.sty")
163 breqn = wrap and lt.use_breqn and kpsewhich("breqn.sty")
164 yield u(r'\documentclass{article}')
164 yield r'\documentclass{article}'
165 packages = lt.packages
165 packages = lt.packages
166 if breqn:
166 if breqn:
167 packages = packages + ['breqn']
167 packages = packages + ['breqn']
168 for pack in packages:
168 for pack in packages:
169 yield u(r'\usepackage{{{0}}}'.format(pack))
169 yield r'\usepackage{{{0}}}'.format(pack)
170 yield u(r'\pagestyle{empty}')
170 yield r'\pagestyle{empty}'
171 if lt.preamble:
171 if lt.preamble:
172 yield lt.preamble
172 yield lt.preamble
173 yield u(r'\begin{document}')
173 yield r'\begin{document}'
174 if breqn:
174 if breqn:
175 yield u(r'\begin{dmath*}')
175 yield r'\begin{dmath*}'
176 yield body
176 yield body
177 yield u(r'\end{dmath*}')
177 yield r'\end{dmath*}'
178 elif wrap:
178 elif wrap:
179 yield u'$${0}$$'.format(body)
179 yield u'$${0}$$'.format(body)
180 else:
180 else:
@@ -7,7 +7,7 b' from warnings import warn'
7
7
8 from IPython.core.interactiveshell import InteractiveShell, InteractiveShellABC
8 from IPython.core.interactiveshell import InteractiveShell, InteractiveShellABC
9 from IPython.utils import io
9 from IPython.utils import io
10 from IPython.utils.py3compat import cast_unicode_py2, input
10 from IPython.utils.py3compat import input
11 from IPython.utils.terminal import toggle_set_term_title, set_term_title
11 from IPython.utils.terminal import toggle_set_term_title, set_term_title
12 from IPython.utils.process import abbrev_cwd
12 from IPython.utils.process import abbrev_cwd
13 from traitlets import (
13 from traitlets import (
@@ -227,7 +227,7 b' class TerminalInteractiveShell(InteractiveShell):'
227 # Fall back to plain non-interactive output for tests.
227 # Fall back to plain non-interactive output for tests.
228 # This is very limited, and only accepts a single line.
228 # This is very limited, and only accepts a single line.
229 def prompt():
229 def prompt():
230 return cast_unicode_py2(input('In [%d]: ' % self.execution_count))
230 return input('In [%d]: ' % self.execution_count)
231 self.prompt_for_code = prompt
231 self.prompt_for_code = prompt
232 return
232 return
233
233
@@ -432,7 +432,7 b' class TerminalInteractiveShell(InteractiveShell):'
432 # We can't set the buffer here, because it will be reset just after
432 # We can't set the buffer here, because it will be reset just after
433 # this. Adding a callable to pre_run_callables does what we need
433 # this. Adding a callable to pre_run_callables does what we need
434 # after the buffer is reset.
434 # after the buffer is reset.
435 s = cast_unicode_py2(self.rl_next_input)
435 s = self.rl_next_input
436 def set_doc():
436 def set_doc():
437 self.pt_cli.application.buffer.document = Document(s)
437 self.pt_cli.application.buffer.document = Document(s)
438 if hasattr(self.pt_cli, 'pre_run_callables'):
438 if hasattr(self.pt_cli, 'pre_run_callables'):
@@ -3,13 +3,12 b''
3 # Copyright (c) IPython Development Team.
3 # Copyright (c) IPython Development Team.
4 # Distributed under the terms of the Modified BSD License.
4 # Distributed under the terms of the Modified BSD License.
5
5
6
7 from collections import namedtuple
6 from collections import namedtuple
8 from io import StringIO
7 from io import StringIO
9 from keyword import iskeyword
8 from keyword import iskeyword
10
9
11 from . import tokenize2
10 from . import tokenize2
12 from .py3compat import cast_unicode_py2
11
13
12
14 Token = namedtuple('Token', ['token', 'text', 'start', 'end', 'line'])
13 Token = namedtuple('Token', ['token', 'text', 'start', 'end', 'line'])
15
14
@@ -68,7 +67,6 b' def token_at_cursor(cell, cursor_pos=0):'
68 cursor_pos : int
67 cursor_pos : int
69 The location of the cursor in the block where the token should be found
68 The location of the cursor in the block where the token should be found
70 """
69 """
71 cell = cast_unicode_py2(cell)
72 names = []
70 names = []
73 tokens = []
71 tokens = []
74 call_names = []
72 call_names = []
General Comments 0
You need to be logged in to leave comments. Login now