The pyramid.compat module provides platform and version compatibility for Pyramid and its add-ons across Python platform and version differences. APIs will be removed from this module over time as Pyramid ceases to support systems which require compatibility imports.
Python 3: If s is an instance of text_type, return s.encode('ascii'), otherwise return str(s, 'ascii', 'strict')
Python 2: If s is an instance of text_type, return s.encode('ascii'), otherwise return str(s)
Binary type for this platform. For Python 3, it’s bytes. For Python 2, it’s str.
If s is an instance of text_type, return s.encode(encoding, errors), otherwise return s
Sequence of class types for this platform. For Python 3, it’s (type,). For Python 2, it’s (type, types.ClassType).
On Python 2, the ConfigParser module, on Python 3, the configparser module.
On Python 2, the cgi.escape function, on Python 3, the html.escape function.
On Python 2, the string value im_func, on Python 3, the string value __func__.
On Python 2, the raw_input function, on Python 3, the input function.
Sequence of integer types for this platform. For Python 3, it’s (int,). For Python 2, it’s (int, long).
Long type for this platform. For Python 3, it’s int. For Python 2, it’s long.
cPickle module if it exists, pickle module otherwise.
True if running on Python 3, False otherwise.
True if running on PyPy, False otherwise.
Reraise an exception in a compatible way on both Python 2 and Python 3, e.g. reraise(*sys.exc_info()).
Sequence of string types for this platform. For Python 3, it’s (str,). For Python 2, it’s (basestring,).
On Python 2, the Cookie.SimpleCookie class, on Python 3, the http.cookies.SimpleCookie module.
If s is an instance of binary_type, return s.decode(encoding, errors), otherwise return s
Text type for this platform. For Python 3, it’s str. For Python 2, it’s unicode.
Python 3: If s is an instance of text_type, return s, otherwise return str(s, encoding, errors)
Python 2: If s is an instance of text_type, return s.encode(encoding, errors), otherwise return str(s)
urlparse module on Python 2, urllib.parse module on Python 3.
urllib.quote function on Python 2, urllib.parse.quote function on Python 3.
urllib.quote_plus function on Python 2, urllib.parse.quote_plus function on Python 3.
urllib.unquote function on Python 2, urllib.parse.unquote function on Python 3.
urllib.urlencode function on Python 2, urllib.parse.urlencode function on Python 3.
urllib2.urlopen function on Python 2, urllib.request.urlopen function on Python 3.