# on this file might be covered by the GNU General Public License.
"""
-Helpers for type checking and conversion, like isstr(x)
+Helpers for type checking and conversion, like isstr(x), is_file_obj(x)
.. codeauthor:: Christian Herdtweck, christian.herdtweck@intra2net.com
"""
from __future__ import print_function
import sys
+from io import IOBase
# determine python version
PY3 = sys.version_info.major == 3
return isinstance(var, str)
else:
return isinstance(var, basestring)
-# end: function isstr
+
+
+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)
+
+
+def is_file_obj(var):
+ """ determines whether given input is the result of 'open(file_name)'
+
+ just checks whether given var is subclass of io.IOBase, which is also True
+ for 'file-like objects' like StringIO
+ """
+ return isinstance(var, IOBase)
def test_isstr():