summaryrefslogtreecommitdiff
path: root/cmd2.py
diff options
context:
space:
mode:
authorTodd Leonhardt <todd.leonhardt@gmail.com>2018-01-22 00:33:26 -0500
committerTodd Leonhardt <todd.leonhardt@gmail.com>2018-01-22 00:33:26 -0500
commit6c2cdf229dd62a957d7e27533725a9cc013db22e (patch)
treeb426400b79068713c75dc281112d7c80da16e328 /cmd2.py
parentf28c10a50535f753419bd2120ac6cb0bea9f56e2 (diff)
downloadcmd2-git-6c2cdf229dd62a957d7e27533725a9cc013db22e.tar.gz
redirect_stderr wasn't added to contextlib until Python 3.5
So it turns out that we need contextlib2 for Python 3.4 and earlier.
Diffstat (limited to 'cmd2.py')
-rwxr-xr-xcmd2.py10
1 files changed, 6 insertions, 4 deletions
diff --git a/cmd2.py b/cmd2.py
index c397bb7c..e77f4557 100755
--- a/cmd2.py
+++ b/cmd2.py
@@ -73,6 +73,12 @@ try:
except ImportError:
import subprocess
+# Python 3.4 and earlier require contextlib2 for temporarily redirecting stderr and stdout
+if sys.version_info < (3, 5):
+ from contextlib2 import redirect_stdout, redirect_stderr
+else:
+ from contextlib import redirect_stdout, redirect_stderr
+
# Detect whether IPython is installed to determine if the built-in "ipy" command should be included
ipython_available = True
try:
@@ -92,12 +98,8 @@ except ImportError:
# BrokenPipeError is only in Python 3. Use IOError for Python 2.
if six.PY3:
BROKEN_PIPE_ERROR = BrokenPipeError
-
- # redirect_stdout and redirect_stderr weren't added to contextlib until Python 3.4
- from contextlib import redirect_stdout, redirect_stderr
else:
BROKEN_PIPE_ERROR = IOError
- from contextlib2 import redirect_stdout, redirect_stderr
# On some systems, pyperclip will import gtk for its clipboard functionality.
# The following code is a workaround for gtk interfering with printing from a background