Documentation in progress Edit me on GitHub

pyramid.compat

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.

ascii_native_(s)[source]

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

Binary type for this platform. For Python 3, it's bytes. For Python 2, it's str.

bytes_(s, encoding='latin-1', errors='strict')[source]

If s is an instance of text_type, return s.encode(encoding, errors), otherwise return s

class_types

Sequence of class types for this platform. For Python 3, it's (type,). For Python 2, it's (type, types.ClassType).

configparser

On Python 2, the ConfigParser module, on Python 3, the configparser module.

escape(v)

On Python 2, the cgi.escape function, on Python 3, the html.escape function.

exec_(code, globs=None, locs=None)[source]

Exec code in a compatible way on both Python 2 and 3.

im_func

On Python 2, the string value im_func, on Python 3, the string value __func__.

input_(v)

On Python 2, the raw_input function, on Python 3, the input function.

integer_types

Sequence of integer types for this platform. For Python 3, it's (int,). For Python 2, it's (int, long).

is_nonstr_iter(v)[source]

Return True if v is a non-str iterable on both Python 2 and Python 3.

iteritems_(d)[source]

Return d.items() on Python 3, d.iteritems() on Python 2.

itervalues_(d)[source]

Return d.values() on Python 3, d.itervalues() on Python 2.

iterkeys_(d)[source]

Return d.keys() on Python 3, d.iterkeys() on Python 2.

long

Long type for this platform. For Python 3, it's int. For Python 2, it's long.

map_(v)[source]

Return list(map(v)) on Python 3, map(v) on Python 2.

pickle

cPickle module if it exists, pickle module otherwise.

PY3

True if running on Python 3, False otherwise.

PYPY

True if running on PyPy, False otherwise.

reraise(tp, value, tb=None)[source]

Reraise an exception in a compatible way on both Python 2 and Python 3, e.g. reraise(*sys.exc_info()).

string_types

Sequence of string types for this platform. For Python 3, it's (str,). For Python 2, it's (basestring,).

SimpleCookie

On Python 2, the Cookie.SimpleCookie class, on Python 3, the http.cookies.SimpleCookie module.

text_(s, encoding='latin-1', errors='strict')[source]

If s is an instance of binary_type, return s.decode(encoding, errors), otherwise return s

text_type

Text type for this platform. For Python 3, it's str. For Python 2, it's unicode.

native_(s, encoding='latin-1', errors='strict')[source]

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

urlparse module on Python 2, urllib.parse module on Python 3.

url_quote

urllib.quote function on Python 2, urllib.parse.quote function on Python 3.

url_quote_plus

urllib.quote_plus function on Python 2, urllib.parse.quote_plus function on Python 3.

url_unquote

urllib.unquote function on Python 2, urllib.parse.unquote function on Python 3.

url_encode

urllib.urlencode function on Python 2, urllib.parse.urlencode function on Python 3.

url_open

urllib2.urlopen function on Python 2, urllib.request.urlopen function on Python 3.

url_unquote_text(v, encoding='utf-8', errors='replace')[source]

On Python 2, return url_unquote(v).decode(encoding(encoding, errors)); on Python 3, return the result of urllib.parse.unquote.

url_unquote_native(v, encoding='utf-8', errors='replace')[source]

On Python 2, return native_(url_unquote_text_v, encoding, errors)); on Python 3, return the result of urllib.parse.unquote.

Previous topic

pyramid.authorization

Next topic

pyramid.config