[Checkins] SVN: z3ext.cacheheaders/trunk/ use latest zope packages; update tests
Nikolay Kim
fafhrd91 at gmail.com
Tue Dec 22 18:19:09 EST 2009
Log message for revision 106963:
use latest zope packages; update tests
Changed:
U z3ext.cacheheaders/trunk/CHANGES.txt
U z3ext.cacheheaders/trunk/setup.py
D z3ext.cacheheaders/trunk/src/z3ext/cacheheaders/README.txt
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/tests.py
A z3ext.cacheheaders/trunk/src/z3ext/cacheheaders/tests.txt
-=-
Modified: z3ext.cacheheaders/trunk/CHANGES.txt
===================================================================
--- z3ext.cacheheaders/trunk/CHANGES.txt 2009-12-22 22:33:52 UTC (rev 106962)
+++ z3ext.cacheheaders/trunk/CHANGES.txt 2009-12-22 23:19:09 UTC (rev 106963)
@@ -2,6 +2,12 @@
CHANGES
=======
+1.3.0 (Unreleased)
+------------------
+
+- ZTK support
+
+
1.2.0 (2009-11-24)
------------------
Modified: z3ext.cacheheaders/trunk/setup.py
===================================================================
--- z3ext.cacheheaders/trunk/setup.py 2009-12-22 22:33:52 UTC (rev 106962)
+++ z3ext.cacheheaders/trunk/setup.py 2009-12-22 23:19:09 UTC (rev 106963)
@@ -31,8 +31,6 @@
'Detailed Dcoumentation\n' +
'======================\n'
+ '\n\n' +
- read('src', 'z3ext', 'cacheheaders', 'README.txt')
- + '\n\n' +
read('CHANGES.txt')
),
classifiers=[
@@ -47,7 +45,7 @@
'Framework :: Zope3'],
author='Nikolay Kim',
author_email='fafhrd91 at gmail.com',
- url='http://z3ext.net/',
+ url='http://pypi.python.org/pypi/z3ext.cacheheaders/',
license='ZPL 2.1',
packages=find_packages('src'),
package_dir = {'':'src'},
@@ -64,11 +62,11 @@
'zope.cachedescriptors',
'zope.app.publication',
],
- extras_require = dict(test=['zope.app.testing',
- 'zope.testing',
+ extras_require = dict(test=['zope.testing',
'zope.traversing',
'zope.security',
- 'zope.app.security',
+ 'zope.authentication',
+ 'zope.principalregistry',
]),
include_package_data = True,
zip_safe = False
Deleted: z3ext.cacheheaders/trunk/src/z3ext/cacheheaders/README.txt
===================================================================
--- z3ext.cacheheaders/trunk/src/z3ext/cacheheaders/README.txt 2009-12-22 22:33:52 UTC (rev 106962)
+++ z3ext.cacheheaders/trunk/src/z3ext/cacheheaders/README.txt 2009-12-22 23:19:09 UTC (rev 106963)
@@ -1,164 +0,0 @@
-=======================
-Browser caching headers
-=======================
-
-`Publication` with support `304` response code
-
- >>> import time, datetime, pytz
- >>> from zope import component, interface
- >>> from z3ext.cacheheaders import interfaces
-
- >>> from z3ext.cacheheaders.publication import \
- ... BrowserFactory, BrowserPublication
-
- >>> factory = BrowserFactory()
- >>> factory.canHandle({})
- True
-
- >>> rclass, pclass = factory()
- >>> pclass == BrowserPublication
- True
-
- >>> pub = BrowserPublication(None)
-
- >>> from zope.publisher.browser import TestRequest
- >>> from zope.publisher.interfaces.http import IHTTPRequest
-
- >>> request = TestRequest()
- >>> response = request.response
-
- >>> request.setPublication(pub)
-
-We need object
-
- >>> class IContent(interface.Interface):
- ... pass
-
- >>> class Content(object):
- ... interface.implements(IContent)
- ... marker = 0
- ...
- ... def __call__(self):
- ... self.marker = 1
- ... return 'Content body'
-
- >>> ob = Content()
-
- >>> print pub.callObject(request, ob)
- Content body
-
-
-If we want control caching headers we need define ICacheStrategy adapter.
-this package predefine some cache strategies. Simplest is StatusCache, it's
-base on object modification date (IModificationInfo interface)
-So to use static cache fist we need IModificationInfo adapter
-
- >>> from z3ext.cacheheaders.staticcache import getStaticCache
- >>> getStaticCache(ob) is None
- True
-
- >>> class ModInfo(object):
- ... interface.implements(interfaces.IModificationInfo)
- ... component.adapts(IContent)
- ...
- ... dt = datetime.datetime(2007, 10, 10, 0, 0, 0, 0, tzinfo=pytz.utc)
- ...
- ... def __init__(self, context):
- ... self.context = context
- ...
- ... def modified(self):
- ... return long(time.mktime(self.dt.utctimetuple()))
-
- >>> component.provideAdapter(ModInfo)
-
- >>> strategy = getStaticCache(ob).__bind__(request)
- >>> interfaces.ICacheStrategy.providedBy(strategy)
- True
-
-This strategy uses 'If-Modified-Since' request header.
-
- >>> request._environ['IF_MODIFIED_SINCE'] = 'Mon, 10 Dec 2007 00:00:00 GMT'
- >>> strategy.isModified()
- False
-
- >>> request._environ['IF_MODIFIED_SINCE'] = 'Mon, 10 Sep 2007 00:00:00 GMT'
- >>> strategy.isModified()
- True
-
-If format is wrong isModified is always True
-
- >>> request._environ['IF_MODIFIED_SINCE'] = 'wrong format'
- >>> strategy.isModified()
- True
-
- >>> request._environ['IF_MODIFIED_SINCE'] = 'Mon, 10 Dec 2007 00:00:00 GMT'
-
-
-Static Cache set 'Cache-Control', 'Expires', 'Last-Modified' headers for browser
-
- >>> strategy.setCacheHeaders()
-
- >>> response.getHeader('Cache-Control')
- 'public,max-age=86400'
-
- >>> response.getHeader('Expires')
- '..., ... GMT'
-
- >>> response.getHeader('Last-Modified')
- 'Wed, 10 Oct 2007 01:00:00 GMT'
-
-It also should automaticly convert modified date to utc timezone
-
- >>> ModInfo.dt = datetime.datetime(2007, 10, 10, 0, 0, 0, 0)
-
- >>> strategy = getStaticCache(ob).__bind__(request)
- >>> strategy.setCacheHeaders()
- >>> response.getHeader('Last-Modified')
- 'Wed, 10 Oct 2007 01:00:00 GMT'
-
- >>> ModInfo.dt = datetime.datetime(
- ... 2007, 10, 9, 18, 0, 0, 0, pytz.timezone('Asia/Almaty'))
-
- >>> strategy = getStaticCache(ob).__bind__(request)
- >>> strategy.setCacheHeaders()
- >>> response.getHeader('Last-Modified')
- 'Wed, 10 Oct 2007 01:00:00 GMT'
-
- >>> ModInfo.dt = datetime.datetime(2007, 10, 10, 0, 0, 0, 0, tzinfo=pytz.utc)
-
-To use this cache we have to register adater
-
- >>> component.provideAdapter(getStaticCache, (IContent,))
-
-Now we can use this strategy in publication.
-If content doesn't changed we should get just 304 response code
-
- >>> print pub.callObject(request, ob)
- <BLANKLINE>
-
- >>> response.getStatus()
- 304
-
-Or content
-
- >>> response.setStatus('200')
- >>> request._environ['IF_MODIFIED_SINCE'] = 'Mon, 10 Sep 2007 00:00:00 GMT'
-
- >>> print pub.callObject(request, ob)
- Content body
-
- >>> response.getStatus()
- 200
-
- >>> response.getHeader('Last-Modified')
- 'Wed, 10 Oct 2007 01:00:00 GMT'
-
-
-Additional feature, calculating duration of call.
-
- >>> pub.beforeTraversal(request)
- >>> time.sleep(2)
- >>> pub.afterCall(request, ob)
-
- >>> response.getHeader('X-Generated-Time')
- '... sec'
Modified: z3ext.cacheheaders/trunk/src/z3ext/cacheheaders/interfaces.py
===================================================================
--- z3ext.cacheheaders/trunk/src/z3ext/cacheheaders/interfaces.py 2009-12-22 22:33:52 UTC (rev 106962)
+++ z3ext.cacheheaders/trunk/src/z3ext/cacheheaders/interfaces.py 2009-12-22 23:19:09 UTC (rev 106963)
@@ -25,6 +25,12 @@
request = interface.Attribute('Request')
+class IAfterExceptionCallEvent(IObjectEvent):
+ """ after call event """
+
+ request = interface.Attribute('Request')
+
+
class AfterCallEvent(object):
interface.implements(IAfterCallEvent)
@@ -33,12 +39,6 @@
self.request = request
-class IAfterExceptionCallEvent(IObjectEvent):
- """ after call event """
-
- request = interface.Attribute('Request')
-
-
class AfterExceptionCallEvent(object):
interface.implements(IAfterExceptionCallEvent)
Modified: z3ext.cacheheaders/trunk/src/z3ext/cacheheaders/publication.py
===================================================================
--- z3ext.cacheheaders/trunk/src/z3ext/cacheheaders/publication.py 2009-12-22 22:33:52 UTC (rev 106962)
+++ z3ext.cacheheaders/trunk/src/z3ext/cacheheaders/publication.py 2009-12-22 23:19:09 UTC (rev 106963)
@@ -80,8 +80,8 @@
notify(AfterExceptionCallEvent(orig.im_self, request))
else:
notify(AfterExceptionCallEvent(orig, request))
-
+
class BrowserFactory(object):
interface.implements(IRequestPublicationFactory)
Modified: z3ext.cacheheaders/trunk/src/z3ext/cacheheaders/tests.py
===================================================================
--- z3ext.cacheheaders/trunk/src/z3ext/cacheheaders/tests.py 2009-12-22 22:33:52 UTC (rev 106962)
+++ z3ext.cacheheaders/trunk/src/z3ext/cacheheaders/tests.py 2009-12-22 23:19:09 UTC (rev 106963)
@@ -19,17 +19,19 @@
import doctest, unittest
from zope import component
-from zope.traversing import testing
-from zope.app.testing import placelesssetup
+from zope.component import testing, eventtesting
+from zope.traversing.testing import setUp as traversalSetUp
from zope.traversing.interfaces import ITraversable
-from zope.app.security import principalregistry
+from zope.principalregistry import principalregistry
from zope.security.management import endInteraction
-from zope.app.security.interfaces import IAuthentication
-from zope.app.security.interfaces import IFallbackUnauthenticatedPrincipal
+from zope.authentication.interfaces import IAuthentication
+from zope.authentication.interfaces import IFallbackUnauthenticatedPrincipal
+
def setUp(test):
- placelesssetup.setUp()
testing.setUp()
+ eventtesting.setUp()
+ traversalSetUp()
endInteraction()
@@ -39,13 +41,15 @@
component.provideUtility(
principalregistry.principalRegistry, IAuthentication)
+
def tearDown(test):
- placelesssetup.tearDown()
+ testing.tearDown()
+
def test_suite():
return unittest.TestSuite((
doctest.DocFileSuite(
- 'README.txt',
+ 'tests.txt',
setUp=setUp, tearDown=tearDown,
optionflags=doctest.NORMALIZE_WHITESPACE|doctest.ELLIPSIS),
))
Copied: z3ext.cacheheaders/trunk/src/z3ext/cacheheaders/tests.txt (from rev 106129, z3ext.cacheheaders/trunk/src/z3ext/cacheheaders/README.txt)
===================================================================
--- z3ext.cacheheaders/trunk/src/z3ext/cacheheaders/tests.txt (rev 0)
+++ z3ext.cacheheaders/trunk/src/z3ext/cacheheaders/tests.txt 2009-12-22 23:19:09 UTC (rev 106963)
@@ -0,0 +1,203 @@
+=======================
+Browser caching headers
+=======================
+
+`Publication` with support `304` response code
+
+ >>> import time, datetime, pytz
+ >>> from zope import component, interface
+ >>> from z3ext.cacheheaders import interfaces
+
+ >>> from z3ext.cacheheaders.publication import \
+ ... BrowserFactory, BrowserPublication
+
+ >>> factory = BrowserFactory()
+ >>> factory.canHandle({})
+ True
+
+ >>> rclass, pclass = factory()
+ >>> pclass == BrowserPublication
+ True
+
+ >>> pub = BrowserPublication(None)
+
+ >>> from zope.publisher.browser import TestRequest
+ >>> from zope.publisher.interfaces.http import IHTTPRequest
+
+ >>> request = TestRequest()
+ >>> response = request.response
+
+ >>> request.setPublication(pub)
+
+We need object
+
+ >>> class IContent(interface.Interface):
+ ... pass
+
+ >>> class Content(object):
+ ... interface.implements(IContent)
+ ... marker = 0
+ ...
+ ... def __call__(self):
+ ... self.marker = 1
+ ... return 'Content body'
+
+ >>> ob = Content()
+
+ >>> print pub.callObject(request, ob)
+ Content body
+
+
+If we want control caching headers we need define ICacheStrategy adapter.
+this package predefine some cache strategies. Simplest is StatusCache, it's
+base on object modification date (IModificationInfo interface)
+So to use static cache fist we need IModificationInfo adapter
+
+ >>> from z3ext.cacheheaders.staticcache import getStaticCache
+ >>> getStaticCache(ob) is None
+ True
+
+ >>> class ModInfo(object):
+ ... interface.implements(interfaces.IModificationInfo)
+ ... component.adapts(IContent)
+ ...
+ ... dt = datetime.datetime(2007, 10, 10, 0, 0, 0, 0, tzinfo=pytz.utc)
+ ...
+ ... def __init__(self, context):
+ ... self.context = context
+ ...
+ ... def modified(self):
+ ... return long(time.mktime(self.dt.utctimetuple()))
+
+ >>> component.provideAdapter(ModInfo)
+
+ >>> strategy = getStaticCache(ob).__bind__(request)
+ >>> interfaces.ICacheStrategy.providedBy(strategy)
+ True
+
+This strategy uses 'If-Modified-Since' request header.
+
+ >>> request._environ['IF_MODIFIED_SINCE'] = 'Mon, 10 Dec 2007 00:00:00 GMT'
+ >>> strategy.isModified()
+ False
+
+ >>> request._environ['IF_MODIFIED_SINCE'] = 'Mon, 10 Sep 2007 00:00:00 GMT'
+ >>> strategy.isModified()
+ True
+
+If format is wrong isModified is always True
+
+ >>> request._environ['IF_MODIFIED_SINCE'] = 'wrong format'
+ >>> strategy.isModified()
+ True
+
+ >>> request._environ['IF_MODIFIED_SINCE'] = 'Mon, 10 Dec 2007 00:00:00 GMT'
+
+
+Static Cache set 'Cache-Control', 'Expires', 'Last-Modified' headers for browser
+
+ >>> strategy.setCacheHeaders()
+
+ >>> response.getHeader('Cache-Control')
+ 'public,max-age=86400'
+
+ >>> response.getHeader('Expires')
+ '..., ... GMT'
+
+ >>> response.getHeader('Last-Modified')
+ 'Wed, 10 Oct 2007 01:00:00 GMT'
+
+It also should automaticly convert modified date to utc timezone
+
+ >>> ModInfo.dt = datetime.datetime(2007, 10, 10, 0, 0, 0, 0)
+
+ >>> strategy = getStaticCache(ob).__bind__(request)
+ >>> strategy.setCacheHeaders()
+ >>> response.getHeader('Last-Modified')
+ 'Wed, 10 Oct 2007 01:00:00 GMT'
+
+ >>> ModInfo.dt = datetime.datetime(
+ ... 2007, 10, 9, 18, 0, 0, 0, pytz.timezone('Asia/Almaty'))
+
+ >>> strategy = getStaticCache(ob).__bind__(request)
+ >>> strategy.setCacheHeaders()
+ >>> response.getHeader('Last-Modified')
+ 'Wed, 10 Oct 2007 01:00:00 GMT'
+
+ >>> ModInfo.dt = datetime.datetime(2007, 10, 10, 0, 0, 0, 0, tzinfo=pytz.utc)
+
+To use this cache we have to register adater
+
+ >>> component.provideAdapter(getStaticCache, (IContent,))
+
+Now we can use this strategy in publication.
+If content doesn't changed we should get just 304 response code
+
+ >>> print pub.callObject(request, ob)
+ <BLANKLINE>
+
+ >>> response.getStatus()
+ 304
+
+Or content
+
+ >>> response.setStatus('200')
+ >>> request._environ['IF_MODIFIED_SINCE'] = 'Mon, 10 Sep 2007 00:00:00 GMT'
+
+ >>> print pub.callObject(request, ob)
+ Content body
+
+ >>> response.getStatus()
+ 200
+
+ >>> response.getHeader('Last-Modified')
+ 'Wed, 10 Oct 2007 01:00:00 GMT'
+
+
+Additional feature, calculating duration of call.
+
+ >>> pub.beforeTraversal(request)
+ >>> time.sleep(2)
+ >>> pub.afterCall(request, ob)
+
+ >>> response.getHeader('X-Generated-Time')
+ '... sec'
+
+ >>> from zope.component.eventtesting import getEvents
+
+ >>> ev = getEvents()[-1]
+ >>> interfaces.IAfterCallEvent.providedBy(ev)
+ True
+
+ >>> ev.object is ob
+ True
+
+ >>> pub.afterCall(request, ob.__call__)
+ >>> interfaces.IAfterCallEvent.providedBy(ev)
+ True
+ >>> ev.object is ob
+ True
+
+ >>> import sys
+ >>> from zope.publisher.interfaces import NotFound
+ >>> try:
+ ... raise NotFound(request)
+ ... except:
+ ... exc = sys.exc_info()
+
+ >>> pub.handleException(ob, request, exc)
+
+ >>> ev = getEvents()[-1]
+ >>> interfaces.IAfterExceptionCallEvent.providedBy(ev)
+ True
+ >>> ev.object is ob
+ True
+
+ >>> pub.handleException(ob.__call__, request, exc)
+
+ >>> ev = getEvents()[-1]
+ >>> interfaces.IAfterExceptionCallEvent.providedBy(ev)
+ True
+ >>> ev.object is ob
+ True
+
More information about the checkins
mailing list