cherrypy._cpcompat.ntob, fails silently on u'str'

Derek Litz avatarDerek Litz created an issue

from cherrypy._cpcompat import ntob

test_non_native_str = u'unicode string'

ntob(test_non_native_str)

Out[75]: u'unicode string'

sys.version_info Out[76]: sys.version_info(major=2, minor=7, micro=2, releaselevel='final', serial=0)

Related is the usage of ntob in the SessionAuth class.

https://bitbucket.org/cherrypy/cherrypy/src/701f413a0d64/cherrypy/lib/cptools.py

See also:

https://groups.google.com/forum/?fromgroups#!topic/cherrypy-users/4UJR5GVfH_0

Comments (9)

  1. Jason R. Coombs

    So fumanchu said, "[ntob] should probably fail loudly if it receives a non-native string arg." That's easy to fix, but will probably trigger a new problem - where the failure will occur when username is unicode. I plan to put together a couple of tests to capture both aspects of the issue.

  2. Robert Brewer
    • changed status to open

    Thanks, Jason, for working on this. Unfortunately, I think we'd still like to support Python 3.0-3.2, which don't have support for the "u" prefix for string literals. So I think the changeset should be reworked. If a native string should always be encoded, then ntob is the right choice. If we want the login_screen method to accept either bytestrings or unicodestrings, then we'll have to do the hard work inside the function of detecting unicode args and encoding them.

  3. Log in to comment
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.