Library of common python code for Intra2net
+Target: python3.3+
+
To create a source tar.gz and spec file, run
./make_dist.sh
This uses python distutils with info in setup.py.
echo "" >> ./pyi2ncommon.spec
echo "%check" >> ./pyi2ncommon.spec
#echo "echo \"unittests disabled for now...\"" >> ./pyi2ncommon.spec
-echo "PYTHONPATH=./src:\$PYTHONPATH && python2 -m unittest discover test" >> ./pyi2ncommon.spec
echo "PYTHONPATH=./src:\$PYTHONPATH && python3 -m unittest discover test" >> ./pyi2ncommon.spec
mv ./pyi2ncommon.spec dist/
#!/bin/sh
-# run unittest suite using python2 and python3
+# run unittest suite using python3
# The software in this package is distributed under the GNU General
# Public License version 2 (with a special exception described below).
#
# Copyright (c) 2016-2018 Intra2net AG <info@intra2net.com>
-python2 -m unittest discover test && python3 -m unittest discover test
+python3 -m unittest discover test
# 'doc/index.rst', 'doc/modules.rst', 'doc/conf.py',
# 'doc/about_docu.rst'],
license='GPLv2 + linking exception',
+ classifiers=[
+ "Programming Language :: Python :: 3",
+ "Operating System :: OS Independent",
+ ],
)
-------------------------------------------------------------------------------
"""
-from __future__ import print_function
-
import functools
import sys
import json
* https://en.wikipedia.org/wiki/ANSI_escape_code
"""
-from __future__ import print_function
-
try:
from builtins import print as _builtin_print
except ImportError: # different name in py2
"""
Helpers for type checking and conversion, like isstr(x), is_file_obj(x)
-
-Provides abstraction from difference between PY2 and PY3
"""
-from __future__ import print_function
import sys
from io import IOBase
-# determine python version
-PY3 = sys.version_info.major == 3
-PY2 = sys.version_info.major == 2
-
def isstr(var):
""" determines if the given var is a (regular/unicode/raw) string or not
(https://pythonhosted.org/six)
"""
- if PY3:
- return isinstance(var, str)
- else:
- return isinstance(var, basestring)
+ return isinstance(var, str)
def is_str_or_byte(var):
""" returns true for str, unicode and byte objects """
- if PY3:
- return isinstance(var, (str, bytes))
- else:
- return isinstance(var, basestring)
+ return isinstance(var, (str, bytes))
def is_unicode(var):
py2: return True for type unicode but not type str
py3: return True for type str but not type bytes
"""
-
- if PY2:
- return isinstance(var, unicode)
- else:
- return isinstance(var, str)
+ return isinstance(var, str)
def is_file_obj(var):
just checks whether given var is subclass of io.IOBase, which is also True
for 'file-like objects' like StringIO
"""
- return isinstance(var, IOBase) or (PY2 and isinstance(var, file))
-
-
-def main():
- """ Main function, called when running file as script
-
- just tells you what python version you are running (2 or 3)
- """
- if PY3:
- print('is python3')
- else:
- print('is python2')
-# end: function main
-
-
-if __name__ == '__main__':
- main()
+ return isinstance(var, IOBase)
.. warning:: This is a warning
"""
-from __future__ import print_function
-
THE_CONSTANT = None
"""Some constant with docstring *AFTER* the constant."""
For help see :py:mod:`unittest`
"""
-from __future__ import print_function
-from __future__ import absolute_import
-
import unittest
# relative import of tested module ensures we do not test installed version
For help see :py:mod:`unittest`
"""
-from __future__ import absolute_import
-
import unittest
from math import log, floor
Creates own thread to write data to a log file
"""
-from __future__ import absolute_import
-
import unittest
from threading import Thread
from tempfile import mkstemp
For help see :py:mod:`unittest`
"""
-from __future__ import absolute_import
-
import unittest
from src.text_helpers import *
For help see :py:mod:`unittest`
"""
-from __future__ import absolute_import
-
import unittest
from src.type_helpers import is_unicode, isstr