Module _cpcompat
source code
Compatibility code for using CherryPy with various versions of
Python.
CherryPy 3.2 is compatible with Python versions 2.3+. This module
provides a useful abstraction over the differences between Python
versions, sometimes by preferring a newer idiom, sometimes an older one,
and sometimes a custom one.
In particular, Python 2 uses str and '' for byte strings, while Python
3 uses str and '' for unicode strings. We will call each of these the
'native string' type for each version. Because of this major difference,
this module provides new 'bytestr', 'unicodestr', and 'nativestr'
attributes, as well as two functions: 'ntob', which translates native
strings (of type 'str') into byte strings regardless of Python version,
and 'ntou', which translates native strings to unicode strings. This also
provides a 'BytesIO' name for dealing specifically with bytes, and a
'StringIO' name for dealing with native strings. It also provides a
'base64_decode' function with native strings as input and output.
|
ntob(n,
encoding=' ISO-8859-1 ' )
Return the given native string as a byte string in the given
encoding. |
source code
|
|
|
ntou(n,
encoding=' ISO-8859-1 ' )
Return the given native string as a unicode string with the given
encoding. |
source code
|
|
|
tonative(n,
encoding=' ISO-8859-1 ' )
Return the given string as a native string in the given encoding. |
source code
|
|
|
base64_decode(n,
encoding=' ISO-8859-1 ' )
Return the native string base64-decoded (as a native string). |
source code
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
unquote_qs(atom,
encoding,
errors=' strict ' ) |
source code
|
|
|
|
|
py3k = False
|
|
_json_encode = json.JSONEncoder().iterencode
|
|
__package__ = ' cherrypy '
|