unicode_literals = _get_feature("unicode_literals")
with_statement = _get_feature("with_statement")
division = _get_feature("division")
+print_function = _get_feature("print_function")
del _get_feature
from time import time
import cython
-cython.declare(EncodedString=object, string_prefixes=object, raw_prefixes=object, IDENT=object)
+cython.declare(EncodedString=object, string_prefixes=object, raw_prefixes=object, IDENT=object,
+ print_function=object)
from Cython import Plex, Utils
from Cython.Plex.Scanners import Scanner
from Cython.Plex.Errors import UnrecognizedInput
from Errors import CompileError, error
from Lexicon import string_prefixes, raw_prefixes, make_lexicon, IDENT
+from Future import print_function
from StringEncoding import EncodedString
self.error("Unrecognized character")
if sy == IDENT:
if systring in resword_dict:
- sy = systring
+ if systring == 'print' and \
+ print_function in self.context.future_directives:
+ systring = EncodedString(systring)
+ else:
+ sy = systring
else:
systring = EncodedString(systring)
self.sy = sy
]
VER_DEP_MODULES = {
+ # tests are excluded if 'CurrentPythonVersion OP VersionTuple', i.e.
+ # (2,4) : (operator.le, ...) excludes ... when PyVer <= 2.4.x
(2,4) : (operator.le, lambda x: x in ['run.extern_builtins_T258'
]),
+ (2,6) : (operator.lt, lambda x: x in ['run.print_function'
+ ]),
(3,): (operator.ge, lambda x: x in ['run.non_future_division',
'compile.extsetslice',
'compile.extdelslice']),
--- /dev/null
+
+# Py2.6 and later only!
+from __future__ import print_function
+
+def print_to_stdout(a, b):
+ """
+ >>> print_to_stdout(1, 'test')
+ <BLANKLINE>
+ 1
+ 1 test
+ 1 test
+ 1 test 42 spam
+ """
+ print()
+ print(a)
+ print(a, end=' ')
+ print(b)
+ print(a, b)
+ print(a, b, end=' ')
+ print(42, u"spam")
+
+def print_assign(a, b):
+ """
+ >>> print_assign(1, 'test')
+ <BLANKLINE>
+ 1
+ 1 test
+ 1 test
+ 1 test 42 spam
+ """
+ x = print
+ x()
+ x(a)
+ x(a, end=' ')
+ x(b)
+ x(a, b)
+ x(a, b, end=' ')
+ x(42, u"spam")
+
+
+try:
+ from StringIO import StringIO
+except ImportError:
+ from io import StringIO
+
+def print_to_stringio(stream, a, b):
+ """
+ >>> stream = StringIO()
+ >>> print_to_stringio(stream, 1, 'test')
+ >>> print(stream.getvalue())
+ <BLANKLINE>
+ 1
+ 1 test
+ 1 test
+ 1 test 42 spam
+ <BLANKLINE>
+ """
+ print(file=stream)
+ print(a, file=stream)
+ print(a, end=' ', file=stream)
+ print(b, file=stream)
+ print(a, b, file=stream)
+ print(a, b, end=' ', file=stream)
+ print(42, u"spam", file=stream)