Tool functions to support Python 2 and 3.

Inspired by six

TODO: since it is now based on six, we should remove this module eventually.


is_basestring(s) Return True for any string type (for str/unicode on Py2 and bytes/str on Py3).
is_bytes(s) Return True for bytestrings (for str on Py2 and bytes on Py3).
is_native(s) Return True for native strings (for str on Py2 and Py3).
is_unicode(s) Return True for unicode strings (for unicode on Py2 and str on Py3).
to_bytes(s[, encoding]) Convert unicode (text strings) to binary data (str on Py2 and bytes on Py3).
to_native(s[, encoding]) Convert data to native str type (bytestring on Py2 and unicode on Py3).
to_unicode(s[, encoding]) Convert binary data to unicode (text strings) on Python 2 and 3.
unicode_to_wsgi(u) Convert an environment variable to a WSGI ‘bytes-as-unicode’ string.
wsgi_to_bytes(s) Convert a native string to a WSGI / HTTP compatible byte string.

Other Members

BytesIO alias of StringIO.StringIO
PY2 bool(x) -> bool
PY3 bool(x) -> bool
StringIO StringIO([s]) – Return a StringIO-like stream for reading or writing
b_empty str(object=’‘) -> string
b_slash str(object=’‘) -> string
base64_decodebytes(s) Decode a string.
base64_encodebytes(s) Encode a string into multiple lines of base-64 data.
collections_abc This module implements specialized container datatypes providing alternatives to Python’s general purpose built-in containers, dict, list, set, and tuple.
console_input raw_input([prompt]) -> string
html_escape(s[, quote]) Replace special characters “&”, “<” and “>” to HTML-safe sequences.
queue A multi-producer, multi-consumer queue.
quote() Each part of a URL, e.g.
six Utilities for writing code that runs on Python 2 and 3
sys This module provides access to some objects used or maintained by the interpreter and to functions that interact strongly with the interpreter.
urlparse(url[, scheme, allow_fragments]) Parse a URL into 6 components: <scheme>://<netloc>/<path>;<params>?<query>#<fragment> Return a 6-tuple: (scheme, netloc, path, params, query, fragment).
xrange(stop) xrange(start, stop[, step]) -> xrange object