Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/sivel/speedtest-cli.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatt Martz <matt@sivel.net>2017-04-11 18:18:42 +0300
committerMatt Martz <matt@sivel.net>2017-04-12 20:18:54 +0300
commit824c584658cbab6fbd49becea0e483c3dab5b15e (patch)
tree87206486bbb9e658d07653a090870dd2741af917
parent9806e401e0ed1f665b2fc5c3d789e19e98145e6f (diff)
Invert logic for py3 print detection, to avoid confusion created by the future package
-rwxr-xr-xspeedtest.py44
1 files changed, 23 insertions, 21 deletions
diff --git a/speedtest.py b/speedtest.py
index 5cbf1dd..efba6cc 100755
--- a/speedtest.py
+++ b/speedtest.py
@@ -141,8 +141,30 @@ except ImportError:
BytesIO = None
try:
- import builtins
+ import __builtin__
except ImportError:
+ import builtins
+
+ class _Py3Utf8Stdout(TextIOWrapper):
+ def __init__(self, **kwargs):
+ buf = FileIO(sys.stdout.fileno(), 'w')
+ super(_Py3Utf8Stdout, self).__init__(
+ buf,
+ encoding='utf8',
+ errors='strict'
+ )
+
+ def write(self, s):
+ super(_Py3Utf8Stdout, self).write(s)
+ self.flush()
+
+ _py3_print = getattr(builtins, 'print')
+ _py3_utf8_stdout = _Py3Utf8Stdout()
+
+ def print_(*args, **kwargs):
+ kwargs['file'] = _py3_utf8_stdout
+ _py3_print(*args, **kwargs)
+else:
def print_(*args, **kwargs):
"""The new-style print function for Python 2.4 and 2.5.
@@ -202,26 +224,6 @@ except ImportError:
write(sep)
write(arg)
write(end)
-else:
- class _Py3Utf8Stdout(TextIOWrapper):
- def __init__(self, **kwargs):
- buf = FileIO(sys.stdout.fileno(), 'w')
- super(_Py3Utf8Stdout, self).__init__(
- buf,
- encoding='utf8',
- errors='strict'
- )
-
- def write(self, s):
- super(_Py3Utf8Stdout, self).write(s)
- self.flush()
-
- _py3_print = getattr(builtins, 'print')
- _py3_utf8_stdout = _Py3Utf8Stdout()
-
- def print_(*args, **kwargs):
- kwargs['file'] = _py3_utf8_stdout
- _py3_print(*args, **kwargs)
# Exception "constants" to support Python 2 through Python 3