[Checkins] SVN: z3ext.cacheheaders/trunk/ Added AfterCallEvent event

Nikolay Kim fafhrd91 at gmail.com
Tue Aug 11 03:28:41 EDT 2009


Log message for revision 102635:
  Added AfterCallEvent event

Changed:
  U   z3ext.cacheheaders/trunk/CHANGES.txt
  U   z3ext.cacheheaders/trunk/setup.py
  U   z3ext.cacheheaders/trunk/src/z3ext/cacheheaders/interfaces.py
  U   z3ext.cacheheaders/trunk/src/z3ext/cacheheaders/publication.py
  U   z3ext.cacheheaders/trunk/src/z3ext/cacheheaders/staticcache.py

-=-
Modified: z3ext.cacheheaders/trunk/CHANGES.txt
===================================================================
--- z3ext.cacheheaders/trunk/CHANGES.txt	2009-08-10 20:57:09 UTC (rev 102634)
+++ z3ext.cacheheaders/trunk/CHANGES.txt	2009-08-11 07:28:40 UTC (rev 102635)
@@ -2,6 +2,12 @@
 CHANGES
 =======
 
+1.1.0 (Unreleased)
+------------------
+
+- Added AfterCallEvent event
+
+
 1.0.3 (2009-04-17)
 ------------------
 

Modified: z3ext.cacheheaders/trunk/setup.py
===================================================================
--- z3ext.cacheheaders/trunk/setup.py	2009-08-10 20:57:09 UTC (rev 102634)
+++ z3ext.cacheheaders/trunk/setup.py	2009-08-11 07:28:40 UTC (rev 102635)
@@ -22,7 +22,7 @@
     return open(os.path.join(os.path.dirname(__file__), *rnames)).read()
 
 
-version = '1.0.4dev'
+version = '1.1.0dev'
 
 
 setup(name='z3ext.cacheheaders',
@@ -54,13 +54,13 @@
       package_dir = {'':'src'},
       namespace_packages=['z3ext'],
       install_requires = ['setuptools',
-			  'zope.proxy',
+                          'zope.proxy',
                           'zope.event',
                           'zope.schema',
-			  'zope.datetime',
+                          'zope.datetime',
                           'zope.component',
                           'zope.interface',
-			  'zope.publisher',
+                          'zope.publisher',
                           'zope.dublincore',
                           'zope.cachedescriptors',
                           'zope.app.publication',

Modified: z3ext.cacheheaders/trunk/src/z3ext/cacheheaders/interfaces.py
===================================================================
--- z3ext.cacheheaders/trunk/src/z3ext/cacheheaders/interfaces.py	2009-08-10 20:57:09 UTC (rev 102634)
+++ z3ext.cacheheaders/trunk/src/z3ext/cacheheaders/interfaces.py	2009-08-11 07:28:40 UTC (rev 102635)
@@ -16,8 +16,23 @@
 $Id$
 """
 from zope import schema, interface
+from zope.component.interfaces import IObjectEvent
 
 
+class IAfterCallEvent(IObjectEvent):
+    """ after call event """
+
+    request = interface.Attribute('Request')
+
+
+class AfterCallEvent(object):
+    interface.implements(IAfterCallEvent)
+
+    def __init__(self, object, request):
+        self.object = object
+        self.request = request
+
+
 class IModificationInfo(interface.Interface):
 
     def modified():

Modified: z3ext.cacheheaders/trunk/src/z3ext/cacheheaders/publication.py
===================================================================
--- z3ext.cacheheaders/trunk/src/z3ext/cacheheaders/publication.py	2009-08-10 20:57:09 UTC (rev 102634)
+++ z3ext.cacheheaders/trunk/src/z3ext/cacheheaders/publication.py	2009-08-11 07:28:40 UTC (rev 102635)
@@ -18,6 +18,8 @@
 from types import MethodType
 from datetime import datetime
 
+import transaction
+
 from zope import interface
 from zope.event import notify
 from zope.component import queryUtility
@@ -27,10 +29,11 @@
 from zope.publisher.browser import BrowserRequest
 
 from zope.app.publication import browser
+from zope.app.publication import zopepublication
 from zope.app.publication.interfaces import IBrowserRequestFactory
 from zope.app.publication.interfaces import IRequestPublicationFactory
 
-from interfaces import ICacheStrategy
+from interfaces import ICacheStrategy, AfterCallEvent
 
 
 class BrowserPublication(browser.BrowserPublication):
@@ -79,3 +82,16 @@
         request_class = queryUtility(
             IBrowserRequestFactory, default=BrowserRequest)
         return request_class, BrowserPublication
+
+
+def afterCall(self, request, ob):
+    notify(AfterCallEvent(ob, request))
+
+    txn = transaction.get()
+    if txn.isDoomed():
+        txn.abort()
+    else:
+        self.annotateTransaction(txn, request, ob)
+        txn.commit()
+
+zopepublication.ZopePublication.afterCall = afterCall

Modified: z3ext.cacheheaders/trunk/src/z3ext/cacheheaders/staticcache.py
===================================================================
--- z3ext.cacheheaders/trunk/src/z3ext/cacheheaders/staticcache.py	2009-08-10 20:57:09 UTC (rev 102634)
+++ z3ext.cacheheaders/trunk/src/z3ext/cacheheaders/staticcache.py	2009-08-11 07:28:40 UTC (rev 102635)
@@ -35,8 +35,8 @@
         return StaticCache(context, info)
     else:
         return None
-    
 
+
 class StaticCache(object):
     interface.implements(IStaticCacheStrategy)
 
@@ -63,7 +63,7 @@
             header = header.split(';')[0]
             try:    mod_since=long(timeFromDateTimeString(header))
             except: mod_since=None
-            
+
             if mod_since is not None:
                 lmt = self.info.modified()
                 if lmt > 0 and lmt <= mod_since:
@@ -86,12 +86,12 @@
         t = time.time() + self.maxage
 
         response.setHeader(
-            'Expires', time.strftime("%a, %d %b %Y %H:%M:%S GMT", 
+            'Expires', time.strftime("%a, %d %b %Y %H:%M:%S GMT",
                                      time.gmtime(t)))
 
         if not response.getHeader('Last-Modified', None):
             year, month, day, hh, mm, ss, wd, y, z = time.localtime(modified)
-            
+
             lmod = "%s, %02d %3s %4d %02d:%02d:%02d GMT" % (weekday_abbr[wd],
                                                             day, monthname[month],
                                                             year, hh, mm, ss)



More information about the Checkins mailing list