Previous topic

libearth.codecs — Common codecs

Next topic

libearth.compat.etree — ElementTree compatibility layer

This Page

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.IRON_PYTHON = False

(bool) Whether it is IronPython or not.

libearth.compat.PY3 = False

(bool) Whether it is Python 3.x or not.

libearth.compat.UNICODE_BY_DEFAULT = False

(bool) Whether the Python VM uses Unicode strings by default. It must be True if PY3 or IronPython.

libearth.compat.binary(string, var=None)

Makes string to str in Python 2. Makes string to bytes in Python 3 or IronPython.

Parameters:
  • string (bytes, str, unicode) – a string to cast it to binary_type
  • var (str) – an optional variable name to be used for error message
libearth.compat.binary_type

(type) Type for representing binary data. str in Python 2 and bytes in Python 3.

alias of str

libearth.compat.encode_filename(filename)

If filename is a text_type, encode it to binary_type according to filesystem’s default encoding.

libearth.compat.file_types = (<class 'io.RawIOBase'>, <type 'file'>)

(type, tuple) Types for file objects that have fileno().

libearth.compat.string_type

(type) Type for text data. basestring in Python 2 and str in Python 3.

alias of basestring

libearth.compat.text(string)

Makes string to str in Python 3 or IronPython. Does nothing in Python 2.

Parameters:string (bytes, str, unicode) – a string to cast it to text_type
libearth.compat.text_type

(type) Type for representing Unicode textual data. unicode in Python 2 and str in Python 3.

alias of unicode

class libearth.compat.xrange

The xrange() function. Alias for range() in Python 3.

Fork me on GitHub