diff options
author | Benjamin Peterson <benjamin@python.org> | 2013-09-08 12:48:25 -0400 |
---|---|---|
committer | Benjamin Peterson <benjamin@python.org> | 2013-09-08 12:48:25 -0400 |
commit | f517a8e36ca0032f5291a65a9cad4f19cdb75c2e (patch) | |
tree | 620bd2bec2bcaa2403c3ea3d9e04c287782738b1 | |
parent | a2d1d9817b862da0b7b19b681b074b4323fb2ad7 (diff) | |
download | six-f517a8e36ca0032f5291a65a9cad4f19cdb75c2e.tar.gz |
use builtin print function when possible
-rw-r--r-- | six.py | 17 | ||||
-rw-r--r-- | test_six.py | 2 |
2 files changed, 7 insertions, 12 deletions
@@ -481,8 +481,7 @@ _add_doc(u, """Text literal""") if PY3: - import builtins - exec_ = getattr(builtins, "exec") + exec_ = getattr(moves.builtins, "exec") def reraise(tp, value, tb=None): @@ -490,10 +489,6 @@ if PY3: raise value.with_traceback(tb) raise value - - print_ = getattr(builtins, "print") - del builtins - else: def exec_(_code_, _globs_=None, _locs_=None): """Execute code in a namespace.""" @@ -513,18 +508,18 @@ else: """) +print_ = getattr(moves.builtins, "print", None) +if print_ is None: def print_(*args, **kwargs): - """The new-style print function.""" + """The new-style print function for Python 2.4 and 2.5.""" fp = kwargs.pop("file", sys.stdout) if fp is None: return def write(data): if not isinstance(data, basestring): data = str(data) - # If the file has an encoding, encode unicode with it. In Python - # 2.7, file.write handles this. - if (sys.version_info[1] < 7 and - isinstance(fp, file) and + # If the file has an encoding, encode unicode with it. + if (isinstance(fp, file) and isinstance(data, unicode) and fp.encoding is not None): errors = getattr(fp, "errors", None) diff --git a/test_six.py b/test_six.py index 37fa6fa..feabd73 100644 --- a/test_six.py +++ b/test_six.py @@ -528,7 +528,7 @@ def test_print_(): assert out.getvalue() == "None\n" -@py.test.mark.skipif("sys.version_info[:2] >= (2, 7)") +@py.test.mark.skipif("sys.version_info[:2] >= (2, 6)") def test_print_encoding(monkeypatch): # Fool the type checking print_. monkeypatch.setattr(six, "file", six.BytesIO, raising=False) |