wand.compat
— Compatibility layer¶
This module provides several subtle things to support multiple Python versions (2.6, 2.7, 3.3+) and VM implementations (CPython, PyPy).
-
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
- string (
-
wand.compat.
binary_type
¶ alias of
__builtin__.str
-
wand.compat.
encode_filename
(filename)¶ If
filename
is atext_type
, encode it tobinary_type
according to filesystem’s default encoding.
-
wand.compat.
file_types
= (<class 'io.RawIOBase'>, <type 'file'>)¶
-
wand.compat.
nested
(*args, **kwds)¶ Combine multiple context managers into a single nested context manager.
This function has been deprecated in favour of the multiple manager form of the with statement.
The one advantage of this function over the multiple manager form of the with statement is that argument unpacking allows it to be used with a variable number of context managers as follows:
- with nested(*managers):
- do_something()
-
wand.compat.
string_type
¶ alias of
__builtin__.basestring
-
wand.compat.
text
(string)¶ Makes
string
tostr
in Python 3. Does nothing in Python 2.Parameters: string ( bytes
,str
,unicode
) – a string to cast it totext_type
-
wand.compat.
text_type
¶ alias of
__builtin__.unicode
-
class
wand.compat.
xrange
(stop) → xrange object¶ xrange(start, stop[, step]) -> xrange object
Like range(), but instead of returning a list, returns an object that generates the numbers in the range on demand. For looping, this is slightly faster than range() and more memory efficient.