##// END OF EJS Templates
remove unicode_type function
Srinivas Reddy Thatiparthy -
Show More
@@ -18,7 +18,7 b' import struct'
18 import sys
18 import sys
19 import warnings
19 import warnings
20
20
21 from IPython.utils.py3compat import cast_bytes_py2, cast_unicode, unicode_type
21 from IPython.utils.py3compat import cast_bytes_py2, cast_unicode
22 from IPython.testing.skipdoctest import skip_doctest
22 from IPython.testing.skipdoctest import skip_doctest
23
23
24 __all__ = ['display', 'display_pretty', 'display_html', 'display_markdown',
24 __all__ = ['display', 'display_pretty', 'display_html', 'display_markdown',
@@ -492,7 +492,7 b' class DisplayObject(object):'
492
492
493 self.data = data
493 self.data = data
494 self.url = url
494 self.url = url
495 self.filename = None if filename is None else unicode_type(filename)
495 self.filename = filename
496
496
497 self.reload()
497 self.reload()
498 self._check_data()
498 self._check_data()
@@ -876,7 +876,7 b' class Image(DisplayObject):'
876 # jpg->jpeg
876 # jpg->jpeg
877 format = self._FMT_JPEG
877 format = self._FMT_JPEG
878
878
879 self.format = unicode_type(format).lower()
879 self.format = format.lower()
880 self.embed = embed if embed is not None else (url is None)
880 self.embed = embed if embed is not None else (url is None)
881
881
882 if self.embed and self.format not in self._ACCEPTABLE_EMBEDDINGS:
882 if self.embed and self.format not in self._ACCEPTABLE_EMBEDDINGS:
@@ -953,7 +953,7 b' class Image(DisplayObject):'
953 return self._data_and_metadata()
953 return self._data_and_metadata()
954
954
955 def _find_ext(self, s):
955 def _find_ext(self, s):
956 return unicode_type(s.split('.')[-1].lower())
956 return s.split('.')[-1].lower()
957
957
958 class Video(DisplayObject):
958 class Video(DisplayObject):
959
959
@@ -1037,7 +1037,7 b' class Video(DisplayObject):'
1037 video = f.read()
1037 video = f.read()
1038 else:
1038 else:
1039 video = self.data
1039 video = self.data
1040 if isinstance(video, unicode_type):
1040 if isinstance(video, str):
1041 # unicode input is already b64-encoded
1041 # unicode input is already b64-encoded
1042 b64_video = video
1042 b64_video = video
1043 else:
1043 else:
@@ -29,7 +29,7 b' from traitlets import ('
29 default, observe,
29 default, observe,
30 )
30 )
31 from IPython.utils.py3compat import (
31 from IPython.utils.py3compat import (
32 with_metaclass, unicode_type,
32 with_metaclass
33 )
33 )
34
34
35
35
@@ -737,7 +737,7 b' class PNGFormatter(BaseFormatter):'
737
737
738 print_method = ObjectName('_repr_png_')
738 print_method = ObjectName('_repr_png_')
739
739
740 _return_type = (bytes, unicode_type)
740 _return_type = (bytes, str)
741
741
742
742
743 class JPEGFormatter(BaseFormatter):
743 class JPEGFormatter(BaseFormatter):
@@ -755,7 +755,7 b' class JPEGFormatter(BaseFormatter):'
755
755
756 print_method = ObjectName('_repr_jpeg_')
756 print_method = ObjectName('_repr_jpeg_')
757
757
758 _return_type = (bytes, unicode_type)
758 _return_type = (bytes, str)
759
759
760
760
761 class LatexFormatter(BaseFormatter):
761 class LatexFormatter(BaseFormatter):
@@ -846,7 +846,7 b' class PDFFormatter(BaseFormatter):'
846
846
847 print_method = ObjectName('_repr_pdf_')
847 print_method = ObjectName('_repr_pdf_')
848
848
849 _return_type = (bytes, unicode_type)
849 _return_type = (bytes, str)
850
850
851 class IPythonDisplayFormatter(BaseFormatter):
851 class IPythonDisplayFormatter(BaseFormatter):
852 """A Formatter for objects that know how to display themselves.
852 """A Formatter for objects that know how to display themselves.
@@ -67,7 +67,7 b' from IPython.utils.ipstruct import Struct'
67 from IPython.paths import get_ipython_dir
67 from IPython.paths import get_ipython_dir
68 from IPython.utils.path import get_home_dir, get_py_filename, ensure_dir_exists
68 from IPython.utils.path import get_home_dir, get_py_filename, ensure_dir_exists
69 from IPython.utils.process import system, getoutput
69 from IPython.utils.process import system, getoutput
70 from IPython.utils.py3compat import builtin_mod, unicode_type, with_metaclass
70 from IPython.utils.py3compat import builtin_mod, with_metaclass
71 from IPython.utils.strdispatch import StrDispatch
71 from IPython.utils.strdispatch import StrDispatch
72 from IPython.utils.syspathcontext import prepended_to_syspath
72 from IPython.utils.syspathcontext import prepended_to_syspath
73 from IPython.utils.text import format_screen, LSString, SList, DollarFormatter
73 from IPython.utils.text import format_screen, LSString, SList, DollarFormatter
@@ -2340,7 +2340,7 b' class InteractiveShell(SingletonConfigurable):'
2340 exc_info = {
2340 exc_info = {
2341 u'status' : 'error',
2341 u'status' : 'error',
2342 u'traceback' : stb,
2342 u'traceback' : stb,
2343 u'ename' : unicode_type(etype.__name__),
2343 u'ename' : etype.__name__,
2344 u'evalue' : py3compat.safe_unicode(evalue),
2344 u'evalue' : py3compat.safe_unicode(evalue),
2345 }
2345 }
2346
2346
@@ -12,7 +12,6 b' from IPython.core.magic import Magics, magics_class, line_magic, magic_escapes'
12 from IPython.utils.text import format_screen, dedent, indent
12 from IPython.utils.text import format_screen, dedent, indent
13 from IPython.testing.skipdoctest import skip_doctest
13 from IPython.testing.skipdoctest import skip_doctest
14 from IPython.utils.ipstruct import Struct
14 from IPython.utils.ipstruct import Struct
15 from IPython.utils.py3compat import unicode_type
16 from warnings import warn
15 from warnings import warn
17 from logging import error
16 from logging import error
18
17
@@ -550,7 +549,7 b' Currently the magic system has the following functions:""",'
550 help=argparse.SUPPRESS
549 help=argparse.SUPPRESS
551 )
550 )
552 @magic_arguments.argument(
551 @magic_arguments.argument(
553 'filename', type=unicode_type,
552 'filename', type=str,
554 help='Notebook name or filename'
553 help='Notebook name or filename'
555 )
554 )
556 @line_magic
555 @line_magic
@@ -25,7 +25,6 b' from IPython.testing.skipdoctest import skip_doctest'
25 from IPython.utils.encoding import DEFAULT_ENCODING
25 from IPython.utils.encoding import DEFAULT_ENCODING
26 from IPython.utils.openpy import read_py_file
26 from IPython.utils.openpy import read_py_file
27 from IPython.utils.path import get_py_filename
27 from IPython.utils.path import get_py_filename
28 from IPython.utils.py3compat import unicode_type
29
28
30 #-----------------------------------------------------------------------------
29 #-----------------------------------------------------------------------------
31 # Magic implementation classes
30 # Magic implementation classes
@@ -460,8 +459,8 b' class NamespaceMagics(Magics):'
460 try:
459 try:
461 vstr = str(var)
460 vstr = str(var)
462 except UnicodeEncodeError:
461 except UnicodeEncodeError:
463 vstr = unicode_type(var).encode(DEFAULT_ENCODING,
462 vstr = var.encode(DEFAULT_ENCODING,
464 'backslashreplace')
463 'backslashreplace')
465 except:
464 except:
466 vstr = "<object with id %d (str() failed)>" % id(var)
465 vstr = "<object with id %d (str() failed)>" % id(var)
467 vstr = vstr.replace('\n', '\\n')
466 vstr = vstr.replace('\n', '\\n')
@@ -35,7 +35,6 b' from IPython.testing.skipdoctest import skip_doctest'
35 from IPython.utils.openpy import source_to_unicode
35 from IPython.utils.openpy import source_to_unicode
36 from IPython.utils.process import abbrev_cwd
36 from IPython.utils.process import abbrev_cwd
37 from IPython.utils import py3compat
37 from IPython.utils import py3compat
38 from IPython.utils.py3compat import unicode_type
39 from IPython.utils.terminal import set_term_title
38 from IPython.utils.terminal import set_term_title
40
39
41 #-----------------------------------------------------------------------------
40 #-----------------------------------------------------------------------------
@@ -764,7 +763,7 b' class OSMagics(Magics):'
764 'The file will be created if it does not exist.'
763 'The file will be created if it does not exist.'
765 )
764 )
766 @magic_arguments.argument(
765 @magic_arguments.argument(
767 'filename', type=unicode_type,
766 'filename', type=str,
768 help='file to write'
767 help='file to write'
769 )
768 )
770 @cell_magic
769 @cell_magic
@@ -20,7 +20,7 b' class LazyEvaluate(object):'
20 return str(self())
20 return str(self())
21
21
22 def __unicode__(self):
22 def __unicode__(self):
23 return py3compat.unicode_type(self())
23 return self.__str__()
24
24
25 def __format__(self, format_spec):
25 def __format__(self, format_spec):
26 return format(self(), format_spec)
26 return format(self(), format_spec)
@@ -18,7 +18,6 b' from IPython.core import completer'
18 from IPython.external.decorators import knownfailureif
18 from IPython.external.decorators import knownfailureif
19 from IPython.utils.tempdir import TemporaryDirectory, TemporaryWorkingDirectory
19 from IPython.utils.tempdir import TemporaryDirectory, TemporaryWorkingDirectory
20 from IPython.utils.generics import complete_object
20 from IPython.utils.generics import complete_object
21 from IPython.utils.py3compat import unicode_type
22 from IPython.testing import decorators as dec
21 from IPython.testing import decorators as dec
23
22
24 #-----------------------------------------------------------------------------
23 #-----------------------------------------------------------------------------
@@ -102,7 +101,7 b' def test_line_split():'
102 check_line_split(sp, t)
101 check_line_split(sp, t)
103 # Ensure splitting works OK with unicode by re-running the tests with
102 # Ensure splitting works OK with unicode by re-running the tests with
104 # all inputs turned into unicode
103 # all inputs turned into unicode
105 check_line_split(sp, [ map(unicode_type, p) for p in t] )
104 check_line_split(sp, [ map(str, p) for p in t] )
106
105
107
106
108 def test_custom_completion_error():
107 def test_custom_completion_error():
@@ -123,7 +122,7 b' def test_unicode_completions():'
123 # Some strings that trigger different types of completion. Check them both
122 # Some strings that trigger different types of completion. Check them both
124 # in str and unicode forms
123 # in str and unicode forms
125 s = ['ru', '%ru', 'cd /', 'floa', 'float(x)/']
124 s = ['ru', '%ru', 'cd /', 'floa', 'float(x)/']
126 for t in s + list(map(unicode_type, s)):
125 for t in s + list(map(str, s)):
127 # We don't need to check exact completion values (they may change
126 # We don't need to check exact completion values (they may change
128 # depending on the state of the namespace, but at least no exceptions
127 # depending on the state of the namespace, but at least no exceptions
129 # should be thrown and the return value should be a pair of text, list
128 # should be thrown and the return value should be a pair of text, list
@@ -32,7 +32,7 b' from IPython.testing.decorators import ('
32 from IPython.testing import tools as tt
32 from IPython.testing import tools as tt
33 from IPython.utils.process import find_cmd
33 from IPython.utils.process import find_cmd
34 from IPython.utils import py3compat
34 from IPython.utils import py3compat
35 from IPython.utils.py3compat import unicode_type, PY3
35 from IPython.utils.py3compat import PY3
36
36
37 if PY3:
37 if PY3:
38 from io import StringIO
38 from io import StringIO
@@ -473,7 +473,7 b' class InteractiveShellTestCase(unittest.TestCase):'
473 def test_inspect_text(self):
473 def test_inspect_text(self):
474 ip.run_cell('a = 5')
474 ip.run_cell('a = 5')
475 text = ip.object_inspect_text('a')
475 text = ip.object_inspect_text('a')
476 self.assertIsInstance(text, unicode_type)
476 self.assertIsInstance(text, str)
477
477
478
478
479 class TestSafeExecfileNonAsciiPath(unittest.TestCase):
479 class TestSafeExecfileNonAsciiPath(unittest.TestCase):
@@ -5,7 +5,6 b' import unittest'
5
5
6 from IPython.core.prompts import LazyEvaluate
6 from IPython.core.prompts import LazyEvaluate
7 from IPython.testing.globalipapp import get_ipython
7 from IPython.testing.globalipapp import get_ipython
8 from IPython.utils.py3compat import unicode_type
9
8
10 ip = get_ipython()
9 ip = get_ipython()
11
10
@@ -14,8 +13,7 b' class PromptTests(unittest.TestCase):'
14 def test_lazy_eval_unicode(self):
13 def test_lazy_eval_unicode(self):
15 u = u'ünicødé'
14 u = u'ünicødé'
16 lz = LazyEvaluate(lambda : u)
15 lz = LazyEvaluate(lambda : u)
17 # str(lz) would fail
16 self.assertEqual(str(lz), u)
18 self.assertEqual(unicode_type(lz), u)
19 self.assertEqual(format(lz), u)
17 self.assertEqual(format(lz), u)
20
18
21 def test_lazy_eval_nonascii_bytes(self):
19 def test_lazy_eval_nonascii_bytes(self):
@@ -31,7 +29,6 b' class PromptTests(unittest.TestCase):'
31 lz = LazyEvaluate(lambda : f)
29 lz = LazyEvaluate(lambda : f)
32
30
33 self.assertEqual(str(lz), str(f))
31 self.assertEqual(str(lz), str(f))
34 self.assertEqual(unicode_type(lz), unicode_type(f))
35 self.assertEqual(format(lz), str(f))
32 self.assertEqual(format(lz), str(f))
36 self.assertEqual(format(lz, '.1'), '0.5')
33 self.assertEqual(format(lz, '.1'), '0.5')
37
34
@@ -3,7 +3,6 b' import nose.tools as nt'
3 from IPython.core.error import TryNext
3 from IPython.core.error import TryNext
4 from IPython.lib.clipboard import ClipboardEmpty
4 from IPython.lib.clipboard import ClipboardEmpty
5 from IPython.testing.decorators import skip_if_no_x11
5 from IPython.testing.decorators import skip_if_no_x11
6 from IPython.utils.py3compat import unicode_type
7
6
8 @skip_if_no_x11
7 @skip_if_no_x11
9 def test_clipboard_get():
8 def test_clipboard_get():
@@ -19,4 +18,4 b' def test_clipboard_get():'
19 # No clipboard access API available
18 # No clipboard access API available
20 pass
19 pass
21 else:
20 else:
22 nt.assert_is_instance(a, unicode_type)
21 nt.assert_is_instance(a, str)
@@ -10,7 +10,6 b' from io import TextIOWrapper, BytesIO'
10 import os.path
10 import os.path
11 import re
11 import re
12
12
13 from .py3compat import unicode_type
14
13
15 cookie_re = re.compile(r"coding[:=]\s*([-\w.]+)", re.UNICODE)
14 cookie_re = re.compile(r"coding[:=]\s*([-\w.]+)", re.UNICODE)
16 cookie_comment_re = re.compile(r"^\s*#.*coding[:=]\s*([-\w.]+)", re.UNICODE)
15 cookie_comment_re = re.compile(r"^\s*#.*coding[:=]\s*([-\w.]+)", re.UNICODE)
@@ -129,7 +128,7 b" def source_to_unicode(txt, errors='replace', skip_encoding_cookie=True):"
129 txt can be either a bytes buffer or a string containing the source
128 txt can be either a bytes buffer or a string containing the source
130 code.
129 code.
131 """
130 """
132 if isinstance(txt, unicode_type):
131 if isinstance(txt, str):
133 return txt
132 return txt
134 if isinstance(txt, bytes):
133 if isinstance(txt, bytes):
135 buffer = BytesIO(txt)
134 buffer = BytesIO(txt)
@@ -25,8 +25,7 b' else:'
25 filename = py3compat.cast_bytes(filename, sys.getfilesystemencoding())
25 filename = py3compat.cast_bytes(filename, sys.getfilesystemencoding())
26 lines = linecache.getlines(filename, module_globals=module_globals)
26 lines = linecache.getlines(filename, module_globals=module_globals)
27
27
28 # The bits we cache ourselves can be unicode.
28 if (not lines) or isinstance(lines[0], str):
29 if (not lines) or isinstance(lines[0], py3compat.unicode_type):
30 return lines
29 return lines
31
30
32 readline = openpy._list_readline(lines)
31 readline = openpy._list_readline(lines)
General Comments 0
You need to be logged in to leave comments. Login now