wand.compat — Compatibility layer

This module provides several subtle things to support multiple Python versions (2.6, 2.7, 3.2–3.5) and VM implementations (CPython, PyPy).

wand.compat.PY3 = True

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

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

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

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
wand.compat.binary_type

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

alias of bytes

wand.compat.encode_filename(filename)

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

wand.compat.file_types

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

alias of RawIOBase

wand.compat.string_type

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

alias of str

wand.compat.text_type

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

alias of str

wand.compat.xrange

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

alias of range