[Checkins] SVN: z3ext.resource/tags/1.2.1/ release tag
Nikolay Kim
fafhrd at datacom.kz
Tue Nov 25 02:07:14 EST 2008
Log message for revision 93335:
release tag
Changed:
A z3ext.resource/tags/1.2.1/
U z3ext.resource/tags/1.2.1/setup.py
D z3ext.resource/tags/1.2.1/src/z3ext/resource/README.txt
A z3ext.resource/tags/1.2.1/src/z3ext/resource/README.txt
D z3ext.resource/tags/1.2.1/src/z3ext/resource/tests.py
A z3ext.resource/tags/1.2.1/src/z3ext/resource/tests.py
-=-
Modified: z3ext.resource/tags/1.2.1/setup.py
===================================================================
--- z3ext.resource/trunk/setup.py 2008-11-24 23:18:19 UTC (rev 93333)
+++ z3ext.resource/tags/1.2.1/setup.py 2008-11-25 07:07:13 UTC (rev 93335)
@@ -21,7 +21,7 @@
def read(*rnames):
return open(os.path.join(os.path.dirname(__file__), *rnames)).read()
-version = '1.2.1dev'
+version = '1.2.1'
setup(name='z3ext.resource',
Deleted: z3ext.resource/tags/1.2.1/src/z3ext/resource/README.txt
===================================================================
--- z3ext.resource/trunk/src/z3ext/resource/README.txt 2008-11-24 23:18:19 UTC (rev 93333)
+++ z3ext.resource/tags/1.2.1/src/z3ext/resource/README.txt 2008-11-25 07:07:13 UTC (rev 93335)
@@ -1,245 +0,0 @@
-============================
-``z3ext:resource`` Directive
-============================
-
-This package provides a new directive similar to browser:resource directive.
-
- >>> from zope import component, interface
- >>> from z3ext.resource import interfaces, fileresource
-
- >>> import z3ext.resource
- >>> from zope.configuration import xmlconfig
- >>> context = xmlconfig.file('meta.zcml', z3ext.resource)
-
-Now we can register a resource:
-
- >>> import tempfile, os, os.path
- >>> fn = tempfile.mktemp('.js')
- >>> open(fn, 'w').write('''some resource data''')
-
- >>> context = xmlconfig.string('''
- ... <configure xmlns:z3ext="http://namespaces.zope.org/z3ext">
- ... <z3ext:resource
- ... name="resource.js"
- ... file="%s" />
- ... </configure>
- ... '''%fn, context=context)
-
-Now let's see whether the adapter has been registered:
-
- >>> from zope.publisher.browser import TestRequest
- >>> request = TestRequest()
- >>> response = request.response
-
- >>> resource = component.getAdapter(
- ... request, interface.Interface, name='resource.js')
-
- >>> modified = resource.modified()
-
- >>> resource.render(request)
- 'some resource data'
-
-By default resource is FileResource
-
- >>> isinstance(resource.context, fileresource.File)
- True
-
-We can set resource type explicitly
-
- >>> context = xmlconfig.string('''
- ... <configure xmlns:z3ext="http://namespaces.zope.org/z3ext">
- ... <z3ext:resource
- ... name="resource-image"
- ... type="imageresource"
- ... file="%s" />
- ... </configure>
- ... ''' %fn, context=context)
-
- >>> resource = component.getAdapter(
- ... request, interface.Interface, name='resource-image')
-
- >>> isinstance(resource.context, fileresource.Image)
- True
-
-
-Custom resource type
---------------------
-
-We have to register IResourceFactoryType utility
-
- >>> from z3ext.resource.tests import CustomFileResourceFactory
- >>> custom = component.factory.Factory(
- ... CustomFileResourceFactory, interfaces=(interfaces.IResourceFactory,))
- >>> component.provideUtility(
- ... custom, interfaces.IResourceFactoryType, name='custom')
-
- >>> context = xmlconfig.string('''
- ... <configure xmlns:z3ext="http://namespaces.zope.org/z3ext">
- ... <z3ext:resource
- ... name="resource-custom"
- ... type="custom"
- ... file="%s" />
- ... </configure>
- ... ''' %fn, context=context)
-
- >>> resource = component.getAdapter(
- ... request, interface.Interface, name='resource-custom')
-
- >>> resource
- <z3ext.resource.tests.CustomResource object at ...>
-
- >>> os.unlink(fn)
-
-
-=====================================
-``z3ext:resourceDirectory`` Directive
-=====================================
-
-We need some temporary directories and files
-
- >>> import tempfile
- >>> dn = tempfile.mkdtemp()
- >>> os.mkdir(os.path.join(dn, 'subfolder'))
- >>> open(os.path.join(dn, 'resource1.css'), 'w').write('''\
- ... h1 {
- ... color: red;
- ... font: fontName;
- ... background: url('../img1/mybackground.gif');
- ... }''')
- >>> open(os.path.join(dn, 'resource2.js'), 'w').write('test')
- >>> open(os.path.join(dn, 'resource3.css'), 'w').write('test')
- >>> open(os.path.join(dn, 'resource4.jpg'), 'w').write('test')
- >>> open(os.path.join(dn, 'resource5.png'), 'w').write('test')
-
-Directive require directory path
-
- >>> context = xmlconfig.string('''
- ... <configure xmlns:z3ext="http://namespaces.zope.org/z3ext">
- ... <z3ext:resourcedirectory
- ... name="myresources"
- ... directory="%s" />
- ... </configure>
- ... ''' %(dn+'123123234534234'), context=context)
- Traceback (most recent call last):
- ...
- ZopeXMLConfigurationError: ...
-
-Now we can register a directory of resources, also we can set
-resource types:
-
- >>> context = xmlconfig.string('''
- ... <configure xmlns:z3ext="http://namespaces.zope.org/z3ext">
- ... <z3ext:resourcedirectory
- ... name="myresources"
- ... directory="%s"
- ... mapping=".css:custom .js:fileresource
- ... resource3.css:fileresource .png:null" />
- ... </configure>
- ... ''' %dn, context=context)
-
- >>> dirresource = component.getAdapter(
- ... request, interface.Interface, name='myresources')
-
-Now we can get resource
-
- >>> dirresource.browserDefault(request)
- (<function empty at ...>, ())
-
- >>> resource = dirresource.publishTraverse(request, 'resource1.css')
- >>> print resource.GET()
- h1 {
- color: red;
- font: fontName;
- background: url('../img1/mybackground.gif');
- }
-
- >>> print dirresource['resource1.css'].GET()
- h1 {
- color: red;
- font: fontName;
- background: url('../img1/mybackground.gif');
- }
-
- >>> dirresource.publishTraverse(request, 'unknown.css')
- Traceback (most recent call last):
- ...
- NotFound: ...
-
- >>> dirresource['unknown.css']
- Traceback (most recent call last):
- ...
- KeyError: 'unknown.css'
-
-
-Types mapping
--------------
-
- In 'mapping' we defined that all files with '.css' extension should be
-custom type, '.js' should be file resource and filename 'test.css'
-should be file resource, '.png' should be not available
-
- >>> dirresource.publishTraverse(request, 'resource1.css')
- <z3ext.resource.tests.CustomResource object at ...>
-
- >>> dirresource.publishTraverse(request, 'resource2.js')
- <z3ext.resource.fileresource.FileResource object at ...>
-
- >>> dirresource.publishTraverse(request, 'resource3.css')
- <z3ext.resource.fileresource.FileResource object at ...>
-
- >>> dirresource.publishTraverse(request, 'resource4.jpg')
- <z3ext.resource.fileresource.FileResource object at ...>
-
- >>> dirresource.publishTraverse(request, 'resource5.png')
- Traceback (most recent call last):
- ...
- NotFound: Object: ...
-
-Or we can use 'resourceType' subdirective:
-
- >>> context = xmlconfig.string('''
- ... <configure xmlns:z3ext="http://namespaces.zope.org/z3ext">
- ... <z3ext:resourcedirectory
- ... name="myresources2"
- ... directory="%s">
- ... <resourceType file=".css" type="custom" />
- ... <resourceType file=".js" type="fileresource" />
- ... <resourceType file="resource3.css" type="fileresource" />
- ... <resourceType file=".png" type="null" />
- ... </z3ext:resourcedirectory>
- ... </configure>
- ... ''' %dn, context=context)
-
- >>> dirresource = component.getAdapter(
- ... request, interface.Interface, name='myresources2')
-
- >>> dirresource.publishTraverse(request, 'resource1.css')
- <z3ext.resource.tests.CustomResource object at ...>
-
- >>> dirresource.publishTraverse(request, 'resource2.js')
- <z3ext.resource.fileresource.FileResource object at ...>
-
- >>> dirresource.publishTraverse(request, 'resource3.css')
- <z3ext.resource.fileresource.FileResource object at ...>
-
- >>> dirresource.publishTraverse(request, 'resource4.jpg')
- <z3ext.resource.fileresource.FileResource object at ...>
-
- >>> dirresource.publishTraverse(request, 'resource5.png')
- Traceback (most recent call last):
- ...
- NotFound: Object: ...
-
-
-We can get sub directories
-
- >>> subdir = dirresource.publishTraverse(request, 'subfolder')
-
-
- >>> os.unlink(os.path.join(dn, 'resource1.css'))
- >>> os.unlink(os.path.join(dn, 'resource2.js'))
- >>> os.unlink(os.path.join(dn, 'resource3.css'))
- >>> os.unlink(os.path.join(dn, 'resource4.jpg'))
- >>> os.unlink(os.path.join(dn, 'resource5.png'))
- >>> os.rmdir(os.path.join(dn, 'subfolder'))
- >>> os.rmdir(dn)
Copied: z3ext.resource/tags/1.2.1/src/z3ext/resource/README.txt (from rev 93334, z3ext.resource/trunk/src/z3ext/resource/README.txt)
===================================================================
--- z3ext.resource/tags/1.2.1/src/z3ext/resource/README.txt (rev 0)
+++ z3ext.resource/tags/1.2.1/src/z3ext/resource/README.txt 2008-11-25 07:07:13 UTC (rev 93335)
@@ -0,0 +1,246 @@
+============================
+``z3ext:resource`` Directive
+============================
+
+This package provides a new directive similar to browser:resource directive.
+
+ >>> from zope import component, interface
+ >>> from z3ext.resource import interfaces, fileresource
+
+ >>> import z3ext.resource
+ >>> from zope.configuration import xmlconfig
+ >>> context = xmlconfig.file('meta.zcml', z3ext.resource)
+
+Now we can register a resource:
+
+ >>> import tempfile, os, os.path
+ >>> fn = tempfile.mktemp('.js')
+ >>> open(fn, 'w').write('''some resource data''')
+
+ >>> context = xmlconfig.string('''
+ ... <configure xmlns:z3ext="http://namespaces.zope.org/z3ext">
+ ... <z3ext:resource
+ ... name="resource.js"
+ ... file="%s" />
+ ... </configure>
+ ... '''%fn, context=context)
+
+Now let's see whether the adapter has been registered:
+
+ >>> from zope.publisher.browser import TestRequest
+ >>> request = TestRequest()
+ >>> response = request.response
+
+ >>> resource = component.getAdapter(
+ ... request, interface.Interface, name='resource.js')
+
+ >>> modified = resource.modified()
+
+ >>> resource.render(request)
+ 'some resource data'
+
+By default resource is FileResource
+
+ >>> isinstance(resource.context, fileresource.File)
+ True
+
+We can set resource type explicitly
+
+ >>> context = xmlconfig.string('''
+ ... <configure xmlns:z3ext="http://namespaces.zope.org/z3ext">
+ ... <z3ext:resource
+ ... name="resource-image"
+ ... type="imageresource"
+ ... file="%s" />
+ ... </configure>
+ ... ''' %fn, context=context)
+
+ >>> resource = component.getAdapter(
+ ... request, interface.Interface, name='resource-image')
+
+ >>> isinstance(resource.context, fileresource.Image)
+ True
+
+
+Custom resource type
+--------------------
+
+We have to register IResourceFactoryType utility
+
+ >>> from z3ext.resource.tests import CustomFileResourceFactory
+ >>> custom = component.factory.Factory(
+ ... CustomFileResourceFactory, interfaces=(interfaces.IResourceFactory,))
+ >>> component.provideUtility(
+ ... custom, interfaces.IResourceFactoryType, name='custom')
+
+ >>> context = xmlconfig.string('''
+ ... <configure xmlns:z3ext="http://namespaces.zope.org/z3ext">
+ ... <z3ext:resource
+ ... name="resource-custom"
+ ... type="custom"
+ ... file="%s" />
+ ... </configure>
+ ... ''' %fn, context=context)
+
+ >>> resource = component.getAdapter(
+ ... request, interface.Interface, name='resource-custom')
+
+ >>> resource
+ <z3ext.resource.tests.CustomResource object at ...>
+
+ >>> os.unlink(fn)
+
+
+=====================================
+``z3ext:resourceDirectory`` Directive
+=====================================
+
+We need some temporary directories and files
+
+ >>> import tempfile
+ >>> dn = tempfile.mkdtemp()
+ >>> os.mkdir(os.path.join(dn, 'subfolder'))
+ >>> open(os.path.join(dn, 'resource1.css'), 'w').write('''\
+ ... /* zrt-cssregistry: */
+ ... h1 {
+ ... color: fontColor;
+ ... font: fontFamily;
+ ... background: url('../img1/mybackground.gif');
+ ... }''')
+ >>> open(os.path.join(dn, 'resource2.js'), 'w').write('test')
+ >>> open(os.path.join(dn, 'resource3.css'), 'w').write('test')
+ >>> open(os.path.join(dn, 'resource4.jpg'), 'w').write('test')
+ >>> open(os.path.join(dn, 'resource5.png'), 'w').write('test')
+
+Directive require directory path
+
+ >>> context = xmlconfig.string('''
+ ... <configure xmlns:z3ext="http://namespaces.zope.org/z3ext">
+ ... <z3ext:resourcedirectory
+ ... name="myresources"
+ ... directory="%s" />
+ ... </configure>
+ ... ''' %(dn+'123123234534234'), context=context)
+ Traceback (most recent call last):
+ ...
+ ZopeXMLConfigurationError: ...
+
+Now we can register a directory of resources, also we can set
+resource types:
+
+ >>> context = xmlconfig.string('''
+ ... <configure xmlns:z3ext="http://namespaces.zope.org/z3ext">
+ ... <z3ext:resourcedirectory
+ ... name="myresources"
+ ... directory="%s"
+ ... mapping=".css:zrt .js:fileresource
+ ... resource3.css:cutom .png:null" />
+ ... </configure>
+ ... ''' %dn, context=context)
+
+ >>> dirresource = component.getAdapter(
+ ... request, interface.Interface, name='myresources')
+
+Now we can get resource
+
+ >>> dirresource.browserDefault(request)
+ (<function empty at ...>, ())
+
+ >>> resource = dirresource.publishTraverse(request, 'resource1.css')
+ >>> print resource.GET()
+ h1 {
+ color: #11111111;
+ font: Verdana;
+ background: url('../img1/mybackground.gif');
+ }
+
+ >>> print dirresource['resource1.css'].GET()
+ h1 {
+ color: #11111111;
+ font: Verdana;
+ background: url('../img1/mybackground.gif');
+ }
+
+ >>> dirresource.publishTraverse(request, 'unknown.css')
+ Traceback (most recent call last):
+ ...
+ NotFound: ...
+
+ >>> dirresource['unknown.css']
+ Traceback (most recent call last):
+ ...
+ KeyError: 'unknown.css'
+
+
+Types mapping
+-------------
+
+ In 'mapping' we defined that all files with '.css' extension should be
+custom type, '.js' should be file resource and filename 'test.css'
+should be file resource, '.png' should be not available
+
+ >>> dirresource.publishTraverse(request, 'resource1.css')
+ <z3ext.resource.zrtresource.zrtresource.ZRTFileResource ...>
+
+ >>> dirresource.publishTraverse(request, 'resource2.js')
+ <z3ext.resource.fileresource.FileResource object at ...>
+
+ >>> dirresource.publishTraverse(request, 'resource3.css')
+ <z3ext.resource.fileresource.FileResource object at ...>
+
+ >>> dirresource.publishTraverse(request, 'resource4.jpg')
+ <z3ext.resource.fileresource.FileResource object at ...>
+
+ >>> dirresource.publishTraverse(request, 'resource5.png')
+ Traceback (most recent call last):
+ ...
+ NotFound: Object: ...
+
+Or we can use 'resourceType' subdirective:
+
+ >>> context = xmlconfig.string('''
+ ... <configure xmlns:z3ext="http://namespaces.zope.org/z3ext">
+ ... <z3ext:resourcedirectory
+ ... name="myresources2"
+ ... directory="%s">
+ ... <resourceType file=".css" type="zrt" />
+ ... <resourceType file=".js" type="fileresource" />
+ ... <resourceType file="resource3.css" type="custom" />
+ ... <resourceType file=".png" type="null" />
+ ... </z3ext:resourcedirectory>
+ ... </configure>
+ ... ''' %dn, context=context)
+
+ >>> dirresource = component.getAdapter(
+ ... request, interface.Interface, name='myresources2')
+
+ >>> dirresource.publishTraverse(request, 'resource1.css')
+ <z3ext.resource.zrtresource.zrtresource.ZRTFileResource ...>
+
+ >>> dirresource.publishTraverse(request, 'resource2.js')
+ <z3ext.resource.fileresource.FileResource object at ...>
+
+ >>> dirresource.publishTraverse(request, 'resource3.css')
+ <z3ext.resource.tests.CustomResource object at ...>
+
+ >>> dirresource.publishTraverse(request, 'resource4.jpg')
+ <z3ext.resource.fileresource.FileResource object at ...>
+
+ >>> dirresource.publishTraverse(request, 'resource5.png')
+ Traceback (most recent call last):
+ ...
+ NotFound: Object: ...
+
+
+We can get sub directories
+
+ >>> subdir = dirresource.publishTraverse(request, 'subfolder')
+
+
+ >>> os.unlink(os.path.join(dn, 'resource1.css'))
+ >>> os.unlink(os.path.join(dn, 'resource2.js'))
+ >>> os.unlink(os.path.join(dn, 'resource3.css'))
+ >>> os.unlink(os.path.join(dn, 'resource4.jpg'))
+ >>> os.unlink(os.path.join(dn, 'resource5.png'))
+ >>> os.rmdir(os.path.join(dn, 'subfolder'))
+ >>> os.rmdir(dn)
Deleted: z3ext.resource/tags/1.2.1/src/z3ext/resource/tests.py
===================================================================
--- z3ext.resource/trunk/src/z3ext/resource/tests.py 2008-11-24 23:18:19 UTC (rev 93333)
+++ z3ext.resource/tags/1.2.1/src/z3ext/resource/tests.py 2008-11-25 07:07:13 UTC (rev 93335)
@@ -1,67 +0,0 @@
-##############################################################################
-#
-# Copyright (c) 2007 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.
-#
-##############################################################################
-"""test setup
-
-$Id$
-"""
-__docformat__ = "reStructuredText"
-
-import doctest, unittest
-from zope import component
-from zope.app.testing import placelesssetup
-from zope.traversing import testing
-from zope.traversing.interfaces import ITraversable
-from zope.traversing.namespace import view
-from zope.app.publisher.browser.fileresource import FileResource
-
-from z3ext.resource import fileresource
-from z3ext.resource.interfaces import IResourceFactoryType
-
-
-class CustomResource(fileresource.FileResource):
- pass
-
-
-class CustomFileResourceFactory(fileresource.FileResourceFactory):
-
- def __call__(self, request):
- resource = CustomResource(self._file, request)
- resource.__Security_checker__ = self._checker
- resource.__name__ = self._name
- return resource
-
-
-def setUp(test):
- placelesssetup.setUp(test)
- testing.setUp()
- component.provideAdapter(view, (None, None), ITraversable, name="view")
-
- component.provideUtility(
- fileresource.filefactory, IResourceFactoryType)
- component.provideUtility(
- fileresource.filefactory, IResourceFactoryType, name='fileresource')
- component.provideUtility(
- fileresource.imagefactory, IResourceFactoryType, name='imageresource')
-
- component.provideAdapter(
- fileresource.FileResourceAdapter, (FileResource,))
-
-
-def test_suite():
- return unittest.TestSuite((
- doctest.DocFileSuite(
- 'README.txt',
- setUp=setUp, tearDown=placelesssetup.tearDown,
- optionflags=doctest.NORMALIZE_WHITESPACE|doctest.ELLIPSIS),
- ))
Copied: z3ext.resource/tags/1.2.1/src/z3ext/resource/tests.py (from rev 93334, z3ext.resource/trunk/src/z3ext/resource/tests.py)
===================================================================
--- z3ext.resource/tags/1.2.1/src/z3ext/resource/tests.py (rev 0)
+++ z3ext.resource/tags/1.2.1/src/z3ext/resource/tests.py 2008-11-25 07:07:13 UTC (rev 93335)
@@ -0,0 +1,87 @@
+##############################################################################
+#
+# Copyright (c) 2007 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.
+#
+##############################################################################
+"""test setup
+
+$Id$
+"""
+__docformat__ = "reStructuredText"
+
+import doctest, unittest
+from zope import component, interface
+from zope.app.testing import placelesssetup
+from zope.traversing import testing
+from zope.traversing.interfaces import ITraversable
+from zope.traversing.namespace import view
+from zope.app.publisher.browser.fileresource import FileResource
+
+from z3c.zrtresource.interfaces import IZRTCommandFactory
+
+from zrtresource import zrtresource
+
+from z3ext.resource import fileresource
+from z3ext.resource.interfaces import IResourceFactoryType
+from z3ext.cssregistry.registry import CSSRegistry
+from z3ext.cssregistry import zcml, command, property, interfaces
+
+
+class CustomResource(fileresource.FileResource):
+ pass
+
+
+class CustomFileResourceFactory(fileresource.FileResourceFactory):
+
+ def __call__(self, request):
+ resource = CustomResource(self._file, request)
+ resource.__Security_checker__ = self._checker
+ resource.__name__ = self._name
+ return resource
+
+
+def setUp(test):
+ placelesssetup.setUp(test)
+ testing.setUp()
+ component.provideAdapter(view, (None, None), ITraversable, name="view")
+
+ component.provideUtility(
+ fileresource.filefactory, IResourceFactoryType)
+ component.provideUtility(
+ fileresource.filefactory, IResourceFactoryType, name='fileresource')
+ component.provideUtility(
+ fileresource.imagefactory, IResourceFactoryType, name='imageresource')
+ component.provideUtility(
+ zrtresource.zrtfactory, IResourceFactoryType, name='zrt')
+
+ component.provideAdapter(
+ fileresource.FileResourceAdapter, (FileResource,))
+
+ component.provideUtility(
+ command.cssregistry_factory, IZRTCommandFactory, 'cssregistry')
+
+ registry = CSSRegistry()
+ registry['fontColor']= property.Property('fontColor', '#11111111')
+ registry['fontFamily']= property.Property('fontFamily', 'Verdana')
+
+ component.provideAdapter(
+ zcml.Factory(registry),
+ (interfaces.ICSSRegistryLayer, interfaces.ICSSRegistryLayer,
+ interface.Interface), interfaces.ICSSRegistry, '')
+
+
+def test_suite():
+ return unittest.TestSuite((
+ doctest.DocFileSuite(
+ 'README.txt',
+ setUp=setUp, tearDown=placelesssetup.tearDown,
+ optionflags=doctest.NORMALIZE_WHITESPACE|doctest.ELLIPSIS),
+ ))
More information about the Checkins
mailing list