##// END OF EJS Templates
remove python2 specific cast_unicode_py2 function
Srinivas Reddy Thatiparthy -
Show More
@@ -139,7 +139,6 b' from IPython.core.latex_symbols import latex_symbols, reverse_latex_symbol'
139 139 from IPython.utils import generics
140 140 from IPython.utils.dir2 import dir2, get_real_method
141 141 from IPython.utils.process import arg_split
142 from IPython.utils.py3compat import cast_unicode_py2
143 142 from traitlets import Bool, Enum, observe, Int
144 143
145 144 try:
@@ -665,7 +664,7 b' class Completer(Configurable):'
665 664 for word in shortened.keys():
666 665 if word[:n] == text and word != "__builtins__":
667 666 match_append(shortened[word])
668 return [cast_unicode_py2(m) for m in matches]
667 return matches
669 668
670 669 def attr_matches(self, text):
671 670 """Compute matches when text contains a dot.
@@ -729,7 +728,7 b' def get__all__entries(obj):'
729 728 except:
730 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 734 def match_dict_keys(keys: List[str], prefix: str, delims: str):
@@ -1125,7 +1124,7 b' class IPCompleter(Completer):'
1125 1124 text = os.path.expanduser(text)
1126 1125
1127 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 1129 # Compute the matches from the filesystem
1131 1130 if sys.platform == 'win32':
@@ -1152,7 +1151,7 b' class IPCompleter(Completer):'
1152 1151 protect_filename(f) for f in m0]
1153 1152
1154 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 1156 def magic_matches(self, text):
1158 1157 """Match magics"""
@@ -1180,7 +1179,7 b' class IPCompleter(Completer):'
1180 1179 if not text.startswith(pre2):
1181 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 1184 def magic_config_matches(self, text):
1186 1185 """ Match class names and attributes for %config magic """
@@ -1637,12 +1636,12 b' class IPCompleter(Completer):'
1637 1636 res = c(event)
1638 1637 if res:
1639 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 1640 if withcase:
1642 1641 return withcase
1643 1642 # if none, then case insensitive ones are ok too
1644 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 1645 except TryNext:
1647 1646 pass
1648 1647
@@ -13,7 +13,6 b' import io as _io'
13 13 import tokenize
14 14
15 15 from traitlets.config.configurable import Configurable
16 from IPython.utils.py3compat import cast_unicode_py2
17 16 from traitlets import Instance, Float
18 17 from warnings import warn
19 18
@@ -87,7 +86,7 b' class DisplayHook(Configurable):'
87 86 # do not print output if input ends in ';'
88 87
89 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 90 except IndexError:
92 91 # some uses of ipshellembed may fail here
93 92 return False
@@ -24,7 +24,6 b' from IPython.core.magic_arguments import (argument, magic_arguments,'
24 24 parse_argstring)
25 25 from IPython.testing.skipdoctest import skip_doctest
26 26 from IPython.utils import io
27 from IPython.utils.py3compat import cast_unicode_py2
28 27
29 28 #-----------------------------------------------------------------------------
30 29 # Magics class implementation
@@ -214,7 +213,7 b' class HistoryMagics(Magics):'
214 213 inline = "\n... ".join(inline.splitlines()) + "\n..."
215 214 print(inline, file=outfile)
216 215 if get_output and output:
217 print(cast_unicode_py2(output), file=outfile)
216 print(output, file=outfile)
218 217
219 218 if close_at_end:
220 219 outfile.close()
@@ -328,7 +328,6 b' def fix_frame_records_filenames(records):'
328 328 # Look inside the frame's globals dictionary for __file__,
329 329 # which should be better. However, keep Cython filenames since
330 330 # we prefer the source filenames over the compiled .so file.
331 filename = py3compat.cast_unicode_py2(filename, "utf-8")
332 331 if not filename.endswith(('.pyx', '.pxd', '.pxi')):
333 332 better_fn = frame.f_globals.get('__file__', None)
334 333 if isinstance(better_fn, str):
@@ -382,8 +381,6 b' def _format_traceback_lines(lnum, index, lines, Colors, lvals=None, _line_forma'
382 381 i = lnum - index
383 382
384 383 for line in lines:
385 line = py3compat.cast_unicode(line)
386
387 384 new_line, err = _line_format(line, 'str')
388 385 if not err: line = new_line
389 386
@@ -652,9 +649,9 b' class ListTB(TBTools):'
652 649 list = []
653 650 for filename, lineno, name, line in extracted_list[:-1]:
654 651 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,
652 (Colors.filename, filename, Colors.Normal,
656 653 Colors.lineno, lineno, Colors.Normal,
657 Colors.name, py3compat.cast_unicode_py2(name, "utf-8"), Colors.Normal)
654 Colors.name, name, Colors.Normal)
658 655 if line:
659 656 item += ' %s\n' % line.strip()
660 657 list.append(item)
@@ -662,9 +659,9 b' class ListTB(TBTools):'
662 659 filename, lineno, name, line = extracted_list[-1]
663 660 item = '%s File %s"%s"%s, line %s%d%s, in %s%s%s%s\n' % \
664 661 (Colors.normalEm,
665 Colors.filenameEm, py3compat.cast_unicode_py2(filename, "utf-8"), Colors.normalEm,
662 Colors.filenameEm, filename, Colors.normalEm,
666 663 Colors.linenoEm, lineno, Colors.normalEm,
667 Colors.nameEm, py3compat.cast_unicode_py2(name, "utf-8"), Colors.normalEm,
664 Colors.nameEm, name, Colors.normalEm,
668 665 Colors.Normal)
669 666 if line:
670 667 item += '%s %s%s\n' % (Colors.line, line.strip(),
@@ -688,7 +685,7 b' class ListTB(TBTools):'
688 685 have_filedata = False
689 686 Colors = self.Colors
690 687 list = []
691 stype = py3compat.cast_unicode(Colors.excName + etype.__name__ + Colors.Normal)
688 stype = Colors.excName + etype.__name__ + Colors.Normal
692 689 if value is None:
693 690 # Not sure if this can still happen in Python 2.6 and above
694 691 list.append(stype + '\n')
@@ -704,10 +701,10 b' class ListTB(TBTools):'
704 701 textline = ''
705 702 list.append('%s File %s"%s"%s, line %s%s%s\n' % \
706 703 (Colors.normalEm,
707 Colors.filenameEm, py3compat.cast_unicode(value.filename), Colors.normalEm,
704 Colors.filenameEm, value.filename, Colors.normalEm,
708 705 Colors.linenoEm, lineno, Colors.Normal ))
709 706 if textline == '':
710 textline = py3compat.cast_unicode(value.text, "utf-8")
707 textline = value.text
711 708
712 709 if textline is not None:
713 710 i = 0
@@ -772,7 +769,7 b' class ListTB(TBTools):'
772 769 def _some_str(self, value):
773 770 # Lifted from traceback.py
774 771 try:
775 return py3compat.cast_unicode(str(value))
772 return str(value)
776 773 except:
777 774 return u'<unprintable %s object>' % type(value).__name__
778 775
@@ -869,7 +866,6 b' class VerboseTB(TBTools):'
869 866 # strange entries...
870 867 pass
871 868
872 file = py3compat.cast_unicode(file, util_path.fs_encoding)
873 869 link = tpl_link % util_path.compress_user(file)
874 870 args, varargs, varkw, locals = inspect.getargvalues(frame)
875 871
@@ -1047,8 +1043,7 b' class VerboseTB(TBTools):'
1047 1043 etype, evalue = str, sys.exc_info()[:2]
1048 1044 etype_str, evalue_str = map(str, (etype, evalue))
1049 1045 # ... and format it
1050 return ['%s%s%s: %s' % (colors.excName, etype_str,
1051 colorsnormal, py3compat.cast_unicode(evalue_str))]
1046 return ['%s%s%s: %s' % (colors.excName, etype_str, colorsnormal, evalue_str)]
1052 1047
1053 1048 def format_exception_as_a_whole(self, etype, evalue, etb, number_of_lines_of_context, tb_offset):
1054 1049 """Formats the header, traceback and exception message for a single exception.
@@ -15,7 +15,7 b' from IPython.utils.process import find_cmd, FindCmdError'
15 15 from traitlets.config import get_config
16 16 from traitlets.config.configurable import SingletonConfigurable
17 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 21 class LaTeXTool(SingletonConfigurable):
@@ -161,20 +161,20 b' def genelatex(body, wrap):'
161 161 """Generate LaTeX document for dvipng backend."""
162 162 lt = LaTeXTool.instance()
163 163 breqn = wrap and lt.use_breqn and kpsewhich("breqn.sty")
164 yield u(r'\documentclass{article}')
164 yield r'\documentclass{article}'
165 165 packages = lt.packages
166 166 if breqn:
167 167 packages = packages + ['breqn']
168 168 for pack in packages:
169 yield u(r'\usepackage{{{0}}}'.format(pack))
170 yield u(r'\pagestyle{empty}')
169 yield r'\usepackage{{{0}}}'.format(pack)
170 yield r'\pagestyle{empty}'
171 171 if lt.preamble:
172 172 yield lt.preamble
173 yield u(r'\begin{document}')
173 yield r'\begin{document}'
174 174 if breqn:
175 yield u(r'\begin{dmath*}')
175 yield r'\begin{dmath*}'
176 176 yield body
177 yield u(r'\end{dmath*}')
177 yield r'\end{dmath*}'
178 178 elif wrap:
179 179 yield u'$${0}$$'.format(body)
180 180 else:
@@ -7,7 +7,7 b' from warnings import warn'
7 7
8 8 from IPython.core.interactiveshell import InteractiveShell, InteractiveShellABC
9 9 from IPython.utils import io
10 from IPython.utils.py3compat import cast_unicode_py2, input
10 from IPython.utils.py3compat import input
11 11 from IPython.utils.terminal import toggle_set_term_title, set_term_title
12 12 from IPython.utils.process import abbrev_cwd
13 13 from traitlets import (
@@ -227,7 +227,7 b' class TerminalInteractiveShell(InteractiveShell):'
227 227 # Fall back to plain non-interactive output for tests.
228 228 # This is very limited, and only accepts a single line.
229 229 def prompt():
230 return cast_unicode_py2(input('In [%d]: ' % self.execution_count))
230 return input('In [%d]: ' % self.execution_count)
231 231 self.prompt_for_code = prompt
232 232 return
233 233
@@ -432,7 +432,7 b' class TerminalInteractiveShell(InteractiveShell):'
432 432 # We can't set the buffer here, because it will be reset just after
433 433 # this. Adding a callable to pre_run_callables does what we need
434 434 # after the buffer is reset.
435 s = cast_unicode_py2(self.rl_next_input)
435 s = self.rl_next_input
436 436 def set_doc():
437 437 self.pt_cli.application.buffer.document = Document(s)
438 438 if hasattr(self.pt_cli, 'pre_run_callables'):
@@ -3,13 +3,12 b''
3 3 # Copyright (c) IPython Development Team.
4 4 # Distributed under the terms of the Modified BSD License.
5 5
6
7 6 from collections import namedtuple
8 7 from io import StringIO
9 8 from keyword import iskeyword
10 9
11 10 from . import tokenize2
12 from .py3compat import cast_unicode_py2
11
13 12
14 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 67 cursor_pos : int
69 68 The location of the cursor in the block where the token should be found
70 69 """
71 cell = cast_unicode_py2(cell)
72 70 names = []
73 71 tokens = []
74 72 call_names = []
General Comments 0
You need to be logged in to leave comments. Login now