quetz-mod_python-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Apache Wiki <wikidi...@apache.org>
Subject [Mod_python Wiki] Trivial Update of "Cookie use with Classes" by MartinStoufer
Date Wed, 20 Dec 2006 17:50:51 GMT
Dear Wiki user,

You have subscribed to a wiki page or wiki category on "Mod_python Wiki" for change notification.

The following page has been changed by MartinStoufer:
http://wiki.apache.org/mod_python/Cookie_use_with_Classes

The comment on the change is:
Abstracted out secret string

------------------------------------------------------------------------------
  import types
  
  _tags = (1,2,3,4)
+ _secret = 'secret007'
  
  class Instance:
     def __init__(self, target, *args, **kwargs):
@@ -27, +28 @@

         return
  
     def __call__(self, req):
+        global _secret
         assert(type(self.__target) in [types.ClassType, types.TypeType])
         if not hasattr(req, 'session'):
            req.session = Session.Session(req)
         cookies = Cookie.get_cookies(req, Cookie.MarshalCookie,
-                                     secret='secret007')
+                                     secret=_secret)
         target = self.__target(*self.__args, **self.__kwargs)
         return util.apply_fs_data(target, req.form, req=req, cookies=cookies)
  
@@ -70, +72 @@

  
     def _do_cookies(self, req, cookies):
         # Handle Cookie now
+        global _secret
         if cookies and cookies.has_key('spam'):
             _spamcookie = cookies['spam']
  
@@ -85, +88 @@

             # MarshaCookie allows value to be any marshallable object
             _new_cookie_value = {'egg_count': 42, 'color': 'white'}
             Cookie.add_cookie(req,
-                    Cookie.MarshalCookie('spam', _new_cookie_value, 'secret007'))
+                    Cookie.MarshalCookie('spam', _new_cookie_value, _ssecret))
             self._output += ("\nSpam cookie not found, but we just set one!\n")
         return
  
@@ -98, +101 @@

  
  With the addition of the 'cookies' argument, we define a new method to handle the extraction/setting
of cookie information. From here, you can easily extend your code to customize cookie use.
  ----
- CategoryExamples CategoryExamples
+ CategoryExamples CategoryExamples CategoryExamples
  

Mime
View raw message