diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 02:59:59 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 02:59:59 +0000 |
commit | c9ef4ed560a5de28fce031882257b6741565284e (patch) | |
tree | 07afa40629447df997726efd4de84d5987ff5e50 /cli_helpers/compat.py | |
parent | Initial commit. (diff) | |
download | cli-helpers-upstream.tar.xz cli-helpers-upstream.zip |
Adding upstream version 2.3.1.upstream/2.3.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'cli_helpers/compat.py')
-rw-r--r-- | cli_helpers/compat.py | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/cli_helpers/compat.py b/cli_helpers/compat.py new file mode 100644 index 0000000..422403c --- /dev/null +++ b/cli_helpers/compat.py @@ -0,0 +1,56 @@ +# -*- coding: utf-8 -*- +"""OS and Python compatibility support.""" + +from decimal import Decimal +from types import SimpleNamespace +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.token import Token + from pygments.formatters.terminal256 import Terminal256Formatter +except ImportError: + HAS_PYGMENTS = False + Terminal256Formatter = None + Token = SimpleNamespace() + Token.Output = SimpleNamespace() + Token.Output.Header = None + Token.Output.OddRow = None + Token.Output.EvenRow = None + Token.Output.Null = None + Token.Output.TableSeparator = None + Token.Results = SimpleNamespace() + Token.Results.Header = None + Token.Results.OddRow = None + Token.Results.EvenRow = None + + +float_types = (float, Decimal) |