[Checkins] SVN: z3c.authenticator/trunk/ Bugfix: Did not handle unicode IUser.login values.

Adam Groszer agroszer at gmail.com
Wed Mar 31 03:58:34 EDT 2010


Log message for revision 110354:
  Bugfix: Did not handle unicode IUser.login values.

Changed:
  U   z3c.authenticator/trunk/CHANGES.txt
  U   z3c.authenticator/trunk/src/z3c/authenticator/README.txt
  U   z3c.authenticator/trunk/src/z3c/authenticator/user.py

-=-
Modified: z3c.authenticator/trunk/CHANGES.txt
===================================================================
--- z3c.authenticator/trunk/CHANGES.txt	2010-03-31 01:53:33 UTC (rev 110353)
+++ z3c.authenticator/trunk/CHANGES.txt	2010-03-31 07:58:34 UTC (rev 110354)
@@ -5,7 +5,7 @@
 0.9.0 (unreleased)
 ------------------
 
-- ...
+- Bugfix: Did not handle unicode IUser.login values.
 
 0.8.0 (2010-01-25)
 ------------------

Modified: z3c.authenticator/trunk/src/z3c/authenticator/README.txt
===================================================================
--- z3c.authenticator/trunk/src/z3c/authenticator/README.txt	2010-03-31 01:53:33 UTC (rev 110353)
+++ z3c.authenticator/trunk/src/z3c/authenticator/README.txt	2010-03-31 07:58:34 UTC (rev 110354)
@@ -521,3 +521,15 @@
 
   >>> authPlugin.getUserByLogin('migrateduser')
   <z3c.authenticator.user.User object at ...>
+
+
+Edge cases
+----------
+
+We can have Users with unicode login, as we allow this with TextLine in IUser.
+
+  >>> p = User(u'bob'+unichr(233), 'password', 'title')
+
+Adding it should not fail:
+
+  >>> uid, user = authPlugin.add(p)

Modified: z3c.authenticator/trunk/src/z3c/authenticator/user.py
===================================================================
--- z3c.authenticator/trunk/src/z3c/authenticator/user.py	2010-03-31 01:53:33 UTC (rev 110353)
+++ z3c.authenticator/trunk/src/z3c/authenticator/user.py	2010-03-31 07:58:34 UTC (rev 110354)
@@ -32,15 +32,19 @@
 
 # get the IP addresss only once
 try:
-  ip = socket.getaddrinfo(socket.gethostname(), 0)[-1][-1][0]
+    ip = socket.getaddrinfo(socket.gethostname(), 0)[-1][-1][0]
 except:
-  ip = '127.0.0.1'
+    ip = '127.0.0.1'
 
 def generateUserIDToken(id):
     """Generates a unique user id token."""
     t = long(time.time() * 1000)
     r = long(random.random()*100000000000000000L)
-    data = str(ip)+' '+str(t)+' '+str(r)+' '+str(id)
+    try:
+        id = str(id)
+    except UnicodeEncodeError:
+        id = id.encode('utf-8')
+    data = str(ip)+' '+str(t)+' '+str(r)+' '+id
     return unicode(md5.md5(data).hexdigest())
 
 



More information about the checkins mailing list