New submission from Nuno Teixeira <tei...@gmail.com>:

I think that encoding cookies data could be useful. My usecase is related with 
SQLAlchemy that avoid the use of non-unicode strings on queries.

----------
files: r9728.diff
messages: 426
nosy: nteixeira
priority: feature
status: unread
title: Support encoding of cookies on repoze.who cookie plugin
topic: repoze.who

__________________________________
Repoze Bugs <b...@bugs.repoze.org>
<http://bugs.repoze.org/issue155>
__________________________________
Index: repoze/who/plugins/cookie.py
===================================================================
--- repoze/who/plugins/cookie.py	(revision 9728)
+++ repoze/who/plugins/cookie.py	(working copy)
@@ -10,9 +10,10 @@
 
     implements(IIdentifier)
     
-    def __init__(self, cookie_name, cookie_path='/'):
+    def __init__(self, cookie_name, cookie_path='/', charset=None):
         self.cookie_name = cookie_name
         self.cookie_path = cookie_path
+        self.charset = charset
 
     # IIdentifier
     def identify(self, environ):
@@ -29,7 +30,11 @@
 
         try:
             login, password = auth.split(':', 1)
-            return {'login':login, 'password':password}
+            if self.charset is None:
+                return {'login':login, 'password':password}
+            else:
+                return {'login': login.decode(self.charset),
+                        'password': password.decode(self.charset)}
         except ValueError: # not enough values to unpack
             return None
 
@@ -44,6 +49,8 @@
     def remember(self, environ, identity):
         cookie_value = '%(login)s:%(password)s' % identity
         cookie_value = cookie_value.encode('base64').rstrip()
+        if self.charset:
+            cookie_value = cookie_value.encode(self.charset)
         cookies = get_cookies(environ)
         existing = cookies.get(self.cookie_name)
         value = getattr(existing, 'value', None)
@@ -57,7 +64,8 @@
         return '<%s %s>' % (self.__class__.__name__,
                             id(self)) #pragma NO COVERAGE
 
-def make_plugin(cookie_name='repoze.who.plugins.cookie', cookie_path='/'):
-    plugin = InsecureCookiePlugin(cookie_name, cookie_path)
+def make_plugin(cookie_name='repoze.who.plugins.cookie', cookie_path='/',
+                charset=None):
+    plugin = InsecureCookiePlugin(cookie_name, cookie_path, charset)
     return plugin
 
_______________________________________________
Repoze-dev mailing list
Repoze-dev@lists.repoze.org
http://lists.repoze.org/listinfo/repoze-dev

Reply via email to