[Twisted-Python] Twisted cred perspective unicode support
I got problems using Twisted cred with Python2.2.0. My perspectives names are based on a url encoding. I have found that there is a problem when PerspectiveName is unicode. I also discovered that the error message is not explicative. The CVS does not have a solution for this problems. Both diminute problem are solved in the next patch. Twisted is a great tool. Thanks you for Twisted. RodrigoB. - Post patch for twisted.cred.perspective (Type -> Types, report error type): the cause: ---------- import types isinstance(u"/test1", types.StringType) =>0 The patch: ---------- class Perspective: """I am an Identity's view onto a service. I am the interface through which most 'external' code should interact with a service; I represent the actions a user may perform upon a service, and the state associated with that user for that service. """ _service_cached = 0 # Has my service cached me from a loaded store, or do I live in memory usually? def __init__(self, perspectiveName, identityName="Nobody"): """Create me. I require a name for myself and a reference to the service I participate in. (My identity name will be 'Nobody' by default, which will normally not resolve.) """ if not isinstance(perspectiveName, types.StringTypes): raise TypeError("Expected string, got '%s' (%s)."% (perspectiveName, type(perspectiveName))) if not isinstance(identityName, types.StringTypes): raise TypeError("Expected string, got '%s' (%s)."% (identityName, type(identityName))) self.perspectiveName = perspectiveName self.identityName = identityName The diff --------- $ diff perspective.py /usr/local/lib/python2.2/site-packages/twisted/cred/perspective.py 49,52c49,52 < if not isinstance(perspectiveName, types.StringType): < raise TypeError("Expected string, got %s."% perspectiveName) < if not isinstance(identityName, types.StringType): < raise TypeError("Expected string, got %s."% identityName) ---
if not isinstance(perspectiveName, types.StringTypes): raise TypeError("Expected string, got '%s' (%s)."% (perspectiveName, type(perspectiveName))) if not isinstance(identityName, types.StringTypes): raise TypeError("Expected string, got '%s' (%s)."% (identityName, type(identityName)))
<rdrb@123.cl> writes:
I got problems using Twisted cred with Python2.2.0. My perspectives names are based on a url encoding. I have found that there is a problem when PerspectiveName is unicode.
I've committed your fix into CVS, along with some new test cases. Thanks for the patch! I did some other s/types.StringType/types.StringTypes/ elsewhere in twisted.cred.perspective too. thanks, -Brian
On Mon, 16 Jun 2003 14:51:06 -0700 (PDT) Brian Warner <warner@lothar.com> wrote:
I got problems using Twisted cred with Python2.2.0. My perspectives names are based on a url encoding. I have found that there is a problem when PerspectiveName is unicode.
I've committed your fix into CVS, along with some new test cases. Thanks for the patch!
The patch should probably be reverted. The perspective name etc. should always be a string because the storage you use for it may have no notion of unicode. If you want to use unicode there they should just be UTF-8ed anyway. However, we now have a new cred, so this doesn't really matter. But, you shouldn't be making *any* changes to old cred if at all possible. Any uses cases should be made to fit new cred. In new cred, avatar ids *must* be 8-bit strings. For a username a user might type in, i.e. credentials, you could write a specific credentials interface that supports unicode credentials and an associated checker. -- Itamar Shtull-Trauring http://itamarst.org/ http://www.zoteca.com -- Python & Twisted consulting
The patch should probably be reverted. The perspective name etc. should always be a string because the storage you use for it may have no notion of unicode. If you want to use unicode there they should just be UTF-8ed anyway.
*nod*. I've just reverted it. Sorry RodrigoB, look to itamar's suggestions for some possibilities. thanks, -Brian
participants (3)
-
Brian Warner
-
Itamar Shtull-Trauring
-
rdrb@123.cl