summaryrefslogtreecommitdiffstats
path: root/cli_helpers/compat.py
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2021-01-30 08:13:47 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2021-02-07 10:48:06 +0000
commit57bc0d56d7e741e1e99d96f14e7ab93232440a16 (patch)
tree0d4631d7416ba98b7a414dc825419afd5b177be0 /cli_helpers/compat.py
parentInitial commit. (diff)
downloadcli-helpers-57bc0d56d7e741e1e99d96f14e7ab93232440a16.tar.xz
cli-helpers-57bc0d56d7e741e1e99d96f14e7ab93232440a16.zip
Adding upstream version 2.1.0.upstream/2.1.0
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'cli_helpers/compat.py')
-rw-r--r--cli_helpers/compat.py42
1 files changed, 42 insertions, 0 deletions
diff --git a/cli_helpers/compat.py b/cli_helpers/compat.py
new file mode 100644
index 0000000..3f67c62
--- /dev/null
+++ b/cli_helpers/compat.py
@@ -0,0 +1,42 @@
+# -*- coding: utf-8 -*-
+"""OS and Python compatibility support."""
+
+from decimal import Decimal
+import sys
+
+PY2 = sys.version_info[0] == 2
+WIN = sys.platform.startswith('win')
+MAC = sys.platform == 'darwin'
+
+
+if PY2:
+ text_type = unicode
+ binary_type = str
+ long_type = long
+ int_types = (int, long)
+
+ from UserDict import UserDict
+ from backports import csv
+
+ from StringIO import StringIO
+ from itertools import izip_longest as zip_longest
+else:
+ text_type = str
+ binary_type = bytes
+ long_type = int
+ int_types = (int,)
+
+ from collections import UserDict
+ import csv
+ from io import StringIO
+ from itertools import zip_longest
+
+
+HAS_PYGMENTS = True
+try:
+ from pygments.formatters.terminal256 import Terminal256Formatter
+except ImportError:
+ HAS_PYGMENTS = False
+ Terminal256Formatter = None
+
+float_types = (float, Decimal)