libearth.compat
— Compatibility layer¶
This module provides several subtle things to support multiple Python versions (2.6, 2.7, 3.2, 3.3) and VM implementations (CPython, PyPy).
-
libearth.compat.
UNICODE_BY_DEFAULT
= False¶ (
bool
) Whether the Python VM uses Unicode strings by default. It must beTrue
ifPY3
or IronPython.
-
libearth.compat.
binary
(string, var=None)¶ Makes
string
tostr
in Python 2. Makesstring
tobytes
in Python 3 or IronPython.Parameters: - string (
bytes
,str
,unicode
) – a string to cast it tobinary_type
- var (
str
) – an optional variable name to be used for error message
- string (
-
libearth.compat.
binary_type
¶ (
type
) Type for representing binary data.str
in Python 2 andbytes
in Python 3.alias of
str
-
libearth.compat.
encode_filename
(filename)¶ If
filename
is atext_type
, encode it tobinary_type
according to filesystem’s default encoding.
-
libearth.compat.
file_types
= (<class 'io.RawIOBase'>, <type 'file'>)¶
-
libearth.compat.
string_type
¶ (
type
) Type for text data.basestring
in Python 2 andstr
in Python 3.alias of
basestring
-
libearth.compat.
text
(string)¶ Makes
string
tostr
in Python 3 or IronPython. Does nothing in Python 2.Parameters: string ( bytes
,str
,unicode
) – a string to cast it totext_type