wand.compat
— Compatibility layer¶
This module provides several subtle things to support multiple Python versions (2.7, 3.3+) and VM implementations (CPython, PyPy).
- wand.compat.PY3 = True¶
(
bool
) Whether it is Python 3.x or not.
- wand.compat.abc = <module 'collections.abc' from '/usr/lib/python3.11/collections/abc.py'>¶
(
module
) Module containing abstract base classes.collections
in Python 2 andcollections.abc
in Python 3.
- wand.compat.binary(string, var=None)¶
Makes
string
tostr
in Python 2. Makesstring
tobytes
in Python 3.- Parameters:
string (
bytes
,str
,unicode
) – a string to cast it tobinary_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 andbytes
in Python 3.
- wand.compat.encode_filename(filename)¶
If
filename
is atext_type
, encode it tobinary_type
according to filesystem’s default encoding.Changed in version 0.5.3: Added support for PEP-519 https://github.com/emcconville/wand/pull/339
- wand.compat.file_types¶
(
type
,tuple
) Types for file objects that havefileno()
.
- wand.compat.string_type¶
(
type
) Type for text data.basestring
in Python 2 andstr
in Python 3.
- wand.compat.text_type¶
(
type
) Type for representing Unicode textual data.unicode
in Python 2 andstr
in Python 3.
- wand.compat.to_bytes(value, string_pattern='{0}')¶
Short-cut method to allow mixed value types to be converted to bytes.
- Parameters:
value (
basestring
,int
,float
) – Value to be cast to bytesstring_pattern (
basestring
) – String format to allow printf style control of bytes output.
New in version 0.6.4.