Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes issues with security.create_token() and Unicode problems #4

Open
wants to merge 11 commits into
base: master
Choose a base branch
from

Conversation

gorakhargosh
Copy link
Contributor

bytes, str, unicode, and basestring mean different
things to Python 2.5, 2.6, and 3.x.

Python 2.5

  • bytes is not available.
  • str is a byte string.
  • unicode converts to unicode string.
  • basestring exists.

Python 2.6

  • bytes is available and maps to str
  • str is a byte string.
  • unicode converts to unicode string
  • basestring exists.

Python 3.x

  • bytes is available and does not map to str.
  • str maps to the earlier unicode, but unicode has been removed.
  • basestring has been removed.
  • unicode has 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:

  • bytes where you need byte strings.
  • unicode_string where 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.
  • bytes is 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]

* The function can now accept a numerical base argument.
* All usages have been updated to return expected
  hexadecimal string.
* Tests have been added for decimals.
* All create_token() tests pass.
* ``bytes`` is a Python 2.6+ type not available
  in Python 2.5. This patch fixes it with a suitable
  replacement.

Signed-off-by: Gora Khargosh <[email protected]>
Signed-off-by: Gora Khargosh <[email protected]>
* You cannot name a module "json" and import "json"
  from within it. This import test had been failing
  all this time. The module has been renamed to
  "escape" for all the tests to work.

* Stray modules (also because they are named "json")
  can pollute the Python namespace and cause our
  imports to fail. We're expecting Python's json
  module, but we can end up receiving a stray
  module named json. Therefore, we test whether
  we're using Python's module.

* All tests now pass.

Signed-off-by: Gora Khargosh <[email protected]>
* Everything in a single module seems fine for a start
  but gets unweildy very fast.

Signed-off-by: Gora Khargosh <[email protected]>
Signed-off-by: Gora Khargosh <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant