webapp-improved
webapp-improved copied to clipboard
Fixes issues with security.create_token() and Unicode problems
bytes, str, unicode, and basestring mean different
things to Python 2.5, 2.6, and 3.x.
Python 2.5
-
bytesis not available. -
stris a byte string. -
unicodeconverts to unicode string. -
basestringexists.
Python 2.6
-
bytesis available and maps to str -
stris a byte string. -
unicodeconverts to unicode string -
basestringexists.
Python 3.x
-
bytesis available and does not map tostr. -
strmaps to the earlierunicode, butunicodehas been removed. -
basestringhas been removed. -
unicodehas been removed
This patch adds portable support for all three versions of Python by adding a portable types module. All Unicode handling has been replaced to use the functions from this module and tests pass.
It introduces these portable types that you can use in your code:
-
byteswhere you need byte strings. -
unicode_stringwhere you need unicode strings - a few other utility functions that hide all the complications behind type checking therefore cleaning up the code base.
- The function create_token() can now accept a numerical base argument.
- All create_token() usages have been updated to return expected hexadecimal string.
- Tests have been added for decimals.
- All create_token() tests pass.
-
bytesis a Python 2.6+ type not available in Python 2.5. This patch fixes it with a suitable replacement.
webapp2 is still small, but it doesn't necessarily mean we can't use packages. All the existing tests pass without affecting any existing parent projects.
This patch ensures webapp2 can be easily ported to Python 3.x in the future as and when required.
Signed-off-by: Gora Khargosh [email protected]