[Checkins] SVN: zope.app.publisher/trunk/ - Refactored code to
provide more hooks when deriving code from this pacakge.
Stephan Richter
srichter at cosmos.phy.tufts.edu
Tue Aug 5 03:35:08 EDT 2008
Log message for revision 89359:
- Refactored code to provide more hooks when deriving code from this pacakge.
* A resource's URL creation is now in its own method.
* The resource class of factories can be overwritten.
* The cache timeout value can now be set as a class or instance attribute.
Changed:
U zope.app.publisher/trunk/CHANGES.txt
U zope.app.publisher/trunk/setup.py
U zope.app.publisher/trunk/src/zope/app/publisher/browser/directoryresource.py
U zope.app.publisher/trunk/src/zope/app/publisher/browser/fileresource.py
U zope.app.publisher/trunk/src/zope/app/publisher/browser/resource.py
-=-
Modified: zope.app.publisher/trunk/CHANGES.txt
===================================================================
--- zope.app.publisher/trunk/CHANGES.txt 2008-08-05 05:48:53 UTC (rev 89358)
+++ zope.app.publisher/trunk/CHANGES.txt 2008-08-05 07:35:05 UTC (rev 89359)
@@ -5,7 +5,14 @@
After 3.5.0a4
=============
+- Refactored code to provide more hooks when deriving code from this pacakge.
+ * A resource's URL creation is now in its own method.
+
+ * The resource class of factories can be overwritten.
+
+ * The cache timeout value can now be set as a class or instance attribute.
+
3.5.0a4 (2007-12-28)
====================
Modified: zope.app.publisher/trunk/setup.py
===================================================================
--- zope.app.publisher/trunk/setup.py 2008-08-05 05:48:53 UTC (rev 89358)
+++ zope.app.publisher/trunk/setup.py 2008-08-05 07:35:05 UTC (rev 89359)
@@ -19,10 +19,10 @@
open('CHANGES.txt').read())
setup(name='zope.app.publisher',
- version = '3.5dev',
+ version = '3.5.0dev',
url='http://pypi.python.org/pypi/zope.app.publisher/',
author='Zope Corporation and Contributors',
- author_email='zope3-dev at zope.org',
+ author_email='zope-dev at zope.org',
classifiers = ['Environment :: Web Environment',
'Intended Audience :: Developers',
'License :: OSI Approved :: Zope Public License',
Modified: zope.app.publisher/trunk/src/zope/app/publisher/browser/directoryresource.py
===================================================================
--- zope.app.publisher/trunk/src/zope/app/publisher/browser/directoryresource.py 2008-08-05 05:48:53 UTC (rev 89358)
+++ zope.app.publisher/trunk/src/zope/app/publisher/browser/directoryresource.py 2008-08-05 07:35:05 UTC (rev 89359)
@@ -61,6 +61,7 @@
}
default_factory = FileResourceFactory
+ directory_factory = None
def publishTraverse(self, request, name):
'''See interface IBrowserPublisher'''
@@ -81,7 +82,7 @@
filename = os.path.join(path, name)
isfile = os.path.isfile(filename)
isdir = os.path.isdir(filename)
-
+
if not (isfile or isdir):
if default is _marker:
raise NotFound(None, name)
@@ -91,22 +92,28 @@
ext = os.path.splitext(os.path.normcase(name))[1]
factory = self.resource_factories.get(ext, self.default_factory)
else:
- factory = DirectoryResourceFactory
+ factory = self.directory_factory
rname = posixpath.join(self.__name__, name)
resource = factory(filename, self.context.checker, rname)(self.request)
resource.__parent__ = self
return resource
+
class DirectoryResourceFactory(object):
+ factoryClass = DirectoryResource
+
def __init__(self, path, checker, name):
self.__dir = Directory(path, checker, name)
self.__checker = checker
self.__name = name
def __call__(self, request):
- resource = DirectoryResource(self.__dir, request)
+ resource = self.factoryClass(self.__dir, request)
resource.__Security_checker__ = self.__checker
resource.__name__ = self.__name
return resource
+
+
+DirectoryResource.directory_factory = DirectoryResourceFactory
Modified: zope.app.publisher/trunk/src/zope/app/publisher/browser/fileresource.py
===================================================================
--- zope.app.publisher/trunk/src/zope/app/publisher/browser/fileresource.py 2008-08-05 05:48:53 UTC (rev 89358)
+++ zope.app.publisher/trunk/src/zope/app/publisher/browser/fileresource.py 2008-08-05 07:35:05 UTC (rev 89359)
@@ -30,6 +30,8 @@
implements(IBrowserPublisher)
+ cacheTimeout = 86400
+
def publishTraverse(self, request, name):
'''See interface IBrowserPublisher'''
raise NotFound(None, name)
@@ -61,7 +63,7 @@
request = self.request
response = request.response
- setCacheControl(response)
+ setCacheControl(response, self.cacheTimeout)
# HTTP If-Modified-Since header handling. This is duplicated
# from OFS.Image.Image - it really should be consolidated
@@ -100,7 +102,7 @@
response = self.request.response
response.setHeader('Content-Type', file.content_type)
response.setHeader('Last-Modified', file.lmh)
- setCacheControl(response)
+ setCacheControl(response, self.cacheTimeout)
return ''
@@ -115,26 +117,31 @@
class FileResourceFactory(object):
+ resourceClass = FileResource
+
def __init__(self, path, checker, name):
self.__file = File(path, name)
self.__checker = checker
self.__name = name
def __call__(self, request):
- resource = FileResource(self.__file, request)
+ resource = self.resourceClass(self.__file, request)
resource.__Security_checker__ = self.__checker
resource.__name__ = self.__name
return resource
+
class ImageResourceFactory(object):
+ resourceClass = FileResource
+
def __init__(self, path, checker, name):
self.__file = Image(path, name)
self.__checker = checker
self.__name = name
def __call__(self, request):
- resource = FileResource(self.__file, request)
+ resource = self.resourceClass(self.__file, request)
resource.__Security_checker__ = self.__checker
resource.__name__ = self.__name
return resource
Modified: zope.app.publisher/trunk/src/zope/app/publisher/browser/resource.py
===================================================================
--- zope.app.publisher/trunk/src/zope/app/publisher/browser/resource.py 2008-08-05 05:48:53 UTC (rev 89358)
+++ zope.app.publisher/trunk/src/zope/app/publisher/browser/resource.py 2008-08-05 07:35:05 UTC (rev 89359)
@@ -29,6 +29,9 @@
def __init__(self, request):
self.request = request
+ def _createUrl(self, baseUrl, name):
+ return "%s/@@/%s" % (baseUrl, name)
+
def __call__(self):
name = self.__name__
if name.startswith('++resource++'):
@@ -36,4 +39,4 @@
site = getSite()
url = str(getMultiAdapter((site, self.request), IAbsoluteURL))
- return "%s/@@/%s" % (url, name)
+ return self._createUrl(url, name)
More information about the Checkins
mailing list