##// END OF EJS Templates
Merge pull request #10021 from ivanov/remove-sys-version-checks...
Thomas Kluyver -
r22981:6a5220d0 merge
parent child Browse files
Show More
@@ -0,0 +1,5 b''
1 """This tests that future compiler flags are passed to the embedded IPython."""
2 from __future__ import barry_as_FLUFL
3 from IPython import embed
4 embed(banner1='', header='check 1 <> 2 == True')
5 embed(banner1='', header='check 1 <> 2 cause SyntaxError', compile_flags=0)
@@ -18,7 +18,6 b' http://ipython.org'
18 #-----------------------------------------------------------------------------
18 #-----------------------------------------------------------------------------
19 # Imports
19 # Imports
20 #-----------------------------------------------------------------------------
20 #-----------------------------------------------------------------------------
21 from __future__ import absolute_import
22
21
23 import os
22 import os
24 import sys
23 import sys
@@ -25,7 +25,6 b' Authors'
25 #-----------------------------------------------------------------------------
25 #-----------------------------------------------------------------------------
26 # Imports
26 # Imports
27 #-----------------------------------------------------------------------------
27 #-----------------------------------------------------------------------------
28 from __future__ import print_function
29
28
30 # Stdlib imports
29 # Stdlib imports
31 import __future__
30 import __future__
@@ -13,7 +13,6 b' upstream and were accepted as of Python 2.3,'
13 # Some of this code originated from rlcompleter in the Python standard library
13 # Some of this code originated from rlcompleter in the Python standard library
14 # Copyright (C) 2001 Python Software Foundation, www.python.org
14 # Copyright (C) 2001 Python Software Foundation, www.python.org
15
15
16 from __future__ import print_function
17
16
18 import __main__
17 import __main__
19 import glob
18 import glob
@@ -14,7 +14,6 b' These are all loaded by default by IPython.'
14 #-----------------------------------------------------------------------------
14 #-----------------------------------------------------------------------------
15 # Imports
15 # Imports
16 #-----------------------------------------------------------------------------
16 #-----------------------------------------------------------------------------
17 from __future__ import print_function
18
17
19 # Stdlib imports
18 # Stdlib imports
20 import glob
19 import glob
@@ -18,7 +18,6 b' Authors:'
18 #-----------------------------------------------------------------------------
18 #-----------------------------------------------------------------------------
19 # Imports
19 # Imports
20 #-----------------------------------------------------------------------------
20 #-----------------------------------------------------------------------------
21 from __future__ import print_function
22
21
23 import os
22 import os
24 import sys
23 import sys
@@ -24,7 +24,6 b' http://www.python.org/2.2.3/license.html"""'
24 #
24 #
25 #
25 #
26 #*****************************************************************************
26 #*****************************************************************************
27 from __future__ import print_function
28
27
29 import bdb
28 import bdb
30 import functools
29 import functools
@@ -604,22 +603,21 b' class Pdb(OldPdb, object):'
604 ('Globals', self.curframe.f_globals)]
603 ('Globals', self.curframe.f_globals)]
605 self.shell.find_line_magic('psource')(arg, namespaces=namespaces)
604 self.shell.find_line_magic('psource')(arg, namespaces=namespaces)
606
605
607 if sys.version_info > (3, ):
606 def do_where(self, arg):
608 def do_where(self, arg):
607 """w(here)
609 """w(here)
608 Print a stack trace, with the most recent frame at the bottom.
610 Print a stack trace, with the most recent frame at the bottom.
609 An arrow indicates the "current frame", which determines the
611 An arrow indicates the "current frame", which determines the
610 context of most commands. 'bt' is an alias for this command.
612 context of most commands. 'bt' is an alias for this command.
611
613
612 Take a number as argument as an (optional) number of context line to
614 Take a number as argument as an (optional) number of context line to
613 print"""
615 print"""
614 if arg:
616 if arg:
615 context = int(arg)
617 context = int(arg)
616 self.print_stack_trace(context)
618 self.print_stack_trace(context)
617 else:
619 else:
618 self.print_stack_trace()
620 self.print_stack_trace()
621
619
622 do_w = do_where
620 do_w = do_where
623
621
624
622
625 def set_trace(frame=None):
623 def set_trace(frame=None):
@@ -4,7 +4,6 b''
4 # Copyright (c) IPython Development Team.
4 # Copyright (c) IPython Development Team.
5 # Distributed under the terms of the Modified BSD License.
5 # Distributed under the terms of the Modified BSD License.
6
6
7 from __future__ import print_function
8
7
9 try:
8 try:
10 from base64 import encodebytes as base64_encode
9 from base64 import encodebytes as base64_encode
@@ -7,7 +7,6 b' This defines a callable class that IPython uses for `sys.displayhook`.'
7 # Copyright (c) IPython Development Team.
7 # Copyright (c) IPython Development Team.
8 # Distributed under the terms of the Modified BSD License.
8 # Distributed under the terms of the Modified BSD License.
9
9
10 from __future__ import print_function
11
10
12 import sys
11 import sys
13 import io as _io
12 import io as _io
@@ -15,7 +15,6 b' spec.'
15 # Copyright (c) IPython Development Team.
15 # Copyright (c) IPython Development Team.
16 # Distributed under the terms of the Modified BSD License.
16 # Distributed under the terms of the Modified BSD License.
17
17
18 from __future__ import print_function
19
18
20 import sys
19 import sys
21
20
@@ -12,7 +12,6 b' events and the arguments which will be passed to them.'
12
12
13 This API is experimental in IPython 2.0, and may be revised in future versions.
13 This API is experimental in IPython 2.0, and may be revised in future versions.
14 """
14 """
15 from __future__ import print_function
16
15
17 class EventManager(object):
16 class EventManager(object):
18 """Manage a collection of events and a sequence of callbacks for each.
17 """Manage a collection of events and a sequence of callbacks for each.
@@ -3,7 +3,6 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 from __future__ import print_function
7
6
8 import atexit
7 import atexit
9 import datetime
8 import datetime
@@ -4,7 +4,6 b' An application for managing IPython history.'
4
4
5 To be invoked as the `ipython history` subcommand.
5 To be invoked as the `ipython history` subcommand.
6 """
6 """
7 from __future__ import print_function
8
7
9 import os
8 import os
10 import sqlite3
9 import sqlite3
@@ -10,7 +10,6 b''
10 # the file COPYING, distributed as part of this software.
10 # the file COPYING, distributed as part of this software.
11 #-----------------------------------------------------------------------------
11 #-----------------------------------------------------------------------------
12
12
13 from __future__ import absolute_import, print_function
14
13
15 import __future__
14 import __future__
16 import abc
15 import abc
@@ -57,7 +56,7 b' from IPython.core.payload import PayloadManager'
57 from IPython.core.prefilter import PrefilterManager
56 from IPython.core.prefilter import PrefilterManager
58 from IPython.core.profiledir import ProfileDir
57 from IPython.core.profiledir import ProfileDir
59 from IPython.core.usage import default_banner
58 from IPython.core.usage import default_banner
60 from IPython.testing.skipdoctest import skip_doctest_py2, skip_doctest
59 from IPython.testing.skipdoctest import skip_doctest
61 from IPython.utils import PyColorize
60 from IPython.utils import PyColorize
62 from IPython.utils import io
61 from IPython.utils import io
63 from IPython.utils import py3compat
62 from IPython.utils import py3compat
@@ -187,10 +186,7 b' class ExecutionResult(object):'
187 raise self.error_in_exec
186 raise self.error_in_exec
188
187
189 def __repr__(self):
188 def __repr__(self):
190 if sys.version_info > (3,):
189 name = self.__class__.__qualname__
191 name = self.__class__.__qualname__
192 else:
193 name = self.__class__.__name__
194 return '<%s object at %x, execution_count=%s error_before_exec=%s error_in_exec=%s result=%s>' %\
190 return '<%s object at %x, execution_count=%s error_before_exec=%s error_in_exec=%s result=%s>' %\
195 (name, id(self), self.execution_count, self.error_before_exec, self.error_in_exec, repr(self.result))
191 (name, id(self), self.execution_count, self.error_before_exec, self.error_in_exec, repr(self.result))
196
192
@@ -1922,7 +1918,6 b' class InteractiveShell(SingletonConfigurable):'
1922 self.set_hook('complete_command', reset_completer, str_key = '%reset')
1918 self.set_hook('complete_command', reset_completer, str_key = '%reset')
1923
1919
1924
1920
1925 @skip_doctest_py2
1926 def complete(self, text, line=None, cursor_pos=None):
1921 def complete(self, text, line=None, cursor_pos=None):
1927 """Return the completed text and a list of completions.
1922 """Return the completed text and a list of completions.
1928
1923
@@ -1,6 +1,5 b''
1 """Logger class for IPython's logging facilities.
1 """Logger class for IPython's logging facilities.
2 """
2 """
3 from __future__ import print_function
4
3
5 #*****************************************************************************
4 #*****************************************************************************
6 # Copyright (C) 2001 Janko Hauser <jhauser@zscout.de> and
5 # Copyright (C) 2001 Janko Hauser <jhauser@zscout.de> and
@@ -1,7 +1,6 b''
1 # encoding: utf-8
1 # encoding: utf-8
2 """Magic functions for InteractiveShell.
2 """Magic functions for InteractiveShell.
3 """
3 """
4 from __future__ import print_function
5
4
6 #-----------------------------------------------------------------------------
5 #-----------------------------------------------------------------------------
7 # Copyright (C) 2001 Janko Hauser <jhauser@zscout.de> and
6 # Copyright (C) 2001 Janko Hauser <jhauser@zscout.de> and
@@ -1,7 +1,5 b''
1 """Implementation of magic functions that control various automatic behaviors.
1 """Implementation of magic functions that control various automatic behaviors.
2 """
2 """
3 from __future__ import print_function
4 from __future__ import absolute_import
5 #-----------------------------------------------------------------------------
3 #-----------------------------------------------------------------------------
6 # Copyright (c) 2012 The IPython Development Team.
4 # Copyright (c) 2012 The IPython Development Team.
7 #
5 #
@@ -1,7 +1,5 b''
1 """Implementation of basic magic functions."""
1 """Implementation of basic magic functions."""
2
2
3 from __future__ import print_function
4 from __future__ import absolute_import
5
3
6 import argparse
4 import argparse
7 import io
5 import io
@@ -1,7 +1,5 b''
1 """Implementation of code management magic functions.
1 """Implementation of code management magic functions.
2 """
2 """
3 from __future__ import print_function
4 from __future__ import absolute_import
5 #-----------------------------------------------------------------------------
3 #-----------------------------------------------------------------------------
6 # Copyright (c) 2012 The IPython Development Team.
4 # Copyright (c) 2012 The IPython Development Team.
7 #
5 #
@@ -1,7 +1,5 b''
1 """Implementation of configuration-related magic functions.
1 """Implementation of configuration-related magic functions.
2 """
2 """
3 from __future__ import print_function
4 from __future__ import absolute_import
5 #-----------------------------------------------------------------------------
3 #-----------------------------------------------------------------------------
6 # Copyright (c) 2012 The IPython Development Team.
4 # Copyright (c) 2012 The IPython Development Team.
7 #
5 #
@@ -4,8 +4,6 b''
4 # Copyright (c) IPython Development Team.
4 # Copyright (c) IPython Development Team.
5 # Distributed under the terms of the Modified BSD License.
5 # Distributed under the terms of the Modified BSD License.
6
6
7 from __future__ import print_function
8 from __future__ import absolute_import
9
7
10 import ast
8 import ast
11 import bdb
9 import bdb
@@ -1,6 +1,5 b''
1 """Implementation of magic functions for the extension machinery.
1 """Implementation of magic functions for the extension machinery.
2 """
2 """
3 from __future__ import print_function
4 #-----------------------------------------------------------------------------
3 #-----------------------------------------------------------------------------
5 # Copyright (c) 2012 The IPython Development Team.
4 # Copyright (c) 2012 The IPython Development Team.
6 #
5 #
@@ -11,7 +11,6 b''
11 #-----------------------------------------------------------------------------
11 #-----------------------------------------------------------------------------
12 # Imports
12 # Imports
13 #-----------------------------------------------------------------------------
13 #-----------------------------------------------------------------------------
14 from __future__ import print_function
15
14
16 # Stdlib
15 # Stdlib
17 import os
16 import os
@@ -1,6 +1,5 b''
1 """Implementation of namespace-related magic functions.
1 """Implementation of namespace-related magic functions.
2 """
2 """
3 from __future__ import print_function
4 #-----------------------------------------------------------------------------
3 #-----------------------------------------------------------------------------
5 # Copyright (c) 2012 The IPython Development Team.
4 # Copyright (c) 2012 The IPython Development Team.
6 #
5 #
@@ -3,7 +3,6 b''
3 Note: this module is named 'osm' instead of 'os' to avoid a collision with the
3 Note: this module is named 'osm' instead of 'os' to avoid a collision with the
4 builtin.
4 builtin.
5 """
5 """
6 from __future__ import print_function
7 #-----------------------------------------------------------------------------
6 #-----------------------------------------------------------------------------
8 # Copyright (c) 2012 The IPython Development Team.
7 # Copyright (c) 2012 The IPython Development Team.
9 #
8 #
@@ -1,6 +1,5 b''
1 """Implementation of magic functions for matplotlib/pylab support.
1 """Implementation of magic functions for matplotlib/pylab support.
2 """
2 """
3 from __future__ import print_function
4 #-----------------------------------------------------------------------------
3 #-----------------------------------------------------------------------------
5 # Copyright (c) 2012 The IPython Development Team.
4 # Copyright (c) 2012 The IPython Development Team.
6 #
5 #
@@ -1,5 +1,4 b''
1 """Magic functions for running cells in various scripts."""
1 """Magic functions for running cells in various scripts."""
2 from __future__ import print_function
3
2
4 # Copyright (c) IPython Development Team.
3 # Copyright (c) IPython Development Team.
5 # Distributed under the terms of the Modified BSD License.
4 # Distributed under the terms of the Modified BSD License.
@@ -10,8 +10,6 b' reference the name under which an object is being read.'
10 # Copyright (c) IPython Development Team.
10 # Copyright (c) IPython Development Team.
11 # Distributed under the terms of the Modified BSD License.
11 # Distributed under the terms of the Modified BSD License.
12
12
13 from __future__ import print_function
14
15 __all__ = ['Inspector','InspectColors']
13 __all__ = ['Inspector','InspectColors']
16
14
17 # stdlib modules
15 # stdlib modules
@@ -31,7 +29,7 b' except ImportError:'
31 # IPython's own
29 # IPython's own
32 from IPython.core import page
30 from IPython.core import page
33 from IPython.lib.pretty import pretty
31 from IPython.lib.pretty import pretty
34 from IPython.testing.skipdoctest import skip_doctest_py3
32 from IPython.testing.skipdoctest import skip_doctest
35 from IPython.utils import PyColorize
33 from IPython.utils import PyColorize
36 from IPython.utils import openpy
34 from IPython.utils import openpy
37 from IPython.utils import py3compat
35 from IPython.utils import py3compat
@@ -437,7 +435,7 b' class Inspector(Colorable):'
437 print(header,self.format(output), end=' ')
435 print(header,self.format(output), end=' ')
438
436
439 # In Python 3, all classes are new-style, so they all have __init__.
437 # In Python 3, all classes are new-style, so they all have __init__.
440 @skip_doctest_py3
438 @skip_doctest
441 def pdoc(self, obj, oname='', formatter=None):
439 def pdoc(self, obj, oname='', formatter=None):
442 """Print the docstring for any object.
440 """Print the docstring for any object.
443
441
@@ -13,7 +13,6 b' rid of that dependency, we could move it there.'
13 # Copyright (c) IPython Development Team.
13 # Copyright (c) IPython Development Team.
14 # Distributed under the terms of the Modified BSD License.
14 # Distributed under the terms of the Modified BSD License.
15
15
16 from __future__ import print_function
17
16
18 import os
17 import os
19 import re
18 import re
@@ -9,7 +9,6 b' Authors:'
9 * Min RK
9 * Min RK
10
10
11 """
11 """
12 from __future__ import print_function
13
12
14 #-----------------------------------------------------------------------------
13 #-----------------------------------------------------------------------------
15 # Copyright (C) 2008 The IPython Development Team
14 # Copyright (C) 2008 The IPython Development Team
@@ -1,6 +1,5 b''
1 # -*- coding: utf-8 -*-
1 # -*- coding: utf-8 -*-
2 """Pylab (matplotlib) support utilities."""
2 """Pylab (matplotlib) support utilities."""
3 from __future__ import print_function
4
3
5 # Copyright (c) IPython Development Team.
4 # Copyright (c) IPython Development Team.
6 # Distributed under the terms of the Modified BSD License.
5 # Distributed under the terms of the Modified BSD License.
@@ -7,9 +7,6 b' launch InteractiveShell instances, load extensions, etc.'
7 # Copyright (c) IPython Development Team.
7 # Copyright (c) IPython Development Team.
8 # Distributed under the terms of the Modified BSD License.
8 # Distributed under the terms of the Modified BSD License.
9
9
10 from __future__ import absolute_import
11 from __future__ import print_function
12
13 import glob
10 import glob
14 import os
11 import os
15 import sys
12 import sys
@@ -1,5 +1,4 b''
1 # coding: iso-8859-5
1 # coding: iso-8859-5
2 # (Unlikely to be the default encoding for most testers.)
2 # (Unlikely to be the default encoding for most testers.)
3 # ������������������� <- Cyrillic characters
3 # ������������������� <- Cyrillic characters
4 from __future__ import unicode_literals
5 u = '����'
4 u = '����'
@@ -1,3 +1,2 b''
1 from __future__ import print_function
2 import sys
1 import sys
3 print(sys.argv[1:])
2 print(sys.argv[1:])
@@ -12,7 +12,6 b' This script is meant to be called by other parts of the test suite that call it'
12 via %run as if it were executed interactively by the user. As of 2011-05-29,
12 via %run as if it were executed interactively by the user. As of 2011-05-29,
13 test_run.py calls it.
13 test_run.py calls it.
14 """
14 """
15 from __future__ import print_function
16
15
17 #-----------------------------------------------------------------------------
16 #-----------------------------------------------------------------------------
18 # Module imports
17 # Module imports
@@ -2,7 +2,6 b''
2
2
3 See test_run for details."""
3 See test_run for details."""
4
4
5 from __future__ import print_function
6
5
7 import sys
6 import sys
8
7
@@ -12,7 +12,6 b''
12 #-----------------------------------------------------------------------------
12 #-----------------------------------------------------------------------------
13 # Imports
13 # Imports
14 #-----------------------------------------------------------------------------
14 #-----------------------------------------------------------------------------
15 from __future__ import print_function
16
15
17 # Stdlib imports
16 # Stdlib imports
18 import linecache
17 import linecache
@@ -155,7 +155,6 b' def test_latex_completions():'
155
155
156
156
157
157
158 @dec.onlyif(sys.version_info[0] >= 3, 'This test only apply on python3')
159 def test_back_latex_completion():
158 def test_back_latex_completion():
160 ip = get_ipython()
159 ip = get_ipython()
161
160
@@ -164,7 +163,6 b' def test_back_latex_completion():'
164 nt.assert_equal(len(matches), 1)
163 nt.assert_equal(len(matches), 1)
165 nt.assert_equal(matches[0], '\\beta')
164 nt.assert_equal(matches[0], '\\beta')
166
165
167 @dec.onlyif(sys.version_info[0] >= 3, 'This test only apply on python3')
168 def test_back_unicode_completion():
166 def test_back_unicode_completion():
169 ip = get_ipython()
167 ip = get_ipython()
170
168
@@ -173,7 +171,6 b' def test_back_unicode_completion():'
173 nt.assert_equal(matches[0], '\\ROMAN NUMERAL FIVE')
171 nt.assert_equal(matches[0], '\\ROMAN NUMERAL FIVE')
174
172
175
173
176 @dec.onlyif(sys.version_info[0] >= 3, 'This test only apply on python3')
177 def test_forward_unicode_completion():
174 def test_forward_unicode_completion():
178 ip = get_ipython()
175 ip = get_ipython()
179
176
@@ -181,7 +178,6 b' def test_forward_unicode_completion():'
181 nt.assert_equal(len(matches), 1)
178 nt.assert_equal(len(matches), 1)
182 nt.assert_equal(matches[0], 'Ⅴ')
179 nt.assert_equal(matches[0], 'Ⅴ')
183
180
184 @dec.onlyif(sys.version_info[0] >= 3, 'This test only apply on python3')
185 @dec.knownfailureif(sys.platform == 'win32', 'Fails if there is a C:\\j... path')
181 @dec.knownfailureif(sys.platform == 'win32', 'Fails if there is a C:\\j... path')
186 def test_no_ascii_back_completion():
182 def test_no_ascii_back_completion():
187 ip = get_ipython()
183 ip = get_ipython()
@@ -588,7 +584,6 b' def test_dict_key_completion_contexts():'
588
584
589
585
590
586
591 @dec.onlyif(sys.version_info[0] >= 3, 'This test only applies in Py>=3')
592 def test_dict_key_completion_bytes():
587 def test_dict_key_completion_bytes():
593 """Test handling of bytes in dict key completion"""
588 """Test handling of bytes in dict key completion"""
594 ip = get_ipython()
589 ip = get_ipython()
@@ -618,68 +613,6 b' def test_dict_key_completion_bytes():'
618 nt.assert_not_in("abd", matches)
613 nt.assert_not_in("abd", matches)
619
614
620
615
621 @dec.onlyif(sys.version_info[0] < 3, 'This test only applies in Py<3')
622 def test_dict_key_completion_unicode_py2():
623 """Test handling of unicode in dict key completion"""
624 ip = get_ipython()
625 complete = ip.Completer.complete
626
627 ip.user_ns['d'] = {u'abc': None,
628 u'a\u05d0b': None}
629
630 _, matches = complete(line_buffer="d[")
631 nt.assert_in("u'abc'", matches)
632 nt.assert_in("u'a\\u05d0b'", matches)
633
634 _, matches = complete(line_buffer="d['a")
635 nt.assert_in("abc", matches)
636 nt.assert_not_in("a\\u05d0b", matches)
637
638 _, matches = complete(line_buffer="d[u'a")
639 nt.assert_in("abc", matches)
640 nt.assert_in("a\\u05d0b", matches)
641
642 _, matches = complete(line_buffer="d[U'a")
643 nt.assert_in("abc", matches)
644 nt.assert_in("a\\u05d0b", matches)
645
646 # query using escape
647 if sys.platform != 'win32':
648 # Known failure on Windows
649 _, matches = complete(line_buffer=u"d[u'a\\u05d0")
650 nt.assert_in("u05d0b", matches) # tokenized after \\
651
652 # query using character
653 _, matches = complete(line_buffer=u"d[u'a\u05d0")
654 nt.assert_in(u"a\u05d0b", matches)
655
656 with greedy_completion():
657 _, matches = complete(line_buffer="d[")
658 nt.assert_in("d[u'abc']", matches)
659 nt.assert_in("d[u'a\\u05d0b']", matches)
660
661 _, matches = complete(line_buffer="d['a")
662 nt.assert_in("d['abc']", matches)
663 nt.assert_not_in("d[u'a\\u05d0b']", matches)
664
665 _, matches = complete(line_buffer="d[u'a")
666 nt.assert_in("d[u'abc']", matches)
667 nt.assert_in("d[u'a\\u05d0b']", matches)
668
669 _, matches = complete(line_buffer="d[U'a")
670 nt.assert_in("d[U'abc']", matches)
671 nt.assert_in("d[U'a\\u05d0b']", matches)
672
673 # query using escape
674 _, matches = complete(line_buffer=u"d[u'a\\u05d0")
675 nt.assert_in("d[u'a\\u05d0b']", matches) # tokenized after \\
676
677 # query using character
678 _, matches = complete(line_buffer=u"d[u'a\u05d0")
679 nt.assert_in(u"d[u'a\u05d0b']", matches)
680
681
682 @dec.onlyif(sys.version_info[0] >= 3, 'This test only applies in Py>=3')
683 def test_dict_key_completion_unicode_py3():
616 def test_dict_key_completion_unicode_py3():
684 """Test handling of unicode in dict key completion"""
617 """Test handling of unicode in dict key completion"""
685 ip = get_ipython()
618 ip = get_ipython()
@@ -2,7 +2,6 b''
2 """Tests for completerlib.
2 """Tests for completerlib.
3
3
4 """
4 """
5 from __future__ import absolute_import
6
5
7 #-----------------------------------------------------------------------------
6 #-----------------------------------------------------------------------------
8 # Imports
7 # Imports
@@ -1,6 +1,5 b''
1 """Tests for debugging machinery.
1 """Tests for debugging machinery.
2 """
2 """
3 from __future__ import print_function
4
3
5 # Copyright (c) IPython Development Team.
4 # Copyright (c) IPython Development Team.
6 # Distributed under the terms of the Modified BSD License.
5 # Distributed under the terms of the Modified BSD License.
@@ -1,7 +1,6 b''
1 # -*- coding: utf-8 -*-
1 # -*- coding: utf-8 -*-
2 """Tests for CommandChainDispatcher."""
2 """Tests for CommandChainDispatcher."""
3
3
4 from __future__ import absolute_import
5
4
6 #-----------------------------------------------------------------------------
5 #-----------------------------------------------------------------------------
7 # Imports
6 # Imports
@@ -1,7 +1,6 b''
1 # -*- coding: utf-8 -*-
1 # -*- coding: utf-8 -*-
2 """Tests for the inputsplitter module."""
2 """Tests for the inputsplitter module."""
3
3
4 from __future__ import print_function
5
4
6 # Copyright (c) IPython Development Team.
5 # Copyright (c) IPython Development Team.
7 # Distributed under the terms of the Modified BSD License.
6 # Distributed under the terms of the Modified BSD License.
@@ -143,26 +143,14 b' class InteractiveShellTestCase(unittest.TestCase):'
143
143
144 def test_future_flags(self):
144 def test_future_flags(self):
145 """Check that future flags are used for parsing code (gh-777)"""
145 """Check that future flags are used for parsing code (gh-777)"""
146 ip.run_cell('from __future__ import print_function')
146 ip.run_cell('from __future__ import barry_as_FLUFL')
147 try:
147 try:
148 ip.run_cell('prfunc_return_val = print(1,2, sep=" ")')
148 ip.run_cell('prfunc_return_val = 1 <> 2')
149 assert 'prfunc_return_val' in ip.user_ns
149 assert 'prfunc_return_val' in ip.user_ns
150 finally:
150 finally:
151 # Reset compiler flags so we don't mess up other tests.
151 # Reset compiler flags so we don't mess up other tests.
152 ip.compile.reset_compiler_flags()
152 ip.compile.reset_compiler_flags()
153
153
154 def test_future_unicode(self):
155 """Check that unicode_literals is imported from __future__ (gh #786)"""
156 try:
157 ip.run_cell(u'byte_str = "a"')
158 assert isinstance(ip.user_ns['byte_str'], str) # string literals are byte strings by default
159 ip.run_cell('from __future__ import unicode_literals')
160 ip.run_cell(u'unicode_str = "a"')
161 assert isinstance(ip.user_ns['unicode_str'], unicode_type) # strings literals are now unicode
162 finally:
163 # Reset compiler flags so we don't mess up other tests.
164 ip.compile.reset_compiler_flags()
165
166 def test_can_pickle(self):
154 def test_can_pickle(self):
167 "Can we pickle objects defined interactively (GH-29)"
155 "Can we pickle objects defined interactively (GH-29)"
168 ip = get_ipython()
156 ip = get_ipython()
@@ -338,19 +326,6 b' class InteractiveShellTestCase(unittest.TestCase):'
338 finally:
326 finally:
339 trap.hook = save_hook
327 trap.hook = save_hook
340
328
341 @skipif(sys.version_info[0] >= 3, "softspace removed in py3")
342 def test_print_softspace(self):
343 """Verify that softspace is handled correctly when executing multiple
344 statements.
345
346 In [1]: print 1; print 2
347 1
348 2
349
350 In [2]: print 1,; print 2
351 1 2
352 """
353
354 def test_ofind_line_magic(self):
329 def test_ofind_line_magic(self):
355 from IPython.core.magic import register_line_magic
330 from IPython.core.magic import register_line_magic
356
331
@@ -466,22 +441,6 b' class InteractiveShellTestCase(unittest.TestCase):'
466 # Reset the custom exception hook
441 # Reset the custom exception hook
467 ip.set_custom_exc((), None)
442 ip.set_custom_exc((), None)
468
443
469 @skipif(sys.version_info[0] >= 3, "no differences with __future__ in py3")
470 def test_future_environment(self):
471 "Can we run code with & without the shell's __future__ imports?"
472 ip.run_cell("from __future__ import division")
473 ip.run_cell("a = 1/2", shell_futures=True)
474 self.assertEqual(ip.user_ns['a'], 0.5)
475 ip.run_cell("b = 1/2", shell_futures=False)
476 self.assertEqual(ip.user_ns['b'], 0)
477
478 ip.compile.reset_compiler_flags()
479 # This shouldn't leak to the shell's compiler
480 ip.run_cell("from __future__ import division \nc=1/2", shell_futures=False)
481 self.assertEqual(ip.user_ns['c'], 0.5)
482 ip.run_cell("d = 1/2", shell_futures=True)
483 self.assertEqual(ip.user_ns['d'], 0)
484
485 def test_mktempfile(self):
444 def test_mktempfile(self):
486 filename = ip.mktempfile()
445 filename = ip.mktempfile()
487 # Check that we can open the file again on Windows
446 # Check that we can open the file again on Windows
@@ -509,10 +468,7 b' class InteractiveShellTestCase(unittest.TestCase):'
509 raise DerivedInterrupt("foo")
468 raise DerivedInterrupt("foo")
510 except KeyboardInterrupt:
469 except KeyboardInterrupt:
511 msg = ip.get_exception_only()
470 msg = ip.get_exception_only()
512 if sys.version_info[0] <= 2:
471 self.assertEqual(msg, 'IPython.core.tests.test_interactiveshell.DerivedInterrupt: foo\n')
513 self.assertEqual(msg, 'DerivedInterrupt: foo\n')
514 else:
515 self.assertEqual(msg, 'IPython.core.tests.test_interactiveshell.DerivedInterrupt: foo\n')
516
472
517 def test_inspect_text(self):
473 def test_inspect_text(self):
518 ip.run_cell('a = 5')
474 ip.run_cell('a = 5')
@@ -3,7 +3,6 b''
3
3
4 Needs to be run by nose (to make ipython session available).
4 Needs to be run by nose (to make ipython session available).
5 """
5 """
6 from __future__ import absolute_import
7
6
8 import io
7 import io
9 import os
8 import os
@@ -377,18 +376,6 b' def test_time3():'
377 "run = 0\n"
376 "run = 0\n"
378 "run += 1")
377 "run += 1")
379
378
380 @dec.skipif(sys.version_info[0] >= 3, "no differences with __future__ in py3")
381 def test_time_futures():
382 "Test %time with __future__ environments"
383 ip = get_ipython()
384 ip.autocall = 0
385 ip.run_cell("from __future__ import division")
386 with tt.AssertPrints('0.25'):
387 ip.run_line_magic('time', 'print(1/4)')
388 ip.compile.reset_compiler_flags()
389 with tt.AssertNotPrints('0.25'):
390 ip.run_line_magic('time', 'print(1/4)')
391
392 def test_doctest_mode():
379 def test_doctest_mode():
393 "Toggle doctest_mode twice, it should be a no-op and run without error"
380 "Toggle doctest_mode twice, it should be a no-op and run without error"
394 _ip.magic('doctest_mode')
381 _ip.magic('doctest_mode')
@@ -573,17 +560,6 b' def test_timeit_return_quiet():'
573 res = _ip.run_line_magic('timeit', '-n1 -r1 -q -o 1')
560 res = _ip.run_line_magic('timeit', '-n1 -r1 -q -o 1')
574 assert (res is not None)
561 assert (res is not None)
575
562
576 @dec.skipif(sys.version_info[0] >= 3, "no differences with __future__ in py3")
577 def test_timeit_futures():
578 "Test %timeit with __future__ environments"
579 ip = get_ipython()
580 ip.run_cell("from __future__ import division")
581 with tt.AssertPrints('0.25'):
582 ip.run_line_magic('timeit', '-n1 -r1 print(1/4)')
583 ip.compile.reset_compiler_flags()
584 with tt.AssertNotPrints('0.25'):
585 ip.run_line_magic('timeit', '-n1 -r1 print(1/4)')
586
587 @dec.skipif(execution.profile is None)
563 @dec.skipif(execution.profile is None)
588 def test_prun_special_syntax():
564 def test_prun_special_syntax():
589 "Test %%prun with IPython special syntax"
565 "Test %%prun with IPython special syntax"
@@ -2,7 +2,6 b''
2
2
3 Needs to be run by nose (to make ipython session available).
3 Needs to be run by nose (to make ipython session available).
4 """
4 """
5 from __future__ import absolute_import
6
5
7 #-----------------------------------------------------------------------------
6 #-----------------------------------------------------------------------------
8 # Imports
7 # Imports
@@ -57,8 +56,6 b' def check_cpaste(code, should_fail=False):'
57 finally:
56 finally:
58 sys.stdin = stdin_save
57 sys.stdin = stdin_save
59
58
60 PY31 = sys.version_info[:2] == (3,1)
61
62 def test_cpaste():
59 def test_cpaste():
63 """Test cpaste magic"""
60 """Test cpaste magic"""
64
61
@@ -77,13 +74,8 b' def test_cpaste():'
77 ],
74 ],
78
75
79 'fail': ["1 + runf()",
76 'fail': ["1 + runf()",
77 "++ runf()",
80 ]}
78 ]}
81
82 # I don't know why this is failing specifically on Python 3.1. I've
83 # checked it manually interactively, but we don't care enough about 3.1
84 # to spend time fiddling with the tests, so we just skip it.
85 if not PY31:
86 tests['fail'].append("++ runf()")
87
79
88 ip.user_ns['runf'] = runf
80 ip.user_ns['runf'] = runf
89
81
@@ -4,7 +4,6 b''
4 # Copyright (c) IPython Development Team.
4 # Copyright (c) IPython Development Team.
5 # Distributed under the terms of the Modified BSD License.
5 # Distributed under the terms of the Modified BSD License.
6
6
7 from __future__ import print_function
8
7
9 import os
8 import os
10 import re
9 import re
@@ -40,7 +39,7 b' ip = get_ipython()'
40 # defined, if any code is inserted above, the following line will need to be
39 # defined, if any code is inserted above, the following line will need to be
41 # updated. Do NOT insert any whitespace between the next line and the function
40 # updated. Do NOT insert any whitespace between the next line and the function
42 # definition below.
41 # definition below.
43 THIS_LINE_NUMBER = 43 # Put here the actual number of this line
42 THIS_LINE_NUMBER = 42 # Put here the actual number of this line
44
43
45 from unittest import TestCase
44 from unittest import TestCase
46
45
@@ -275,8 +274,7 b' def test_info():'
275 nt.assert_equal(i['type_name'], 'type')
274 nt.assert_equal(i['type_name'], 'type')
276 expted_class = str(type(type)) # <class 'type'> (Python 3) or <type 'type'>
275 expted_class = str(type(type)) # <class 'type'> (Python 3) or <type 'type'>
277 nt.assert_equal(i['base_class'], expted_class)
276 nt.assert_equal(i['base_class'], expted_class)
278 if sys.version_info > (3,):
277 nt.assert_regex(i['string_form'], "<class 'IPython.core.tests.test_oinspect.Call'( at 0x[0-9a-f]{1,9})?>")
279 nt.assert_regex(i['string_form'], "<class 'IPython.core.tests.test_oinspect.Call'( at 0x[0-9a-f]{1,9})?>")
280 fname = __file__
278 fname = __file__
281 if fname.endswith(".pyc"):
279 if fname.endswith(".pyc"):
282 fname = fname[:-1]
280 fname = fname[:-1]
@@ -15,7 +15,6 b' Authors'
15 * MinRK
15 * MinRK
16
16
17 """
17 """
18 from __future__ import absolute_import
19
18
20 #-----------------------------------------------------------------------------
19 #-----------------------------------------------------------------------------
21 # Imports
20 # Imports
@@ -4,7 +4,6 b''
4 # Copyright (c) IPython Development Team.
4 # Copyright (c) IPython Development Team.
5 # Distributed under the terms of the Modified BSD License.
5 # Distributed under the terms of the Modified BSD License.
6
6
7 from __future__ import print_function
8
7
9 from io import UnsupportedOperation, BytesIO
8 from io import UnsupportedOperation, BytesIO
10
9
@@ -11,7 +11,6 b' and we do so in a common test_magic file.'
11 # Copyright (c) IPython Development Team.
11 # Copyright (c) IPython Development Team.
12 # Distributed under the terms of the Modified BSD License.
12 # Distributed under the terms of the Modified BSD License.
13
13
14 from __future__ import absolute_import
15
14
16
15
17 import functools
16 import functools
@@ -313,44 +313,43 b' def r3o2():'
313 #----------------------------------------------------------------------------
313 #----------------------------------------------------------------------------
314
314
315 # module testing (minimal)
315 # module testing (minimal)
316 if sys.version_info > (3,):
316 def test_handlers():
317 def test_handlers():
317 def spam(c, d_e):
318 def spam(c, d_e):
318 (d, e) = d_e
319 (d, e) = d_e
319 x = c + d
320 x = c + d
320 y = c * d
321 y = c * d
321 foo(x, y)
322 foo(x, y)
322
323
323 def foo(a, b, bar=1):
324 def foo(a, b, bar=1):
324 eggs(a, b + bar)
325 eggs(a, b + bar)
325
326
326 def eggs(f, g, z=globals()):
327 def eggs(f, g, z=globals()):
327 h = f + g
328 h = f + g
328 i = f - g
329 i = f - g
329 return h / i
330 return h / i
330
331
331 buff = io.StringIO()
332 buff = io.StringIO()
332
333
333 buff.write('')
334 buff.write('')
334 buff.write('*** Before ***')
335 buff.write('*** Before ***')
335 try:
336 try:
336 buff.write(spam(1, (2, 3)))
337 buff.write(spam(1, (2, 3)))
337 except:
338 except:
338 traceback.print_exc(file=buff)
339 traceback.print_exc(file=buff)
339
340
340 handler = ColorTB(ostream=buff)
341 handler = ColorTB(ostream=buff)
341 buff.write('*** ColorTB ***')
342 buff.write('*** ColorTB ***')
342 try:
343 try:
343 buff.write(spam(1, (2, 3)))
344 buff.write(spam(1, (2, 3)))
344 except:
345 except:
345 handler(*sys.exc_info())
346 handler(*sys.exc_info())
346 buff.write('')
347 buff.write('')
347
348
348 handler = VerboseTB(ostream=buff)
349 handler = VerboseTB(ostream=buff)
349 buff.write('*** VerboseTB ***')
350 buff.write('*** VerboseTB ***')
350 try:
351 try:
351 buff.write(spam(1, (2, 3)))
352 buff.write(spam(1, (2, 3)))
352 except:
353 except:
353 handler(*sys.exc_info())
354 handler(*sys.exc_info())
354 buff.write('')
355 buff.write('')
356
355
@@ -88,9 +88,6 b' Inheritance diagram:'
88 # the file COPYING, distributed as part of this software.
88 # the file COPYING, distributed as part of this software.
89 #*****************************************************************************
89 #*****************************************************************************
90
90
91 from __future__ import absolute_import
92 from __future__ import unicode_literals
93 from __future__ import print_function
94
91
95 import dis
92 import dis
96 import inspect
93 import inspect
@@ -87,7 +87,6 b' Some of the known remaining caveats are:'
87
87
88 - C extension modules cannot be reloaded, and so cannot be autoreloaded.
88 - C extension modules cannot be reloaded, and so cannot be autoreloaded.
89 """
89 """
90 from __future__ import print_function
91
90
92 skip_doctest = True
91 skip_doctest = True
93
92
@@ -9,7 +9,6 b' To automatically restore stored variables at startup, add this to your'
9
9
10 c.StoreMagics.autorestore = True
10 c.StoreMagics.autorestore = True
11 """
11 """
12 from __future__ import print_function
13
12
14 # Copyright (c) IPython Development Team.
13 # Copyright (c) IPython Development Team.
15 # Distributed under the terms of the Modified BSD License.
14 # Distributed under the terms of the Modified BSD License.
@@ -21,7 +21,6 b' separate implementation).'
21 An example notebook is provided in our documentation illustrating interactive
21 An example notebook is provided in our documentation illustrating interactive
22 use of the system.
22 use of the system.
23 """
23 """
24 from __future__ import print_function
25
24
26 #*****************************************************************************
25 #*****************************************************************************
27 # Copyright (C) 2005-2006 Fernando Perez <fperez@colorado.edu>
26 # Copyright (C) 2005-2006 Fernando Perez <fperez@colorado.edu>
@@ -25,7 +25,6 b' A reference to the original :func:`python:reload` is stored in this module as'
25 This code is almost entirely based on knee.py, which is a Python
25 This code is almost entirely based on knee.py, which is a Python
26 re-implementation of hierarchical module import.
26 re-implementation of hierarchical module import.
27 """
27 """
28 from __future__ import print_function
29 #*****************************************************************************
28 #*****************************************************************************
30 # Copyright (C) 2001 Nathaniel Gray <n8gray@caltech.edu>
29 # Copyright (C) 2001 Nathaniel Gray <n8gray@caltech.edu>
31 #
30 #
@@ -170,7 +170,6 b' The following is a very simple example of a valid demo file.'
170 ################### END EXAMPLE DEMO <ex_demo.py> ############################
170 ################### END EXAMPLE DEMO <ex_demo.py> ############################
171 """
171 """
172
172
173 from __future__ import unicode_literals
174
173
175 #*****************************************************************************
174 #*****************************************************************************
176 # Copyright (C) 2005-2006 Fernando Perez. <Fernando.Perez@colorado.edu>
175 # Copyright (C) 2005-2006 Fernando Perez. <Fernando.Perez@colorado.edu>
@@ -179,7 +178,6 b' from __future__ import unicode_literals'
179 # the file COPYING, distributed as part of this software.
178 # the file COPYING, distributed as part of this software.
180 #
179 #
181 #*****************************************************************************
180 #*****************************************************************************
182 from __future__ import print_function
183
181
184 import os
182 import os
185 import re
183 import re
@@ -4,7 +4,6 b' They should honor the line number argument, at least.'
4
4
5 Contributions are *very* welcome.
5 Contributions are *very* welcome.
6 """
6 """
7 from __future__ import print_function
8
7
9 import os
8 import os
10 import pipes
9 import pipes
@@ -2,7 +2,6 b''
2 """
2 """
3 GLUT Inputhook support functions
3 GLUT Inputhook support functions
4 """
4 """
5 from __future__ import print_function
6
5
7 #-----------------------------------------------------------------------------
6 #-----------------------------------------------------------------------------
8 # Copyright (C) 2008-2011 The IPython Development Team
7 # Copyright (C) 2008-2011 The IPython Development Team
@@ -77,7 +77,6 b' Inheritance diagram:'
77 Portions (c) 2009 by Robert Kern.
77 Portions (c) 2009 by Robert Kern.
78 :license: BSD License.
78 :license: BSD License.
79 """
79 """
80 from __future__ import print_function
81 from contextlib import contextmanager
80 from contextlib import contextmanager
82 import sys
81 import sys
83 import types
82 import types
@@ -11,7 +11,6 b''
11 #-----------------------------------------------------------------------------
11 #-----------------------------------------------------------------------------
12 # Imports
12 # Imports
13 #-----------------------------------------------------------------------------
13 #-----------------------------------------------------------------------------
14 from __future__ import print_function
15
14
16 # Stdlib imports
15 # Stdlib imports
17 import time
16 import time
@@ -12,7 +12,6 b''
12 #-----------------------------------------------------------------------------
12 #-----------------------------------------------------------------------------
13 # Imports
13 # Imports
14 #-----------------------------------------------------------------------------
14 #-----------------------------------------------------------------------------
15 from __future__ import print_function
16 from tempfile import NamedTemporaryFile, mkdtemp
15 from tempfile import NamedTemporaryFile, mkdtemp
17 from os.path import split, join as pjoin, dirname
16 from os.path import split, join as pjoin, dirname
18
17
@@ -4,7 +4,6 b''
4 # Copyright (c) IPython Development Team.
4 # Copyright (c) IPython Development Team.
5 # Distributed under the terms of the Modified BSD License.
5 # Distributed under the terms of the Modified BSD License.
6
6
7 from __future__ import print_function
8
7
9 from collections import Counter, defaultdict, deque, OrderedDict
8 from collections import Counter, defaultdict, deque, OrderedDict
10 import types, string
9 import types, string
@@ -12,14 +11,9 b' import types, string'
12 import nose.tools as nt
11 import nose.tools as nt
13
12
14 from IPython.lib import pretty
13 from IPython.lib import pretty
15 from IPython.testing.decorators import (skip_without, py2_only, py3_only)
14 from IPython.testing.decorators import skip_without
16
17 from IPython.utils.py3compat import PY3, unicode_to_str
18
15
19 if PY3:
16 from io import StringIO
20 from io import StringIO
21 else:
22 from StringIO import StringIO
23
17
24
18
25 class MyList(object):
19 class MyList(object):
@@ -245,7 +239,7 b' def test_metaclass_repr():'
245
239
246 def test_unicode_repr():
240 def test_unicode_repr():
247 u = u"üniçodé"
241 u = u"üniçodé"
248 ustr = unicode_to_str(u)
242 ustr = u
249
243
250 class C(object):
244 class C(object):
251 def __repr__(self):
245 def __repr__(self):
@@ -276,83 +270,6 b' def test_basic_class():'
276 nt.assert_true(type_pprint_wrapper.called)
270 nt.assert_true(type_pprint_wrapper.called)
277
271
278
272
279 # This is only run on Python 2 because in Python 3 the language prevents you
280 # from setting a non-unicode value for __qualname__ on a metaclass, and it
281 # doesn't respect the descriptor protocol if you subclass unicode and implement
282 # __get__.
283 @py2_only
284 def test_fallback_to__name__on_type():
285 # Test that we correctly repr types that have non-string values for
286 # __qualname__ by falling back to __name__
287
288 class Type(object):
289 __qualname__ = 5
290
291 # Test repring of the type.
292 stream = StringIO()
293 printer = pretty.RepresentationPrinter(stream)
294
295 printer.pretty(Type)
296 printer.flush()
297 output = stream.getvalue()
298
299 # If __qualname__ is malformed, we should fall back to __name__.
300 expected = '.'.join([__name__, Type.__name__])
301 nt.assert_equal(output, expected)
302
303 # Clear stream buffer.
304 stream.buf = ''
305
306 # Test repring of an instance of the type.
307 instance = Type()
308 printer.pretty(instance)
309 printer.flush()
310 output = stream.getvalue()
311
312 # Should look like:
313 # <IPython.lib.tests.test_pretty.Type at 0x7f7658ae07d0>
314 prefix = '<' + '.'.join([__name__, Type.__name__]) + ' at 0x'
315 nt.assert_true(output.startswith(prefix))
316
317
318 @py2_only
319 def test_fail_gracefully_on_bogus__qualname__and__name__():
320 # Test that we correctly repr types that have non-string values for both
321 # __qualname__ and __name__
322
323 class Meta(type):
324 __name__ = 5
325
326 class Type(object):
327 __metaclass__ = Meta
328 __qualname__ = 5
329
330 stream = StringIO()
331 printer = pretty.RepresentationPrinter(stream)
332
333 printer.pretty(Type)
334 printer.flush()
335 output = stream.getvalue()
336
337 # If we can't find __name__ or __qualname__ just use a sentinel string.
338 expected = '.'.join([__name__, '<unknown type>'])
339 nt.assert_equal(output, expected)
340
341 # Clear stream buffer.
342 stream.buf = ''
343
344 # Test repring of an instance of the type.
345 instance = Type()
346 printer.pretty(instance)
347 printer.flush()
348 output = stream.getvalue()
349
350 # Should look like:
351 # <IPython.lib.tests.test_pretty.<unknown type> at 0x7f7658ae07d0>
352 prefix = '<' + '.'.join([__name__, '<unknown type>']) + ' at 0x'
353 nt.assert_true(output.startswith(prefix))
354
355
356 def test_collections_defaultdict():
273 def test_collections_defaultdict():
357 # Create defaultdicts with cycles
274 # Create defaultdicts with cycles
358 a = defaultdict()
275 a = defaultdict()
@@ -441,7 +358,6 b' def test_collections_counter():'
441 for obj, expected in cases:
358 for obj, expected in cases:
442 nt.assert_equal(pretty.pretty(obj), expected)
359 nt.assert_equal(pretty.pretty(obj), expected)
443
360
444 @py3_only
445 def test_mappingproxy():
361 def test_mappingproxy():
446 MP = types.MappingProxyType
362 MP = types.MappingProxyType
447 underlying_dict = {}
363 underlying_dict = {}
@@ -119,7 +119,6 b' Authors'
119 - VáclavŠmilauer <eudoxos-AT-arcig.cz>: Prompt generalizations.
119 - VáclavŠmilauer <eudoxos-AT-arcig.cz>: Prompt generalizations.
120 - Skipper Seabold, refactoring, cleanups, pure python addition
120 - Skipper Seabold, refactoring, cleanups, pure python addition
121 """
121 """
122 from __future__ import print_function
123
122
124 #-----------------------------------------------------------------------------
123 #-----------------------------------------------------------------------------
125 # Imports
124 # Imports
@@ -5,8 +5,6 b' An embedded IPython shell.'
5 # Copyright (c) IPython Development Team.
5 # Copyright (c) IPython Development Team.
6 # Distributed under the terms of the Modified BSD License.
6 # Distributed under the terms of the Modified BSD License.
7
7
8 from __future__ import with_statement
9 from __future__ import print_function
10
8
11 import sys
9 import sys
12 import warnings
10 import warnings
@@ -1,5 +1,4 b''
1 """IPython terminal interface using prompt_toolkit"""
1 """IPython terminal interface using prompt_toolkit"""
2 from __future__ import print_function
3
2
4 import os
3 import os
5 import sys
4 import sys
@@ -8,8 +8,6 b' line :command:`ipython` program.'
8 # Copyright (c) IPython Development Team.
8 # Copyright (c) IPython Development Team.
9 # Distributed under the terms of the Modified BSD License.
9 # Distributed under the terms of the Modified BSD License.
10
10
11 from __future__ import absolute_import
12 from __future__ import print_function
13
11
14 import logging
12 import logging
15 import os
13 import os
@@ -3,7 +3,6 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 from __future__ import print_function
7
6
8 from logging import error
7 from logging import error
9 import os
8 import os
@@ -1,5 +1,4 b''
1 """Terminal input and output prompts."""
1 """Terminal input and output prompts."""
2 from __future__ import print_function
3
2
4 from pygments.token import Token
3 from pygments.token import Token
5 import sys
4 import sys
@@ -1,6 +1,5 b''
1 """GLUT Input hook for interactive use with prompt_toolkit
1 """GLUT Input hook for interactive use with prompt_toolkit
2 """
2 """
3 from __future__ import print_function
4
3
5
4
6 # GLUT is quite an old library and it is difficult to ensure proper
5 # GLUT is quite an old library and it is difficult to ensure proper
@@ -35,7 +35,6 b' PyGTK input hook for prompt_toolkit.'
35 Listens on the pipe prompt_toolkit sets up for a notification that it should
35 Listens on the pipe prompt_toolkit sets up for a notification that it should
36 return control to the terminal event loop.
36 return control to the terminal event loop.
37 """
37 """
38 from __future__ import absolute_import
39
38
40 import gtk, gobject
39 import gtk, gobject
41
40
@@ -1,6 +1,5 b''
1 """Enable pyglet to be used interacively with prompt_toolkit
1 """Enable pyglet to be used interacively with prompt_toolkit
2 """
2 """
3 from __future__ import absolute_import
4
3
5 import os
4 import os
6 import sys
5 import sys
@@ -1,6 +1,5 b''
1 """Enable wxPython to be used interacively in prompt_toolkit
1 """Enable wxPython to be used interacively in prompt_toolkit
2 """
2 """
3 from __future__ import absolute_import
4
3
5 import sys
4 import sys
6 import signal
5 import signal
@@ -24,7 +24,6 b' from IPython.testing.decorators import skip_win32'
24
24
25
25
26 _sample_embed = b"""
26 _sample_embed = b"""
27 from __future__ import print_function
28 import IPython
27 import IPython
29
28
30 a = 3
29 a = 3
@@ -74,8 +73,6 b' def test_nest_embed():'
74 child = pexpect.spawn(sys.executable, ['-m', 'IPython', '--colors=nocolor'],
73 child = pexpect.spawn(sys.executable, ['-m', 'IPython', '--colors=nocolor'],
75 env=env)
74 env=env)
76 child.expect(ipy_prompt)
75 child.expect(ipy_prompt)
77 child.sendline("from __future__ import print_function")
78 child.expect(ipy_prompt)
79 child.sendline("import IPython")
76 child.sendline("import IPython")
80 child.expect(ipy_prompt)
77 child.expect(ipy_prompt)
81 child.sendline("ip0 = get_ipython()")
78 child.sendline("ip0 = get_ipython()")
@@ -334,12 +334,6 b" skipif_not_sympy = skip_without('sympy')"
334
334
335 skip_known_failure = knownfailureif(True,'This test is known to fail')
335 skip_known_failure = knownfailureif(True,'This test is known to fail')
336
336
337 known_failure_py3 = knownfailureif(sys.version_info[0] >= 3,
338 'This test is known to fail on Python 3.')
339
340 py2_only = skipif(PY3, "This test only runs on Python 2.")
341 py3_only = skipif(PY2, "This test only runs on Python 3.")
342
343 # A null 'decorator', useful to make more readable code that needs to pick
337 # A null 'decorator', useful to make more readable code that needs to pick
344 # between different decorators based on OS or other conditions
338 # between different decorators based on OS or other conditions
345 null_deco = lambda f: f
339 null_deco = lambda f: f
@@ -5,8 +5,6 b" modifications IPython makes to system behavior don't send the doctest machinery"
5 into a fit. This code should be considered a gross hack, but it gets the job
5 into a fit. This code should be considered a gross hack, but it gets the job
6 done.
6 done.
7 """
7 """
8 from __future__ import absolute_import
9 from __future__ import print_function
10
8
11 # Copyright (c) IPython Development Team.
9 # Copyright (c) IPython Development Team.
12 # Distributed under the terms of the Modified BSD License.
10 # Distributed under the terms of the Modified BSD License.
@@ -17,7 +17,6 b' itself from the command line. There are two ways of running this script:'
17 # Copyright (c) IPython Development Team.
17 # Copyright (c) IPython Development Team.
18 # Distributed under the terms of the Modified BSD License.
18 # Distributed under the terms of the Modified BSD License.
19
19
20 from __future__ import print_function
21
20
22 import glob
21 import glob
23 from io import BytesIO
22 from io import BytesIO
@@ -45,8 +44,7 b' pjoin = path.join'
45
44
46 # Enable printing all warnings raise by IPython's modules
45 # Enable printing all warnings raise by IPython's modules
47 warnings.filterwarnings('ignore', message='.*Matplotlib is building the font cache.*', category=UserWarning, module='.*')
46 warnings.filterwarnings('ignore', message='.*Matplotlib is building the font cache.*', category=UserWarning, module='.*')
48 if sys.version_info > (3,0):
47 warnings.filterwarnings('error', message='.*', category=ResourceWarning, module='.*')
49 warnings.filterwarnings('error', message='.*', category=ResourceWarning, module='.*')
50 warnings.filterwarnings('error', message=".*{'config': True}.*", category=DeprecationWarning, module='IPy.*')
48 warnings.filterwarnings('error', message=".*{'config': True}.*", category=DeprecationWarning, module='IPy.*')
51 warnings.filterwarnings('default', message='.*', category=Warning, module='IPy.*')
49 warnings.filterwarnings('default', message='.*', category=Warning, module='IPy.*')
52
50
@@ -9,7 +9,6 b' test suite.'
9 # Copyright (c) IPython Development Team.
9 # Copyright (c) IPython Development Team.
10 # Distributed under the terms of the Modified BSD License.
10 # Distributed under the terms of the Modified BSD License.
11
11
12 from __future__ import print_function
13
12
14 import argparse
13 import argparse
15 import json
14 import json
@@ -22,7 +22,6 b' Authors'
22 - Fernando Perez <Fernando.Perez@berkeley.edu>
22 - Fernando Perez <Fernando.Perez@berkeley.edu>
23 """
23 """
24
24
25 from __future__ import absolute_import
26
25
27 #-----------------------------------------------------------------------------
26 #-----------------------------------------------------------------------------
28 # Copyright (C) 2009-2011 The IPython Development Team
27 # Copyright (C) 2009-2011 The IPython Development Team
@@ -3,7 +3,6 b''
3 This file just contains doctests both using plain python and IPython prompts.
3 This file just contains doctests both using plain python and IPython prompts.
4 All tests should be loaded by nose.
4 All tests should be loaded by nose.
5 """
5 """
6 from __future__ import print_function
7
6
8 def pyfunc():
7 def pyfunc():
9 """Some pure python tests...
8 """Some pure python tests...
@@ -1,7 +1,6 b''
1 #!/usr/bin/env python
1 #!/usr/bin/env python
2 """Nose-based test runner.
2 """Nose-based test runner.
3 """
3 """
4 from __future__ import print_function
5
4
6 from nose.core import main
5 from nose.core import main
7 from nose.plugins.builtin import plugins
6 from nose.plugins.builtin import plugins
@@ -2,7 +2,6 b''
2
2
3 This is used by a companion test case.
3 This is used by a companion test case.
4 """
4 """
5 from __future__ import print_function
6
5
7 import gc
6 import gc
8
7
@@ -3,7 +3,6 b''
3 This file just contains doctests both using plain python and IPython prompts.
3 This file just contains doctests both using plain python and IPython prompts.
4 All tests should be loaded by nose.
4 All tests should be loaded by nose.
5 """
5 """
6 from __future__ import print_function
7
6
8 def pyfunc():
7 def pyfunc():
9 """Some pure python tests...
8 """Some pure python tests...
@@ -1,3 +1,2 b''
1 from __future__ import print_function
2 x = 1
1 x = 1
3 print('x is:',x)
2 print('x is:',x)
@@ -1,26 +1,13 b''
1 """Decorators marks that a doctest should be skipped, for both python 2 and 3.
1 """Decorators marks that a doctest should be skipped.
2
2
3 The IPython.testing.decorators module triggers various extra imports, including
3 The IPython.testing.decorators module triggers various extra imports, including
4 numpy and sympy if they're present. Since this decorator is used in core parts
4 numpy and sympy if they're present. Since this decorator is used in core parts
5 of IPython, it's in a separate module so that running IPython doesn't trigger
5 of IPython, it's in a separate module so that running IPython doesn't trigger
6 those imports."""
6 those imports."""
7
7
8 #-----------------------------------------------------------------------------
8 # Copyright (C) IPython Development Team
9 # Copyright (C) 2009-2011 The IPython Development Team
9 # Distributed under the terms of the Modified BSD License.
10 #
11 # Distributed under the terms of the BSD License. The full license is in
12 # the file COPYING, distributed as part of this software.
13 #-----------------------------------------------------------------------------
14
10
15 #-----------------------------------------------------------------------------
16 # Imports
17 #-----------------------------------------------------------------------------
18
19 import sys
20
21 #-----------------------------------------------------------------------------
22 # Decorators
23 #-----------------------------------------------------------------------------
24
11
25 def skip_doctest(f):
12 def skip_doctest(f):
26 """Decorator - mark a function or method for skipping its doctest.
13 """Decorator - mark a function or method for skipping its doctest.
@@ -30,14 +17,3 b' def skip_doctest(f):'
30 etc."""
17 etc."""
31 f.skip_doctest = True
18 f.skip_doctest = True
32 return f
19 return f
33
34
35 def skip_doctest_py3(f):
36 """Decorator - skip the doctest under Python 3."""
37 f.skip_doctest = (sys.version_info[0] >= 3)
38 return f
39
40 def skip_doctest_py2(f):
41 """Decorator - skip the doctest under Python 3."""
42 f.skip_doctest = (sys.version_info[0] < 3)
43 return f
@@ -1,6 +1,5 b''
1 """Tests for the decorators we've created for IPython.
1 """Tests for the decorators we've created for IPython.
2 """
2 """
3 from __future__ import print_function
4
3
5 # Module imports
4 # Module imports
6 # Std lib
5 # Std lib
@@ -13,8 +13,6 b' Tests for testing.tools'
13 #-----------------------------------------------------------------------------
13 #-----------------------------------------------------------------------------
14 # Imports
14 # Imports
15 #-----------------------------------------------------------------------------
15 #-----------------------------------------------------------------------------
16 from __future__ import with_statement
17 from __future__ import print_function
18
16
19 import os
17 import os
20 import unittest
18 import unittest
@@ -110,8 +108,7 b' class Test_ipexec_validate(unittest.TestCase, tt.TempFileMixin):'
110 def test_exception_path(self):
108 def test_exception_path(self):
111 """Test exception path in exception_validate.
109 """Test exception path in exception_validate.
112 """
110 """
113 self.mktmp("from __future__ import print_function\n"
111 self.mktmp("import sys\n"
114 "import sys\n"
115 "print('A')\n"
112 "print('A')\n"
116 "print('B')\n"
113 "print('B')\n"
117 "print('C', file=sys.stderr)\n"
114 "print('C', file=sys.stderr)\n"
@@ -123,8 +120,7 b' class Test_ipexec_validate(unittest.TestCase, tt.TempFileMixin):'
123 def test_exception_path2(self):
120 def test_exception_path2(self):
124 """Test exception path in exception_validate, expecting windows line endings.
121 """Test exception path in exception_validate, expecting windows line endings.
125 """
122 """
126 self.mktmp("from __future__ import print_function\n"
123 self.mktmp("import sys\n"
127 "import sys\n"
128 "print('A')\n"
124 "print('A')\n"
129 "print('B')\n"
125 "print('B')\n"
130 "print('C', file=sys.stderr)\n"
126 "print('C', file=sys.stderr)\n"
@@ -5,7 +5,6 b' Authors'
5 - Fernando Perez <Fernando.Perez@berkeley.edu>
5 - Fernando Perez <Fernando.Perez@berkeley.edu>
6 """
6 """
7
7
8 from __future__ import absolute_import
9
8
10 #-----------------------------------------------------------------------------
9 #-----------------------------------------------------------------------------
11 # Copyright (C) 2009 The IPython Development Team
10 # Copyright (C) 2009 The IPython Development Team
@@ -28,9 +28,6 b' It shows how to use the built-in keyword, token and tokenize modules to'
28 scan Python source code and re-emit it with no changes to its original
28 scan Python source code and re-emit it with no changes to its original
29 formatting (which is the hard part).
29 formatting (which is the hard part).
30 """
30 """
31 from __future__ import print_function
32 from __future__ import absolute_import
33 from __future__ import unicode_literals
34
31
35 __all__ = ['ANSICodeColors','Parser']
32 __all__ = ['ANSICodeColors','Parser']
36
33
@@ -13,7 +13,6 b' This file is only meant to be imported by process.py, not by end-users.'
13 #-----------------------------------------------------------------------------
13 #-----------------------------------------------------------------------------
14 # Imports
14 # Imports
15 #-----------------------------------------------------------------------------
15 #-----------------------------------------------------------------------------
16 from __future__ import print_function
17
16
18 # Stdlib
17 # Stdlib
19 import errno
18 import errno
@@ -13,7 +13,6 b' This file is only meant to be imported by process.py, not by end-users.'
13 #-----------------------------------------------------------------------------
13 #-----------------------------------------------------------------------------
14 # Imports
14 # Imports
15 #-----------------------------------------------------------------------------
15 #-----------------------------------------------------------------------------
16 from __future__ import print_function
17
16
18 # stdlib
17 # stdlib
19 import os
18 import os
@@ -10,7 +10,6 b' This file is meant to be used by process.py'
10 # the file COPYING, distributed as part of this software.
10 # the file COPYING, distributed as part of this software.
11 #-----------------------------------------------------------------------------
11 #-----------------------------------------------------------------------------
12
12
13 from __future__ import print_function
14
13
15 # stdlib
14 # stdlib
16 import os, sys, threading
15 import os, sys, threading
@@ -16,7 +16,6 b' modified to be compatible with Python 2.7 and 3.2+.'
16 # the file COPYING, distributed as part of this software.
16 # the file COPYING, distributed as part of this software.
17 #-----------------------------------------------------------------------------
17 #-----------------------------------------------------------------------------
18
18
19 from __future__ import absolute_import, division, print_function
20 import itertools
19 import itertools
21 import functools
20 import functools
22 import re
21 import re
@@ -4,7 +4,6 b''
4 # Copyright (c) IPython Development Team.
4 # Copyright (c) IPython Development Team.
5 # Distributed under the terms of the Modified BSD License.
5 # Distributed under the terms of the Modified BSD License.
6
6
7 from __future__ import print_function, absolute_import
8
7
9 import sys
8 import sys
10
9
@@ -4,7 +4,6 b''
4 # Distributed under the terms of the BSD License. The full license is in
4 # Distributed under the terms of the BSD License. The full license is in
5 # the file COPYING, distributed as part of this software.
5 # the file COPYING, distributed as part of this software.
6 #*****************************************************************************
6 #*****************************************************************************
7 from __future__ import absolute_import
8
7
9 """
8 """
10 Color managing related utilities
9 Color managing related utilities
@@ -1,4 +1,3 b''
1 from __future__ import absolute_import
2
1
3 from warnings import warn
2 from warnings import warn
4
3
@@ -2,7 +2,6 b''
2 """
2 """
3 Utilities for working with stack frames.
3 Utilities for working with stack frames.
4 """
4 """
5 from __future__ import print_function
6
5
7 #-----------------------------------------------------------------------------
6 #-----------------------------------------------------------------------------
8 # Copyright (C) 2008-2011 The IPython Development Team
7 # Copyright (C) 2008-2011 The IPython Development Team
@@ -6,8 +6,6 b' IO related utilities.'
6 # Copyright (c) IPython Development Team.
6 # Copyright (c) IPython Development Team.
7 # Distributed under the terms of the Modified BSD License.
7 # Distributed under the terms of the Modified BSD License.
8
8
9 from __future__ import print_function
10 from __future__ import absolute_import
11
9
12
10
13 import atexit
11 import atexit
@@ -1,4 +1,3 b''
1 from __future__ import absolute_import
2
1
3 from warnings import warn
2 from warnings import warn
4
3
@@ -23,7 +23,6 b' path to module and not an open file object as well.'
23 #-----------------------------------------------------------------------------
23 #-----------------------------------------------------------------------------
24 # Imports
24 # Imports
25 #-----------------------------------------------------------------------------
25 #-----------------------------------------------------------------------------
26 from __future__ import print_function
27
26
28 # Stdlib imports
27 # Stdlib imports
29 import imp
28 import imp
@@ -4,7 +4,6 b' as per PEP 263.'
4
4
5 Much of the code is taken from the tokenize module in Python 3.2.
5 Much of the code is taken from the tokenize module in Python 3.2.
6 """
6 """
7 from __future__ import absolute_import
8
7
9 import io
8 import io
10 from io import TextIOWrapper, BytesIO
9 from io import TextIOWrapper, BytesIO
@@ -6,7 +6,6 b' Utilities for working with external processes.'
6 # Copyright (c) IPython Development Team.
6 # Copyright (c) IPython Development Team.
7 # Distributed under the terms of the Modified BSD License.
7 # Distributed under the terms of the Modified BSD License.
8
8
9 from __future__ import print_function
10
9
11 import os
10 import os
12 import sys
11 import sys
@@ -2,7 +2,6 b''
2
2
3 This is copied from the stdlib and will be standard in Python 3.2 and onwards.
3 This is copied from the stdlib and will be standard in Python 3.2 and onwards.
4 """
4 """
5 from __future__ import print_function
6
5
7 import os as _os
6 import os as _os
8 import warnings as _warnings
7 import warnings as _warnings
@@ -12,7 +12,6 b''
12 # Imports
12 # Imports
13 #-----------------------------------------------------------------------------
13 #-----------------------------------------------------------------------------
14
14
15 from __future__ import print_function
16
15
17 import sys
16 import sys
18
17
@@ -4,8 +4,6 b''
4 # Copyright (c) IPython Development Team.
4 # Copyright (c) IPython Development Team.
5 # Distributed under the terms of the Modified BSD License.
5 # Distributed under the terms of the Modified BSD License.
6
6
7 from __future__ import print_function
8 from __future__ import absolute_import
9
7
10 import io as stdlib_io
8 import io as stdlib_io
11 import os.path
9 import os.path
@@ -12,7 +12,6 b''
12 # Imports
12 # Imports
13 #-----------------------------------------------------------------------------
13 #-----------------------------------------------------------------------------
14
14
15 from __future__ import with_statement
16
15
17 import os
16 import os
18 import shutil
17 import shutil
@@ -93,8 +93,7 b' def test_arg_split_win32():'
93 class SubProcessTestCase(TestCase, tt.TempFileMixin):
93 class SubProcessTestCase(TestCase, tt.TempFileMixin):
94 def setUp(self):
94 def setUp(self):
95 """Make a valid python temp file."""
95 """Make a valid python temp file."""
96 lines = ["from __future__ import print_function",
96 lines = [ "import sys",
97 "import sys",
98 "print('on stdout', end='', file=sys.stdout)",
97 "print('on stdout', end='', file=sys.stdout)",
99 "print('on stderr', end='', file=sys.stderr)",
98 "print('on stderr', end='', file=sys.stderr)",
100 "sys.stdout.flush()",
99 "sys.stdout.flush()",
@@ -1,6 +1,5 b''
1 # encoding: utf-8
1 # encoding: utf-8
2 """Tests for IPython.utils.text"""
2 """Tests for IPython.utils.text"""
3 from __future__ import print_function
4
3
5 #-----------------------------------------------------------------------------
4 #-----------------------------------------------------------------------------
6 # Copyright (C) 2011 The IPython Development Team
5 # Copyright (C) 2011 The IPython Development Team
@@ -7,7 +7,6 b' Inheritance diagram:'
7 .. inheritance-diagram:: IPython.utils.text
7 .. inheritance-diagram:: IPython.utils.text
8 :parts: 3
8 :parts: 3
9 """
9 """
10 from __future__ import absolute_import
11
10
12 import os
11 import os
13 import re
12 import re
@@ -20,7 +19,6 b' except ImportError:'
20 # Python 2 backport
19 # Python 2 backport
21 from pathlib2 import Path
20 from pathlib2 import Path
22
21
23 from IPython.testing.skipdoctest import skip_doctest_py3, skip_doctest
24 from IPython.utils import py3compat
22 from IPython.utils import py3compat
25
23
26 # datetime.strftime date format for ipython
24 # datetime.strftime date format for ipython
@@ -517,7 +515,6 b' class EvalFormatter(Formatter):'
517 # inside [], so EvalFormatter can handle slicing. Once we only support 3.4 and
515 # inside [], so EvalFormatter can handle slicing. Once we only support 3.4 and
518 # above, it should be possible to remove FullEvalFormatter.
516 # above, it should be possible to remove FullEvalFormatter.
519
517
520 @skip_doctest_py3
521 class FullEvalFormatter(Formatter):
518 class FullEvalFormatter(Formatter):
522 """A String Formatter that allows evaluation of simple expressions.
519 """A String Formatter that allows evaluation of simple expressions.
523
520
@@ -533,13 +530,13 b' class FullEvalFormatter(Formatter):'
533
530
534 In [1]: f = FullEvalFormatter()
531 In [1]: f = FullEvalFormatter()
535 In [2]: f.format('{n//4}', n=8)
532 In [2]: f.format('{n//4}', n=8)
536 Out[2]: u'2'
533 Out[2]: '2'
537
534
538 In [3]: f.format('{list(range(5))[2:4]}')
535 In [3]: f.format('{list(range(5))[2:4]}')
539 Out[3]: u'[2, 3]'
536 Out[3]: '[2, 3]'
540
537
541 In [4]: f.format('{3*2}')
538 In [4]: f.format('{3*2}')
542 Out[4]: u'6'
539 Out[4]: '6'
543 """
540 """
544 # copied from Formatter._vformat with minor changes to allow eval
541 # copied from Formatter._vformat with minor changes to allow eval
545 # and replace the format_spec code with slicing
542 # and replace the format_spec code with slicing
@@ -574,7 +571,6 b' class FullEvalFormatter(Formatter):'
574 return u''.join(py3compat.cast_unicode(s) for s in result)
571 return u''.join(py3compat.cast_unicode(s) for s in result)
575
572
576
573
577 @skip_doctest_py3
578 class DollarFormatter(FullEvalFormatter):
574 class DollarFormatter(FullEvalFormatter):
579 """Formatter allowing Itpl style $foo replacement, for names and attribute
575 """Formatter allowing Itpl style $foo replacement, for names and attribute
580 access only. Standard {foo} replacement also works, and allows full
576 access only. Standard {foo} replacement also works, and allows full
@@ -586,13 +582,13 b' class DollarFormatter(FullEvalFormatter):'
586
582
587 In [1]: f = DollarFormatter()
583 In [1]: f = DollarFormatter()
588 In [2]: f.format('{n//4}', n=8)
584 In [2]: f.format('{n//4}', n=8)
589 Out[2]: u'2'
585 Out[2]: '2'
590
586
591 In [3]: f.format('23 * 76 is $result', result=23*76)
587 In [3]: f.format('23 * 76 is $result', result=23*76)
592 Out[3]: u'23 * 76 is 1748'
588 Out[3]: '23 * 76 is 1748'
593
589
594 In [4]: f.format('$a or {b}', a=1, b=2)
590 In [4]: f.format('$a or {b}', a=1, b=2)
595 Out[4]: u'1 or 2'
591 Out[4]: '1 or 2'
596 """
592 """
597 _dollar_pattern = re.compile("(.*?)\$(\$?[\w\.]+)")
593 _dollar_pattern = re.compile("(.*?)\$(\$?[\w\.]+)")
598 def parse(self, fmt_string):
594 def parse(self, fmt_string):
This diff has been collapsed as it changes many lines, (593 lines changed) Show them Hide them
@@ -1,9 +1,594 b''
1 """Load our patched versions of tokenize.
1 """Patched version of standard library tokenize, to deal with various bugs.
2
3 Based on Python 3.2 code.
4
5 Patches:
6
7 - Gareth Rees' patch for Python issue #12691 (untokenizing)
8 - Except we don't encode the output of untokenize
9 - Python 2 compatible syntax, so that it can be byte-compiled at installation
10 - Newlines in comments and blank lines should be either NL or NEWLINE, depending
11 on whether they are in a multi-line statement. Filed as Python issue #17061.
12 - Export generate_tokens & TokenError
13 - u and rb literals are allowed under Python 3.3 and above.
14
15 ------------------------------------------------------------------------------
16 Tokenization help for Python programs.
17
18 tokenize(readline) is a generator that breaks a stream of bytes into
19 Python tokens. It decodes the bytes according to PEP-0263 for
20 determining source file encoding.
21
22 It accepts a readline-like method which is called repeatedly to get the
23 next line of input (or b"" for EOF). It generates 5-tuples with these
24 members:
25
26 the token type (see token.py)
27 the token (a string)
28 the starting (row, column) indices of the token (a 2-tuple of ints)
29 the ending (row, column) indices of the token (a 2-tuple of ints)
30 the original line (string)
31
32 It is designed to match the working of the Python tokenizer exactly, except
33 that it produces COMMENT tokens for comments and gives type OP for all
34 operators. Additionally, all token lists start with an ENCODING token
35 which tells you which encoding was used to decode the bytes stream.
2 """
36 """
3
37
38 __author__ = 'Ka-Ping Yee <ping@lfw.org>'
39 __credits__ = ('GvR, ESR, Tim Peters, Thomas Wouters, Fred Drake, '
40 'Skip Montanaro, Raymond Hettinger, Trent Nelson, '
41 'Michael Foord')
42 import builtins
43 import re
4 import sys
44 import sys
45 from token import *
46 from codecs import lookup, BOM_UTF8
47 import collections
48 from io import TextIOWrapper
49 cookie_re = re.compile("coding[:=]\s*([-\w.]+)")
50
51 import token
52 __all__ = token.__all__ + ["COMMENT", "tokenize", "detect_encoding",
53 "NL", "untokenize", "ENCODING", "TokenInfo"]
54 del token
55
56 __all__ += ["generate_tokens", "TokenError"]
5
57
6 if sys.version_info[0] >= 3:
58 COMMENT = N_TOKENS
7 from ._tokenize_py3 import *
59 tok_name[COMMENT] = 'COMMENT'
60 NL = N_TOKENS + 1
61 tok_name[NL] = 'NL'
62 ENCODING = N_TOKENS + 2
63 tok_name[ENCODING] = 'ENCODING'
64 N_TOKENS += 3
65
66 class TokenInfo(collections.namedtuple('TokenInfo', 'type string start end line')):
67 def __repr__(self):
68 annotated_type = '%d (%s)' % (self.type, tok_name[self.type])
69 return ('TokenInfo(type=%s, string=%r, start=%r, end=%r, line=%r)' %
70 self._replace(type=annotated_type))
71
72 def group(*choices): return '(' + '|'.join(choices) + ')'
73 def any(*choices): return group(*choices) + '*'
74 def maybe(*choices): return group(*choices) + '?'
75
76 # Note: we use unicode matching for names ("\w") but ascii matching for
77 # number literals.
78 Whitespace = r'[ \f\t]*'
79 Comment = r'#[^\r\n]*'
80 Ignore = Whitespace + any(r'\\\r?\n' + Whitespace) + maybe(Comment)
81 Name = r'\w+'
82
83 Hexnumber = r'0[xX][0-9a-fA-F]+'
84 Binnumber = r'0[bB][01]+'
85 Octnumber = r'0[oO][0-7]+'
86 Decnumber = r'(?:0+|[1-9][0-9]*)'
87 Intnumber = group(Hexnumber, Binnumber, Octnumber, Decnumber)
88 Exponent = r'[eE][-+]?[0-9]+'
89 Pointfloat = group(r'[0-9]+\.[0-9]*', r'\.[0-9]+') + maybe(Exponent)
90 Expfloat = r'[0-9]+' + Exponent
91 Floatnumber = group(Pointfloat, Expfloat)
92 Imagnumber = group(r'[0-9]+[jJ]', Floatnumber + r'[jJ]')
93 Number = group(Imagnumber, Floatnumber, Intnumber)
94
95 if sys.version_info.minor >= 3:
96 StringPrefix = r'(?:[bB][rR]?|[rR][bB]?|[uU])?'
8 else:
97 else:
9 from ._tokenize_py2 import *
98 StringPrefix = r'(?:[bB]?[rR]?)?'
99
100 # Tail end of ' string.
101 Single = r"[^'\\]*(?:\\.[^'\\]*)*'"
102 # Tail end of " string.
103 Double = r'[^"\\]*(?:\\.[^"\\]*)*"'
104 # Tail end of ''' string.
105 Single3 = r"[^'\\]*(?:(?:\\.|'(?!''))[^'\\]*)*'''"
106 # Tail end of """ string.
107 Double3 = r'[^"\\]*(?:(?:\\.|"(?!""))[^"\\]*)*"""'
108 Triple = group(StringPrefix + "'''", StringPrefix + '"""')
109 # Single-line ' or " string.
110 String = group(StringPrefix + r"'[^\n'\\]*(?:\\.[^\n'\\]*)*'",
111 StringPrefix + r'"[^\n"\\]*(?:\\.[^\n"\\]*)*"')
112
113 # Because of leftmost-then-longest match semantics, be sure to put the
114 # longest operators first (e.g., if = came before ==, == would get
115 # recognized as two instances of =).
116 Operator = group(r"\*\*=?", r">>=?", r"<<=?", r"!=",
117 r"//=?", r"->",
118 r"[+\-*/%&|^=<>]=?",
119 r"~")
120
121 Bracket = '[][(){}]'
122 Special = group(r'\r?\n', r'\.\.\.', r'[:;.,@]')
123 Funny = group(Operator, Bracket, Special)
124
125 PlainToken = group(Number, Funny, String, Name)
126 Token = Ignore + PlainToken
127
128 # First (or only) line of ' or " string.
129 ContStr = group(StringPrefix + r"'[^\n'\\]*(?:\\.[^\n'\\]*)*" +
130 group("'", r'\\\r?\n'),
131 StringPrefix + r'"[^\n"\\]*(?:\\.[^\n"\\]*)*' +
132 group('"', r'\\\r?\n'))
133 PseudoExtras = group(r'\\\r?\n', Comment, Triple)
134 PseudoToken = Whitespace + group(PseudoExtras, Number, Funny, ContStr, Name)
135
136 def _compile(expr):
137 return re.compile(expr, re.UNICODE)
138
139 tokenprog, pseudoprog, single3prog, double3prog = map(
140 _compile, (Token, PseudoToken, Single3, Double3))
141 endprogs = {"'": _compile(Single), '"': _compile(Double),
142 "'''": single3prog, '"""': double3prog,
143 "r'''": single3prog, 'r"""': double3prog,
144 "b'''": single3prog, 'b"""': double3prog,
145 "R'''": single3prog, 'R"""': double3prog,
146 "B'''": single3prog, 'B"""': double3prog,
147 "br'''": single3prog, 'br"""': double3prog,
148 "bR'''": single3prog, 'bR"""': double3prog,
149 "Br'''": single3prog, 'Br"""': double3prog,
150 "BR'''": single3prog, 'BR"""': double3prog,
151 'r': None, 'R': None, 'b': None, 'B': None}
152
153 triple_quoted = {}
154 for t in ("'''", '"""',
155 "r'''", 'r"""', "R'''", 'R"""',
156 "b'''", 'b"""', "B'''", 'B"""',
157 "br'''", 'br"""', "Br'''", 'Br"""',
158 "bR'''", 'bR"""', "BR'''", 'BR"""'):
159 triple_quoted[t] = t
160 single_quoted = {}
161 for t in ("'", '"',
162 "r'", 'r"', "R'", 'R"',
163 "b'", 'b"', "B'", 'B"',
164 "br'", 'br"', "Br'", 'Br"',
165 "bR'", 'bR"', "BR'", 'BR"' ):
166 single_quoted[t] = t
167
168 if sys.version_info.minor >= 3:
169 # Python 3.3
170 for _prefix in ['rb', 'rB', 'Rb', 'RB', 'u', 'U']:
171 _t2 = _prefix+'"""'
172 endprogs[_t2] = double3prog
173 triple_quoted[_t2] = _t2
174 _t1 = _prefix + "'''"
175 endprogs[_t1] = single3prog
176 triple_quoted[_t1] = _t1
177 single_quoted[_prefix+'"'] = _prefix+'"'
178 single_quoted[_prefix+"'"] = _prefix+"'"
179 del _prefix, _t2, _t1
180 endprogs['u'] = None
181 endprogs['U'] = None
182
183 del _compile
184
185 tabsize = 8
186
187 class TokenError(Exception): pass
188
189 class StopTokenizing(Exception): pass
190
191
192 class Untokenizer:
193
194 def __init__(self):
195 self.tokens = []
196 self.prev_row = 1
197 self.prev_col = 0
198 self.encoding = 'utf-8'
199
200 def add_whitespace(self, tok_type, start):
201 row, col = start
202 assert row >= self.prev_row
203 col_offset = col - self.prev_col
204 if col_offset > 0:
205 self.tokens.append(" " * col_offset)
206 elif row > self.prev_row and tok_type not in (NEWLINE, NL, ENDMARKER):
207 # Line was backslash-continued.
208 self.tokens.append(" ")
209
210 def untokenize(self, tokens):
211 iterable = iter(tokens)
212 for t in iterable:
213 if len(t) == 2:
214 self.compat(t, iterable)
215 break
216 tok_type, token, start, end = t[:4]
217 if tok_type == ENCODING:
218 self.encoding = token
219 continue
220 self.add_whitespace(tok_type, start)
221 self.tokens.append(token)
222 self.prev_row, self.prev_col = end
223 if tok_type in (NEWLINE, NL):
224 self.prev_row += 1
225 self.prev_col = 0
226 return "".join(self.tokens)
227
228 def compat(self, token, iterable):
229 # This import is here to avoid problems when the itertools
230 # module is not built yet and tokenize is imported.
231 from itertools import chain
232 startline = False
233 prevstring = False
234 indents = []
235 toks_append = self.tokens.append
236
237 for tok in chain([token], iterable):
238 toknum, tokval = tok[:2]
239 if toknum == ENCODING:
240 self.encoding = tokval
241 continue
242
243 if toknum in (NAME, NUMBER):
244 tokval += ' '
245
246 # Insert a space between two consecutive strings
247 if toknum == STRING:
248 if prevstring:
249 tokval = ' ' + tokval
250 prevstring = True
251 else:
252 prevstring = False
253
254 if toknum == INDENT:
255 indents.append(tokval)
256 continue
257 elif toknum == DEDENT:
258 indents.pop()
259 continue
260 elif toknum in (NEWLINE, NL):
261 startline = True
262 elif startline and indents:
263 toks_append(indents[-1])
264 startline = False
265 toks_append(tokval)
266
267
268 def untokenize(tokens):
269 """
270 Convert ``tokens`` (an iterable) back into Python source code. Return
271 a bytes object, encoded using the encoding specified by the last
272 ENCODING token in ``tokens``, or UTF-8 if no ENCODING token is found.
273
274 The result is guaranteed to tokenize back to match the input so that
275 the conversion is lossless and round-trips are assured. The
276 guarantee applies only to the token type and token string as the
277 spacing between tokens (column positions) may change.
278
279 :func:`untokenize` has two modes. If the input tokens are sequences
280 of length 2 (``type``, ``string``) then spaces are added as necessary to
281 preserve the round-trip property.
282
283 If the input tokens are sequences of length 4 or more (``type``,
284 ``string``, ``start``, ``end``), as returned by :func:`tokenize`, then
285 spaces are added so that each token appears in the result at the
286 position indicated by ``start`` and ``end``, if possible.
287 """
288 return Untokenizer().untokenize(tokens)
289
290
291 def _get_normal_name(orig_enc):
292 """Imitates get_normal_name in tokenizer.c."""
293 # Only care about the first 12 characters.
294 enc = orig_enc[:12].lower().replace("_", "-")
295 if enc == "utf-8" or enc.startswith("utf-8-"):
296 return "utf-8"
297 if enc in ("latin-1", "iso-8859-1", "iso-latin-1") or \
298 enc.startswith(("latin-1-", "iso-8859-1-", "iso-latin-1-")):
299 return "iso-8859-1"
300 return orig_enc
301
302 def detect_encoding(readline):
303 """
304 The detect_encoding() function is used to detect the encoding that should
305 be used to decode a Python source file. It requires one argment, readline,
306 in the same way as the tokenize() generator.
307
308 It will call readline a maximum of twice, and return the encoding used
309 (as a string) and a list of any lines (left as bytes) it has read in.
310
311 It detects the encoding from the presence of a utf-8 bom or an encoding
312 cookie as specified in pep-0263. If both a bom and a cookie are present,
313 but disagree, a SyntaxError will be raised. If the encoding cookie is an
314 invalid charset, raise a SyntaxError. Note that if a utf-8 bom is found,
315 'utf-8-sig' is returned.
316
317 If no encoding is specified, then the default of 'utf-8' will be returned.
318 """
319 bom_found = False
320 encoding = None
321 default = 'utf-8'
322 def read_or_stop():
323 try:
324 return readline()
325 except StopIteration:
326 return b''
327
328 def find_cookie(line):
329 try:
330 # Decode as UTF-8. Either the line is an encoding declaration,
331 # in which case it should be pure ASCII, or it must be UTF-8
332 # per default encoding.
333 line_string = line.decode('utf-8')
334 except UnicodeDecodeError:
335 raise SyntaxError("invalid or missing encoding declaration")
336
337 matches = cookie_re.findall(line_string)
338 if not matches:
339 return None
340 encoding = _get_normal_name(matches[0])
341 try:
342 codec = lookup(encoding)
343 except LookupError:
344 # This behaviour mimics the Python interpreter
345 raise SyntaxError("unknown encoding: " + encoding)
346
347 if bom_found:
348 if encoding != 'utf-8':
349 # This behaviour mimics the Python interpreter
350 raise SyntaxError('encoding problem: utf-8')
351 encoding += '-sig'
352 return encoding
353
354 first = read_or_stop()
355 if first.startswith(BOM_UTF8):
356 bom_found = True
357 first = first[3:]
358 default = 'utf-8-sig'
359 if not first:
360 return default, []
361
362 encoding = find_cookie(first)
363 if encoding:
364 return encoding, [first]
365
366 second = read_or_stop()
367 if not second:
368 return default, [first]
369
370 encoding = find_cookie(second)
371 if encoding:
372 return encoding, [first, second]
373
374 return default, [first, second]
375
376
377 def open(filename):
378 """Open a file in read only mode using the encoding detected by
379 detect_encoding().
380 """
381 buffer = builtins.open(filename, 'rb')
382 encoding, lines = detect_encoding(buffer.readline)
383 buffer.seek(0)
384 text = TextIOWrapper(buffer, encoding, line_buffering=True)
385 text.mode = 'r'
386 return text
387
388
389 def tokenize(readline):
390 """
391 The tokenize() generator requires one argment, readline, which
392 must be a callable object which provides the same interface as the
393 readline() method of built-in file objects. Each call to the function
394 should return one line of input as bytes. Alternately, readline
395 can be a callable function terminating with StopIteration:
396 readline = open(myfile, 'rb').__next__ # Example of alternate readline
397
398 The generator produces 5-tuples with these members: the token type; the
399 token string; a 2-tuple (srow, scol) of ints specifying the row and
400 column where the token begins in the source; a 2-tuple (erow, ecol) of
401 ints specifying the row and column where the token ends in the source;
402 and the line on which the token was found. The line passed is the
403 logical line; continuation lines are included.
404
405 The first token sequence will always be an ENCODING token
406 which tells you which encoding was used to decode the bytes stream.
407 """
408 # This import is here to avoid problems when the itertools module is not
409 # built yet and tokenize is imported.
410 from itertools import chain, repeat
411 encoding, consumed = detect_encoding(readline)
412 rl_gen = iter(readline, b"")
413 empty = repeat(b"")
414 return _tokenize(chain(consumed, rl_gen, empty).__next__, encoding)
415
416
417 def _tokenize(readline, encoding):
418 lnum = parenlev = continued = 0
419 numchars = '0123456789'
420 contstr, needcont = '', 0
421 contline = None
422 indents = [0]
423
424 if encoding is not None:
425 if encoding == "utf-8-sig":
426 # BOM will already have been stripped.
427 encoding = "utf-8"
428 yield TokenInfo(ENCODING, encoding, (0, 0), (0, 0), '')
429 while True: # loop over lines in stream
430 try:
431 line = readline()
432 except StopIteration:
433 line = b''
434
435 if encoding is not None:
436 line = line.decode(encoding)
437 lnum += 1
438 pos, max = 0, len(line)
439
440 if contstr: # continued string
441 if not line:
442 raise TokenError("EOF in multi-line string", strstart)
443 endmatch = endprog.match(line)
444 if endmatch:
445 pos = end = endmatch.end(0)
446 yield TokenInfo(STRING, contstr + line[:end],
447 strstart, (lnum, end), contline + line)
448 contstr, needcont = '', 0
449 contline = None
450 elif needcont and line[-2:] != '\\\n' and line[-3:] != '\\\r\n':
451 yield TokenInfo(ERRORTOKEN, contstr + line,
452 strstart, (lnum, len(line)), contline)
453 contstr = ''
454 contline = None
455 continue
456 else:
457 contstr = contstr + line
458 contline = contline + line
459 continue
460
461 elif parenlev == 0 and not continued: # new statement
462 if not line: break
463 column = 0
464 while pos < max: # measure leading whitespace
465 if line[pos] == ' ':
466 column += 1
467 elif line[pos] == '\t':
468 column = (column//tabsize + 1)*tabsize
469 elif line[pos] == '\f':
470 column = 0
471 else:
472 break
473 pos += 1
474 if pos == max:
475 break
476
477 if line[pos] in '#\r\n': # skip comments or blank lines
478 if line[pos] == '#':
479 comment_token = line[pos:].rstrip('\r\n')
480 nl_pos = pos + len(comment_token)
481 yield TokenInfo(COMMENT, comment_token,
482 (lnum, pos), (lnum, pos + len(comment_token)), line)
483 yield TokenInfo(NEWLINE, line[nl_pos:],
484 (lnum, nl_pos), (lnum, len(line)), line)
485 else:
486 yield TokenInfo(NEWLINE, line[pos:],
487 (lnum, pos), (lnum, len(line)), line)
488 continue
489
490 if column > indents[-1]: # count indents or dedents
491 indents.append(column)
492 yield TokenInfo(INDENT, line[:pos], (lnum, 0), (lnum, pos), line)
493 while column < indents[-1]:
494 if column not in indents:
495 raise IndentationError(
496 "unindent does not match any outer indentation level",
497 ("<tokenize>", lnum, pos, line))
498 indents = indents[:-1]
499 yield TokenInfo(DEDENT, '', (lnum, pos), (lnum, pos), line)
500
501 else: # continued statement
502 if not line:
503 raise TokenError("EOF in multi-line statement", (lnum, 0))
504 continued = 0
505
506 while pos < max:
507 pseudomatch = pseudoprog.match(line, pos)
508 if pseudomatch: # scan for tokens
509 start, end = pseudomatch.span(1)
510 spos, epos, pos = (lnum, start), (lnum, end), end
511 token, initial = line[start:end], line[start]
512
513 if (initial in numchars or # ordinary number
514 (initial == '.' and token != '.' and token != '...')):
515 yield TokenInfo(NUMBER, token, spos, epos, line)
516 elif initial in '\r\n':
517 yield TokenInfo(NL if parenlev > 0 else NEWLINE,
518 token, spos, epos, line)
519 elif initial == '#':
520 assert not token.endswith("\n")
521 yield TokenInfo(COMMENT, token, spos, epos, line)
522 elif token in triple_quoted:
523 endprog = endprogs[token]
524 endmatch = endprog.match(line, pos)
525 if endmatch: # all on one line
526 pos = endmatch.end(0)
527 token = line[start:pos]
528 yield TokenInfo(STRING, token, spos, (lnum, pos), line)
529 else:
530 strstart = (lnum, start) # multiple lines
531 contstr = line[start:]
532 contline = line
533 break
534 elif initial in single_quoted or \
535 token[:2] in single_quoted or \
536 token[:3] in single_quoted:
537 if token[-1] == '\n': # continued string
538 strstart = (lnum, start)
539 endprog = (endprogs[initial] or endprogs[token[1]] or
540 endprogs[token[2]])
541 contstr, needcont = line[start:], 1
542 contline = line
543 break
544 else: # ordinary string
545 yield TokenInfo(STRING, token, spos, epos, line)
546 elif initial.isidentifier(): # ordinary name
547 yield TokenInfo(NAME, token, spos, epos, line)
548 elif initial == '\\': # continued stmt
549 continued = 1
550 else:
551 if initial in '([{':
552 parenlev += 1
553 elif initial in ')]}':
554 parenlev -= 1
555 yield TokenInfo(OP, token, spos, epos, line)
556 else:
557 yield TokenInfo(ERRORTOKEN, line[pos],
558 (lnum, pos), (lnum, pos+1), line)
559 pos += 1
560
561 for indent in indents[1:]: # pop remaining indent levels
562 yield TokenInfo(DEDENT, '', (lnum, 0), (lnum, 0), '')
563 yield TokenInfo(ENDMARKER, '', (lnum, 0), (lnum, 0), '')
564
565
566 # An undocumented, backwards compatible, API for all the places in the standard
567 # library that expect to be able to use tokenize with strings
568 def generate_tokens(readline):
569 return _tokenize(readline, None)
570
571 if __name__ == "__main__":
572 # Quick sanity check
573 s = b'''def parseline(self, line):
574 """Parse the line into a command name and a string containing
575 the arguments. Returns a tuple containing (command, args, line).
576 'command' and 'args' may be None if the line couldn't be parsed.
577 """
578 line = line.strip()
579 if not line:
580 return None, None, line
581 elif line[0] == '?':
582 line = 'help ' + line[1:]
583 elif line[0] == '!':
584 if hasattr(self, 'do_shell'):
585 line = 'shell ' + line[1:]
586 else:
587 return None, None, line
588 i, n = 0, len(line)
589 while i < n and line[i] in self.identchars: i = i+1
590 cmd, arg = line[:i], line[i:].strip()
591 return cmd, arg, line
592 '''
593 for tok in tokenize(iter(s.splitlines()).__next__):
594 print(tok)
@@ -3,7 +3,6 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 from __future__ import absolute_import, print_function
7
6
8 from collections import namedtuple
7 from collections import namedtuple
9 from io import StringIO
8 from io import StringIO
@@ -1,4 +1,3 b''
1 from __future__ import absolute_import
2
1
3 from warnings import warn
2 from warnings import warn
4
3
@@ -17,7 +17,6 b' NOTE: this is a modified version of a script originally shipped with the'
17 PyMVPA project, which we've adapted for NIPY use. PyMVPA is an MIT-licensed
17 PyMVPA project, which we've adapted for NIPY use. PyMVPA is an MIT-licensed
18 project."""
18 project."""
19
19
20 from __future__ import print_function
21
20
22 # Stdlib imports
21 # Stdlib imports
23 import ast
22 import ast
@@ -8,7 +8,6 b' embedding which you can cut and paste in your code once you understand how'
8 things work.
8 things work.
9
9
10 The code in this file is deliberately extra-verbose, meant for learning."""
10 The code in this file is deliberately extra-verbose, meant for learning."""
11 from __future__ import print_function
12
11
13 # The basics to get you going:
12 # The basics to get you going:
14
13
@@ -8,7 +8,6 b' resuming execution later.'
8
8
9 This is a unicode test, åäö
9 This is a unicode test, åäö
10 """
10 """
11 from __future__ import print_function
12
11
13 print('Hello, welcome to an interactive IPython demo.')
12 print('Hello, welcome to an interactive IPython demo.')
14 print('Executing this block should require confirmation before proceeding,')
13 print('Executing this block should require confirmation before proceeding,')
@@ -5,7 +5,6 b' http://docs.python.org/2/distutils/builtdist.html#the-postinstallation-script'
5
5
6 """
6 """
7
7
8 from __future__ import print_function
9
8
10 import os
9 import os
11 import sys
10 import sys
@@ -41,8 +41,6 b' See IPython `README.rst` file for more information:'
41 print(error, file=sys.stderr)
41 print(error, file=sys.stderr)
42 sys.exit(1)
42 sys.exit(1)
43
43
44 PY3 = (sys.version_info[0] >= 3)
45
46 # At least we're on the python version we need, move on.
44 # At least we're on the python version we need, move on.
47
45
48 #-------------------------------------------------------------------------------
46 #-------------------------------------------------------------------------------
@@ -12,7 +12,6 b' This includes:'
12 # Copyright (c) IPython Development Team.
12 # Copyright (c) IPython Development Team.
13 # Distributed under the terms of the Modified BSD License.
13 # Distributed under the terms of the Modified BSD License.
14
14
15 from __future__ import print_function
16
15
17 import re
16 import re
18 import os
17 import os
@@ -26,7 +26,6 b' of that repo.'
26
26
27 """
27 """
28
28
29 from __future__ import print_function
30
29
31 import os
30 import os
32 import re
31 import re
@@ -8,7 +8,6 b' Usage:'
8 It prints summaries and if chosen, line-by-line info of where \\t or \\r
8 It prints summaries and if chosen, line-by-line info of where \\t or \\r
9 characters can be found in our source tree.
9 characters can be found in our source tree.
10 """
10 """
11 from __future__ import print_function
12
11
13 # Config
12 # Config
14 # If true, all lines that have tabs are printed, with line number
13 # If true, all lines that have tabs are printed, with line number
@@ -9,7 +9,6 b''
9 #
9 #
10 # The original mapping of latex symbols to unicode comes from the `latex_symbols.jl` files from Julia.
10 # The original mapping of latex symbols to unicode comes from the `latex_symbols.jl` files from Julia.
11
11
12 from __future__ import print_function
13 import os, sys
12 import os, sys
14
13
15 if not sys.version_info[0] == 3:
14 if not sys.version_info[0] == 3:
@@ -1,5 +1,4 b''
1 """Functions for Github API requests."""
1 """Functions for Github API requests."""
2 from __future__ import print_function
3
2
4 try:
3 try:
5 input = raw_input
4 input = raw_input
@@ -7,7 +7,6 b' Usage:'
7 Type `git mpr -h` for details.
7 Type `git mpr -h` for details.
8 """
8 """
9
9
10 from __future__ import print_function
11
10
12 import io, os
11 import io, os
13 import argparse
12 import argparse
@@ -9,7 +9,6 b' To generate a report for IPython 2.0, run:'
9 # Imports
9 # Imports
10 #-----------------------------------------------------------------------------
10 #-----------------------------------------------------------------------------
11
11
12 from __future__ import print_function
13
12
14 import codecs
13 import codecs
15 import sys
14 import sys
@@ -114,9 +113,6 b' if __name__ == "__main__":'
114 print("DEPRECATE: backport_pr.py is deprecated and is is now recommended"
113 print("DEPRECATE: backport_pr.py is deprecated and is is now recommended"
115 "to install `ghpro` from PyPI.", file=sys.stderr)
114 "to install `ghpro` from PyPI.", file=sys.stderr)
116
115
117 # deal with unicode
118 if sys.version_info < (3,):
119 sys.stdout = codecs.getwriter('utf8')(sys.stdout)
120
116
121 # Whether to add reST urls for all issues in printout.
117 # Whether to add reST urls for all issues in printout.
122 show_urls = True
118 show_urls = True
@@ -7,7 +7,6 b' Python, and posts the results to Gist if any tests fail.'
7 Usage:
7 Usage:
8 python test_pr.py 1657
8 python test_pr.py 1657
9 """
9 """
10 from __future__ import print_function
11
10
12 import errno
11 import errno
13 from glob import glob
12 from glob import glob
@@ -1,6 +1,6 b''
1 """This tests that future compiler flags are passed to the embedded IPython."""
1 """This tests that future compiler flags are passed to the embedded IPython."""
2 from IPython import embed
2 from IPython import embed
3 import __future__
3 import __future__
4 embed(banner1='', header='check 1/2 == 0 in Python 2')
4 embed(banner1='', header='check 1 <> 2 cause SyntaxError')
5 embed(banner1='', header='check 1/2 == 0.5 in Python 2',
5 embed(banner1='', header='check 1 <> 2 == True',
6 compile_flags=__future__.division.compiler_flag)
6 compile_flags=__future__.barry_as_FLUFL.compiler_flag)
@@ -1,6 +1,5 b''
1 """Various utilities common to IPython release and maintenance tools.
1 """Various utilities common to IPython release and maintenance tools.
2 """
2 """
3 from __future__ import print_function
4
3
5 # Library imports
4 # Library imports
6 import os
5 import os
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
This diff has been collapsed as it changes many lines, (595 lines changed) Show them Hide them
1 NO CONTENT: file was removed
NO CONTENT: file was removed
General Comments 0
You need to be logged in to leave comments. Login now