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 oftext_type
, returns.encode('ascii')
, otherwise returnstr(s, 'ascii', 'strict')
Python 2: If
s
is an instance oftext_type
, returns.encode('ascii')
, otherwise returnstr(s)
-
binary_type
¶ Binary type for this platform. For Python 3, it’s
bytes
. For Python 2, it’sstr
.
-
bytes_
(s, encoding='latin-1', errors='strict')[source]¶ If
s
is an instance oftext_type
, returns.encode(encoding, errors)
, otherwise returns
-
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, theconfigparser
module.
-
exec_
(code, globs=None, locs=None)¶ 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, theinput
function.
-
integer_types
¶ Sequence of integer types for this platform. For Python 3, it’s
(int,)
. For Python 2, it’s(int, long)
.
-
long
¶ Long type for this platform. For Python 3, it’s
int
. For Python 2, it’slong
.
-
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
[source]¶ On Python 2, the
Cookie.SimpleCookie
class, on Python 3, thehttp.cookies.SimpleCookie
module.
-
text_
(s, encoding='latin-1', errors='strict')[source]¶ If
s
is an instance ofbinary_type
, returns.decode(encoding, errors)
, otherwise returns
-
text_type
¶ Text type for this platform. For Python 3, it’s
str
. For Python 2, it’sunicode
.
-
native_
(s, encoding='latin-1', errors='strict')[source]¶ Python 3: If
s
is an instance oftext_type
, returns
, otherwise returnstr(s, encoding, errors)
Python 2: If
s
is an instance oftext_type
, returns.encode(encoding, errors)
, otherwise returnstr(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')¶ On Python 2, return
url_unquote(v).decode(encoding(encoding, errors))
; on Python 3, return the result ofurllib.parse.unquote
.
-
url_unquote_native
(v, encoding='utf-8', errors='replace')¶ On Python 2, return
native_(url_unquote_text_v, encoding, errors))
; on Python 3, return the result ofurllib.parse.unquote
.