[Checkins] SVN: Sandbox/nadako/zope.browserresource/ Remove page template and image resource types. Page template were moved into zope.ptresource and images are really files. :-)
Dan Korostelev
nadako at gmail.com
Sun Aug 23 16:13:18 EDT 2009
Log message for revision 103119:
Remove page template and image resource types. Page template were moved into zope.ptresource and images are really files. :-)
Changed:
D Sandbox/nadako/zope.browserresource/TODO.txt
U Sandbox/nadako/zope.browserresource/setup.py
U Sandbox/nadako/zope.browserresource/src/zope/browserresource/configure.zcml
U Sandbox/nadako/zope.browserresource/src/zope/browserresource/fileresource.py
U Sandbox/nadako/zope.browserresource/src/zope/browserresource/i18nfileresource.py
U Sandbox/nadako/zope.browserresource/src/zope/browserresource/metaconfigure.py
D Sandbox/nadako/zope.browserresource/src/zope/browserresource/pagetemplateresource.py
D Sandbox/nadako/zope.browserresource/src/zope/browserresource/resourcefactories.zcml
U Sandbox/nadako/zope.browserresource/src/zope/browserresource/tests/test_directoryresource.py
U Sandbox/nadako/zope.browserresource/src/zope/browserresource/tests/test_fileresource.py
D Sandbox/nadako/zope.browserresource/src/zope/browserresource/tests/test_pagetemplateresource.py
-=-
Deleted: Sandbox/nadako/zope.browserresource/TODO.txt
===================================================================
--- Sandbox/nadako/zope.browserresource/TODO.txt 2009-08-23 20:10:31 UTC (rev 103118)
+++ Sandbox/nadako/zope.browserresource/TODO.txt 2009-08-23 20:13:17 UTC (rev 103119)
@@ -1,4 +0,0 @@
- * Clean up tests, possibly move them to doctests.
- * Simplify the overall mechanism, remove extra entities.
- * Move PageTemplateResource to a separate package, so this
- one could be independent on any templating system.
Modified: Sandbox/nadako/zope.browserresource/setup.py
===================================================================
--- Sandbox/nadako/zope.browserresource/setup.py 2009-08-23 20:10:31 UTC (rev 103118)
+++ Sandbox/nadako/zope.browserresource/setup.py 2009-08-23 20:13:17 UTC (rev 103119)
@@ -47,11 +47,9 @@
'zope.i18n',
'zope.interface',
'zope.location',
- 'zope.pagetemplate>=3.5.0',
'zope.publisher>=3.8.0',
'zope.schema',
'zope.site',
- 'zope.security[untrustedpython]',
'zope.traversing>3.7.0',
'zope.browser',
],
Modified: Sandbox/nadako/zope.browserresource/src/zope/browserresource/configure.zcml
===================================================================
--- Sandbox/nadako/zope.browserresource/src/zope/browserresource/configure.zcml 2009-08-23 20:10:31 UTC (rev 103118)
+++ Sandbox/nadako/zope.browserresource/src/zope/browserresource/configure.zcml 2009-08-23 20:13:17 UTC (rev 103119)
@@ -21,16 +21,9 @@
<allow attributes="GET HEAD __call__" />
</class>
- <class class=".pagetemplateresource.PageTemplateResource">
- <allow interface="zope.publisher.interfaces.browser.IBrowserPublisher" />
- <allow attributes="__call__" />
- </class>
-
<class class=".directoryresource.DirectoryResource">
<allow interface="zope.publisher.interfaces.browser.IBrowserPublisher" />
<allow attributes="get __getitem__" />
</class>
- <include file="resourcefactories.zcml" />
-
</configure>
Modified: Sandbox/nadako/zope.browserresource/src/zope/browserresource/fileresource.py
===================================================================
--- Sandbox/nadako/zope.browserresource/src/zope/browserresource/fileresource.py 2009-08-23 20:10:31 UTC (rev 103118)
+++ Sandbox/nadako/zope.browserresource/src/zope/browserresource/fileresource.py 2009-08-23 20:13:17 UTC (rev 103119)
@@ -49,23 +49,6 @@
self.lmh = formatdate(self.lmt, usegmt=True)
-class Image(File):
- """Image objects stored in external files."""
-
- # XXX: this class looks nonsense, as it's doesn't seem to be
- # very smart to construct media type from file extension,
- # for example, there's no "image/jpg" type.
- # I'd propose to remove this class completely and do
- # Image = File for backward compatibility.
- # nadako, 23 Aug 2009
-
- def __init__(self, path, name):
- super(Image, self).__init__(path, name)
- if self.content_type in (None, 'application/octet-stream'):
- ext = os.path.splitext(self.path)[1]
- if ext:
- self.content_type = 'image/%s' % ext[1:]
-
class FileResource(BrowserView, Resource):
implements(IBrowserPublisher)
@@ -172,22 +155,3 @@
resource.__Security_checker__ = self.__checker
resource.__name__ = self.__name
return resource
-
-
-class ImageResourceFactory(object):
-
- resourceClass = FileResource
-
- implements(IResourceFactory)
- classProvides(IResourceFactoryFactory)
-
- def __init__(self, path, checker, name):
- self.__file = Image(path, name)
- self.__checker = checker
- self.__name = name
-
- def __call__(self, request):
- resource = self.resourceClass(self.__file, request)
- resource.__Security_checker__ = self.__checker
- resource.__name__ = self.__name
- return resource
Modified: Sandbox/nadako/zope.browserresource/src/zope/browserresource/i18nfileresource.py
===================================================================
--- Sandbox/nadako/zope.browserresource/src/zope/browserresource/i18nfileresource.py 2009-08-23 20:10:31 UTC (rev 103118)
+++ Sandbox/nadako/zope.browserresource/src/zope/browserresource/i18nfileresource.py 2009-08-23 20:13:17 UTC (rev 103119)
@@ -30,7 +30,7 @@
def __init__(self, data, request, defaultLanguage='en'):
"""Creates an internationalized file resource. data should be
- a mapping from languages to File or Image objects.
+ a mapping from languages to File objects.
"""
self._data = data
self.request = request
Modified: Sandbox/nadako/zope.browserresource/src/zope/browserresource/metaconfigure.py
===================================================================
--- Sandbox/nadako/zope.browserresource/src/zope/browserresource/metaconfigure.py 2009-08-23 20:10:31 UTC (rev 103118)
+++ Sandbox/nadako/zope.browserresource/src/zope/browserresource/metaconfigure.py 2009-08-23 20:13:17 UTC (rev 103119)
@@ -28,11 +28,8 @@
from zope.security.proxy import Proxy
from zope.browserresource.directoryresource import DirectoryResourceFactory
-from zope.browserresource.fileresource import File, Image
-from zope.browserresource.fileresource import FileResourceFactory
-from zope.browserresource.fileresource import ImageResourceFactory
+from zope.browserresource.fileresource import File, FileResourceFactory
from zope.browserresource.i18nfileresource import I18nFileResourceFactory
-from zope.browserresource.pagetemplateresource import PageTemplateResourceFactory
from zope.browserresource.icon import IconViewFactory
from zope.browserresource.interfaces import IResourceFactory
from zope.browserresource.interfaces import IResourceFactoryFactory
@@ -75,26 +72,33 @@
" attributes for resource directives"
)
+ if image or template:
+ import warnings
+ warnings.warn('The "template" and "image" attributes of resource '
+ 'directive are deprecated in favor of pluggable '
+ 'file resource factories based on file extensions. '
+ 'Use the "file" attribute instead.',
+ DeprecationWarning)
+ if image:
+ file = image
+ elif template:
+ file = template
+
_context.action(
discriminator = ('resource', name, IBrowserRequest, layer),
callable = resourceHandler,
- args = (name, layer, checker, factory, file, image, template, _context.info),
+ args = (name, layer, checker, factory, file, _context.info),
)
-def resourceHandler(name, layer, checker, factory, file, image, template, context_info):
+def resourceHandler(name, layer, checker, factory, file, context_info):
if factory is not None:
factory = ResourceFactoryWrapper(factory, checker, name)
- elif file:
+ else:
ext = os.path.splitext(os.path.normcase(file))[1][1:]
factory_factory = queryUtility(IResourceFactoryFactory, ext,
FileResourceFactory)
factory = factory_factory(file, checker, name)
- elif image:
- factory = ImageResourceFactory(image, checker, name)
- else:
- factory = PageTemplateResourceFactory(template, checker, name)
-
handler('registerAdapter', factory, (layer,), Interface, name, context_info)
Deleted: Sandbox/nadako/zope.browserresource/src/zope/browserresource/pagetemplateresource.py
===================================================================
--- Sandbox/nadako/zope.browserresource/src/zope/browserresource/pagetemplateresource.py 2009-08-23 20:10:31 UTC (rev 103118)
+++ Sandbox/nadako/zope.browserresource/src/zope/browserresource/pagetemplateresource.py 2009-08-23 20:13:17 UTC (rev 103119)
@@ -1,87 +0,0 @@
-##############################################################################
-#
-# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
-# All Rights Reserved.
-#
-# This software is subject to the provisions of the Zope Public License,
-# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
-# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
-# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
-# FOR A PARTICULAR PURPOSE.
-#
-##############################################################################
-"""Page Template Resource
-
-$Id$
-"""
-
-from zope.interface import implements, classProvides
-from zope.pagetemplate.engine import TrustedAppPT
-from zope.pagetemplate.pagetemplatefile import PageTemplateFile
-from zope.publisher.browser import BrowserView
-from zope.publisher.interfaces import NotFound
-from zope.publisher.interfaces.browser import IBrowserPublisher
-
-from zope.browserresource.resource import Resource
-from zope.browserresource.interfaces import IResourceFactory
-from zope.browserresource.interfaces import IResourceFactoryFactory
-
-class PageTemplate(TrustedAppPT, PageTemplateFile):
- """
- Resource that is a page template
- """
-
- def __init__(self, filename, _prefix=None, content_type=None):
- _prefix = self.get_path_from_prefix(_prefix)
- super(PageTemplate, self).__init__(filename, _prefix)
- if content_type is not None:
- self.content_type = content_type
-
- def pt_getContext(self, request, **kw):
- namespace = super(PageTemplate, self).pt_getContext(**kw)
- namespace['context'] = None
- namespace['request'] = request
- return namespace
-
- def __call__(self, request, **keywords):
- namespace = self.pt_getContext(
- request=request,
- options=keywords
- )
- return self.pt_render(namespace)
-
-class PageTemplateResource(BrowserView, Resource):
-
- implements(IBrowserPublisher)
-
- def publishTraverse(self, request, name):
- '''See interface IBrowserPublisher'''
- raise NotFound(None, name)
-
- def browserDefault(self, request):
- '''See interface IBrowserPublisher'''
- return self, ()
-
- def __call__(self):
- pt = self.context
- response = self.request.response
- if not response.getHeader("Content-Type"):
- response.setHeader("Content-Type", pt.content_type)
- return pt(self.request)
-
-class PageTemplateResourceFactory(object):
-
- implements(IResourceFactory)
- classProvides(IResourceFactoryFactory)
-
- def __init__(self, path, checker, name):
- self.__pt = PageTemplate(path)
- self.__checker = checker
- self.__name = name
-
- def __call__(self, request):
- resource = PageTemplateResource(self.__pt, request)
- resource.__Security_checker__ = self.__checker
- resource.__name__ = self.__name
- return resource
Deleted: Sandbox/nadako/zope.browserresource/src/zope/browserresource/resourcefactories.zcml
===================================================================
--- Sandbox/nadako/zope.browserresource/src/zope/browserresource/resourcefactories.zcml 2009-08-23 20:10:31 UTC (rev 103118)
+++ Sandbox/nadako/zope.browserresource/src/zope/browserresource/resourcefactories.zcml 2009-08-23 20:13:17 UTC (rev 103119)
@@ -1,39 +0,0 @@
-<configure xmlns="http://namespaces.zope.org/zope">
-
- <utility
- name="gif"
- component=".fileresource.ImageResourceFactory"
- provides=".interfaces.IResourceFactoryFactory"
- />
-
- <utility
- name="png"
- component=".fileresource.ImageResourceFactory"
- provides=".interfaces.IResourceFactoryFactory"
- />
-
- <utility
- name="jpg"
- component=".fileresource.ImageResourceFactory"
- provides=".interfaces.IResourceFactoryFactory"
- />
-
- <utility
- name="pt"
- component=".pagetemplateresource.PageTemplateResourceFactory"
- provides=".interfaces.IResourceFactoryFactory"
- />
-
- <utility
- name="zpt"
- component=".pagetemplateresource.PageTemplateResourceFactory"
- provides=".interfaces.IResourceFactoryFactory"
- />
-
- <utility
- name="html"
- component=".pagetemplateresource.PageTemplateResourceFactory"
- provides=".interfaces.IResourceFactoryFactory"
- />
-
-</configure>
Modified: Sandbox/nadako/zope.browserresource/src/zope/browserresource/tests/test_directoryresource.py
===================================================================
--- Sandbox/nadako/zope.browserresource/src/zope/browserresource/tests/test_directoryresource.py 2009-08-23 20:10:31 UTC (rev 103118)
+++ Sandbox/nadako/zope.browserresource/src/zope/browserresource/tests/test_directoryresource.py 2009-08-23 20:13:17 UTC (rev 103119)
@@ -28,15 +28,12 @@
from zope.traversing.browser.absoluteurl import AbsoluteURL
from zope.traversing.browser.interfaces import IAbsoluteURL
from zope.component import provideAdapter
-from zope.configuration.xmlconfig import XMLConfig
from zope.testing import cleanup
from zope.browserresource.directoryresource import \
DirectoryResourceFactory, DirectoryResource
from zope.browserresource.fileresource import FileResource
-from zope.browserresource.pagetemplateresource import \
- PageTemplateResource
import zope.browserresource.tests as p
from zope.browserresource.tests import support
@@ -57,10 +54,6 @@
def setUp(self):
super(Test, self).setUp()
provideAdapter(AbsoluteURL, (None, None), IAbsoluteURL)
- import zope.browserresource
- import zope.component
- XMLConfig('meta.zcml', zope.component)()
- XMLConfig('resourcefactories.zcml', zope.browserresource)()
def testNotFound(self):
path = os.path.join(test_directory, 'testfiles')
@@ -130,8 +123,6 @@
image = resource['test.gif']
self.assert_(proxy.isinstance(image, FileResource))
- template = resource['test.pt']
- self.assert_(proxy.isinstance(template, PageTemplateResource))
file = resource['test.txt']
self.assert_(proxy.isinstance(file, FileResource))
file = resource['png']
Modified: Sandbox/nadako/zope.browserresource/src/zope/browserresource/tests/test_fileresource.py
===================================================================
--- Sandbox/nadako/zope.browserresource/src/zope/browserresource/tests/test_fileresource.py 2009-08-23 20:10:31 UTC (rev 103118)
+++ Sandbox/nadako/zope.browserresource/src/zope/browserresource/tests/test_fileresource.py 2009-08-23 20:13:17 UTC (rev 103119)
@@ -31,7 +31,6 @@
from zope.publisher.browser import TestRequest
from zope.browserresource.fileresource import FileResourceFactory
-from zope.browserresource.fileresource import ImageResourceFactory
import zope.browserresource.tests as p
checker = NamesChecker(
@@ -94,30 +93,6 @@
self.assertEqual(view(), '')
self.assertEqual(next, ())
- def testImageGET(self):
- path = os.path.join(test_directory, 'testfiles', 'test.gif')
-
- factory = ImageResourceFactory(path, checker, 'test.gif')
- resource = factory(TestRequest())
-
- self.assertEqual(resource.GET(), open(path, 'rb').read())
-
- response = removeSecurityProxy(resource.request).response
- self.assertEqual(response.getHeader('Content-Type'), 'image/gif')
-
- def testImageHEAD(self):
-
- path = os.path.join(test_directory, 'testfiles', 'test.gif')
- factory = ImageResourceFactory(path, checker, 'test.gif')
- resource = factory(TestRequest())
-
- self.assertEqual(resource.HEAD(), '')
-
- response = removeSecurityProxy(resource.request).response
- self.assertEqual(response.getHeader('Content-Type'), 'image/gif')
-
-
-
def test_suite():
return makeSuite(Test)
Deleted: Sandbox/nadako/zope.browserresource/src/zope/browserresource/tests/test_pagetemplateresource.py
===================================================================
--- Sandbox/nadako/zope.browserresource/src/zope/browserresource/tests/test_pagetemplateresource.py 2009-08-23 20:10:31 UTC (rev 103118)
+++ Sandbox/nadako/zope.browserresource/src/zope/browserresource/tests/test_pagetemplateresource.py 2009-08-23 20:13:17 UTC (rev 103119)
@@ -1,68 +0,0 @@
-##############################################################################
-#
-# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
-# All Rights Reserved.
-#
-# This software is subject to the provisions of the Zope Public License,
-# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
-# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
-# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
-# FOR A PARTICULAR PURPOSE.
-#
-##############################################################################
-"""Page Template based Resources Test
-
-$Id$
-"""
-import os
-from unittest import TestCase, main, makeSuite
-
-import zope.component
-from zope.publisher.interfaces import NotFound
-from zope.security.checker import NamesChecker
-from zope.publisher.browser import TestRequest
-from zope.traversing.interfaces import ITraversable
-from zope.traversing.adapters import DefaultTraversable
-from zope.testing import cleanup
-
-from zope.browserresource.pagetemplateresource import \
- PageTemplateResourceFactory
-import zope.browserresource.tests as p
-
-
-test_directory = os.path.dirname(p.__file__)
-
-
-checker = NamesChecker(
- ('__call__', 'request', 'publishTraverse')
- )
-
-
-class Test(cleanup.CleanUp, TestCase):
-
- def setUp(self):
- super(Test, self).setUp()
- zope.component.provideAdapter(DefaultTraversable, (None,), ITraversable)
-
- def testNoTraversal(self):
- path = os.path.join(test_directory, 'testfiles', 'test.pt')
- request = TestRequest()
- factory = PageTemplateResourceFactory(path, checker, 'test.pt')
- resource = factory(request)
- self.assertRaises(NotFound, resource.publishTraverse,
- resource.request, ())
-
- def testCall(self):
- path = os.path.join(test_directory, 'testfiles', 'testresource.pt')
- test_data = "Foobar"
- request = TestRequest(test_data=test_data)
- factory = PageTemplateResourceFactory(path, checker, 'testresource.pt')
- resource = factory(request)
- self.assert_(resource(), test_data)
- self.assertEquals('text/html',
- request.response.getHeader('Content-Type'))
-
-
-def test_suite():
- return makeSuite(Test)
More information about the Checkins
mailing list