[Checkins] SVN: zope.browserresource/tags/ Tag 3.9.0
Dan Korostelev
nadako at gmail.com
Thu Aug 27 10:32:39 EDT 2009
Log message for revision 103277:
Tag 3.9.0
Changed:
A zope.browserresource/tags/
A zope.browserresource/tags/3.9.0/
U zope.browserresource/tags/3.9.0/CHANGES.txt
D zope.browserresource/tags/3.9.0/setup.py
A zope.browserresource/tags/3.9.0/setup.py
D zope.browserresource/tags/3.9.0/src/zope/browserresource/interfaces.py
A zope.browserresource/tags/3.9.0/src/zope/browserresource/interfaces.py
D zope.browserresource/tags/3.9.0/src/zope/browserresource/metaconfigure.py
A zope.browserresource/tags/3.9.0/src/zope/browserresource/metaconfigure.py
D zope.browserresource/tags/3.9.0/src/zope/browserresource/metadirectives.py
A zope.browserresource/tags/3.9.0/src/zope/browserresource/metadirectives.py
D zope.browserresource/tags/3.9.0/src/zope/browserresource/resource.py
A zope.browserresource/tags/3.9.0/src/zope/browserresource/resource.py
-=-
Modified: zope.browserresource/tags/3.9.0/CHANGES.txt
===================================================================
--- zope.browserresource/trunk/CHANGES.txt 2009-08-27 14:16:48 UTC (rev 103275)
+++ zope.browserresource/tags/3.9.0/CHANGES.txt 2009-08-27 14:32:38 UTC (rev 103277)
@@ -2,7 +2,7 @@
CHANGES
=======
-3.9.0 (unreleased)
+3.9.0 (2009-08-27)
==================
Initial release. This package was splitted off zope.app.publisher as a part
Deleted: zope.browserresource/tags/3.9.0/setup.py
===================================================================
--- zope.browserresource/trunk/setup.py 2009-08-27 14:16:48 UTC (rev 103275)
+++ zope.browserresource/tags/3.9.0/setup.py 2009-08-27 14:32:38 UTC (rev 103277)
@@ -1,59 +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.
-#
-##############################################################################
-"""zope.browserresource setup
-"""
-from setuptools import setup, find_packages, Extension
-
-long_description = (open('README.txt').read() + '\n\n' +
- open('CHANGES.txt').read())
-
-setup(name='zope.browserresource',
- version = '3.9.0dev',
- url='http://pypi.python.org/pypi/zope.browserresource/',
- author='Zope Corporation and Contributors',
- author_email='zope-dev at zope.org',
- classifiers = ['Environment :: Web Environment',
- 'Intended Audience :: Developers',
- 'License :: OSI Approved :: Zope Public License',
- 'Programming Language :: Python',
- 'Operating System :: OS Independent',
- 'Topic :: Internet :: WWW/HTTP',
- 'Framework :: Zope3',
- ],
- description='Browser resources implementation for Zope.',
- long_description=long_description,
-
- packages=find_packages('src'),
- package_dir={'': 'src'},
-
- namespace_packages=['zope'],
- include_package_data=True,
- install_requires=['setuptools',
- 'zope.component>=3.7.0',
- 'zope.configuration',
- 'zope.contenttype',
- 'zope.i18n',
- 'zope.interface',
- 'zope.location',
- 'zope.publisher>=3.8.0',
- 'zope.schema',
- 'zope.site',
- 'zope.traversing>3.7.0',
- ],
- extras_require={
- 'test': ['zope.testing'],
- },
-
- zip_safe = False,
- )
Copied: zope.browserresource/tags/3.9.0/setup.py (from rev 103276, zope.browserresource/trunk/setup.py)
===================================================================
--- zope.browserresource/tags/3.9.0/setup.py (rev 0)
+++ zope.browserresource/tags/3.9.0/setup.py 2009-08-27 14:32:38 UTC (rev 103277)
@@ -0,0 +1,59 @@
+##############################################################################
+#
+# 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.
+#
+##############################################################################
+"""zope.browserresource setup
+"""
+from setuptools import setup, find_packages, Extension
+
+long_description = (open('README.txt').read() + '\n\n' +
+ open('CHANGES.txt').read())
+
+setup(name='zope.browserresource',
+ version = '3.9.0',
+ url='http://pypi.python.org/pypi/zope.browserresource/',
+ author='Zope Corporation and Contributors',
+ author_email='zope-dev at zope.org',
+ classifiers = ['Environment :: Web Environment',
+ 'Intended Audience :: Developers',
+ 'License :: OSI Approved :: Zope Public License',
+ 'Programming Language :: Python',
+ 'Operating System :: OS Independent',
+ 'Topic :: Internet :: WWW/HTTP',
+ 'Framework :: Zope3',
+ ],
+ description='Browser resources implementation for Zope.',
+ long_description=long_description,
+
+ packages=find_packages('src'),
+ package_dir={'': 'src'},
+
+ namespace_packages=['zope'],
+ include_package_data=True,
+ install_requires=['setuptools',
+ 'zope.component',
+ 'zope.configuration',
+ 'zope.contenttype',
+ 'zope.i18n',
+ 'zope.interface',
+ 'zope.location',
+ 'zope.publisher>=3.8',
+ 'zope.schema',
+ 'zope.site',
+ 'zope.traversing>3.7',
+ ],
+ extras_require={
+ 'test': ['zope.testing'],
+ },
+
+ zip_safe = False,
+ )
Deleted: zope.browserresource/tags/3.9.0/src/zope/browserresource/interfaces.py
===================================================================
--- zope.browserresource/trunk/src/zope/browserresource/interfaces.py 2009-08-27 14:16:48 UTC (rev 103275)
+++ zope.browserresource/tags/3.9.0/src/zope/browserresource/interfaces.py 2009-08-27 14:32:38 UTC (rev 103277)
@@ -1,46 +0,0 @@
-##############################################################################
-#
-# Copyright (c) 2009 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.
-#
-##############################################################################
-"""Resource
-
-$Id$
-"""
-from zope.interface import Interface, Attribute
-
-
-class IResource(Interface):
-
- request = Attribute('Request object that is requesting the resource')
-
- def __call__():
- """return the absolute URL of this resource."""
-
-class IResourceFactory(Interface):
-
- def __call__(request):
- """Return an IResource object"""
-
-class IResourceFactoryFactory(Interface):
- """A factory for IResourceFactory objects
-
- These factories are registered as named utilities that can be selected
- for creating resource factories in a pluggable way.
-
- Resource directories and browser:resource directive use these utilities
- to choose what resource to create, depending on the file extension, so
- third-party packages could easily plug-in additional resource types.
-
- """
-
- def __call__(path, checker, name):
- """Return an IResourceFactory"""
Copied: zope.browserresource/tags/3.9.0/src/zope/browserresource/interfaces.py (from rev 103276, zope.browserresource/trunk/src/zope/browserresource/interfaces.py)
===================================================================
--- zope.browserresource/tags/3.9.0/src/zope/browserresource/interfaces.py (rev 0)
+++ zope.browserresource/tags/3.9.0/src/zope/browserresource/interfaces.py 2009-08-27 14:32:38 UTC (rev 103277)
@@ -0,0 +1,46 @@
+##############################################################################
+#
+# Copyright (c) 2009 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.
+#
+##############################################################################
+"""Resource interfaces
+
+$Id$
+"""
+from zope.interface import Interface, Attribute
+
+
+class IResource(Interface):
+
+ request = Attribute('Request object that is requesting the resource')
+
+ def __call__():
+ """return the absolute URL of this resource."""
+
+class IResourceFactory(Interface):
+
+ def __call__(request):
+ """Return an IResource object"""
+
+class IResourceFactoryFactory(Interface):
+ """A factory for IResourceFactory objects
+
+ These factories are registered as named utilities that can be selected
+ for creating resource factories in a pluggable way.
+
+ Resource directories and browser:resource directive use these utilities
+ to choose what resource to create, depending on the file extension, so
+ third-party packages could easily plug-in additional resource types.
+
+ """
+
+ def __call__(path, checker, name):
+ """Return an IResourceFactory"""
Deleted: zope.browserresource/tags/3.9.0/src/zope/browserresource/metaconfigure.py
===================================================================
--- zope.browserresource/trunk/src/zope/browserresource/metaconfigure.py 2009-08-27 14:16:48 UTC (rev 103275)
+++ zope.browserresource/tags/3.9.0/src/zope/browserresource/metaconfigure.py 2009-08-27 14:32:38 UTC (rev 103277)
@@ -1,264 +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.
-#
-##############################################################################
-"""Browser configuration code
-
-$Id$
-"""
-import os
-
-from zope.component import queryUtility
-from zope.component.interface import provideInterface
-from zope.component.zcml import handler
-from zope.configuration.exceptions import ConfigurationError
-from zope.interface import Interface, implements, classProvides
-from zope.publisher.interfaces.browser import IBrowserRequest
-from zope.publisher.interfaces.browser import IDefaultBrowserLayer
-from zope.security.checker import CheckerPublic, NamesChecker, Checker
-from zope.security.proxy import Proxy
-
-from zope.browserresource.directory import DirectoryResourceFactory
-from zope.browserresource.file import File, FileResourceFactory
-from zope.browserresource.i18nfile import I18nFileResourceFactory
-from zope.browserresource.icon import IconViewFactory
-from zope.browserresource.interfaces import IResourceFactory
-from zope.browserresource.interfaces import IResourceFactoryFactory
-
-allowed_names = ('GET', 'HEAD', 'publishTraverse', 'browserDefault',
- 'request', '__call__')
-
-class ResourceFactoryWrapper(object):
-
- implements(IResourceFactory)
- classProvides(IResourceFactoryFactory)
-
- def __init__(self, factory, checker, name):
- self.__factory = factory
- self.__checker = checker
- self.__name = name
-
- def __call__(self, request):
- resource = self.__factory(request)
- resource.__Security_checker__ = self.__checker
- resource.__name__ = self.__name
- return resource
-
-
-def resource(_context, name, layer=IDefaultBrowserLayer,
- permission='zope.Public', factory=None,
- file=None, image=None, template=None):
-
- if permission == 'zope.Public':
- permission = CheckerPublic
-
- checker = NamesChecker(allowed_names, permission)
-
- if (factory and (file or image or template)) or \
- (file and (factory or image or template)) or \
- (image and (factory or file or template)) or \
- (template and (factory or file or image)):
- raise ConfigurationError(
- "Must use exactly one of factory or file or image or template"
- " attributes for resource directives"
- )
-
- if image or template:
- import warnings
- warnings.warn_explicit(
- '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,
- _context.info.file, _context.info.line)
- if image:
- file = image
- elif template:
- file = template
-
- _context.action(
- discriminator = ('resource', name, IBrowserRequest, layer),
- callable = resourceHandler,
- args = (name, layer, checker, factory, file, _context.info),
- )
-
-
-def resourceHandler(name, layer, checker, factory, file, context_info):
- if factory is not None:
- factory = ResourceFactoryWrapper(factory, checker, name)
- else:
- ext = os.path.splitext(os.path.normcase(file))[1][1:]
- factory_factory = queryUtility(IResourceFactoryFactory, ext,
- FileResourceFactory)
- factory = factory_factory(file, checker, name)
- handler('registerAdapter', factory, (layer,), Interface, name, context_info)
-
-
-def resourceDirectory(_context, name, directory, layer=IDefaultBrowserLayer,
- permission='zope.Public'):
- if permission == 'zope.Public':
- permission = CheckerPublic
-
- checker = NamesChecker(allowed_names + ('__getitem__', 'get'),
- permission)
-
- if not os.path.isdir(directory):
- raise ConfigurationError(
- "Directory %s does not exist" % directory
- )
-
- factory = DirectoryResourceFactory(directory, checker, name)
- _context.action(
- discriminator = ('resource', name, IBrowserRequest, layer),
- callable = handler,
- args = ('registerAdapter',
- factory, (layer,), Interface, name, _context.info),
- )
-
-
-def icon(_context, name, for_, file=None, resource=None,
- layer=IDefaultBrowserLayer, title=None,
- width=16, height=16):
-
- iname = for_.getName()
-
- if title is None:
- title = iname
- if title.startswith('I'):
- title = title[1:] # Remove leading 'I'
-
- if file is not None and resource is not None:
- raise ConfigurationError(
- "Can't use more than one of file, and resource "
- "attributes for icon directives"
- )
- elif file is not None:
- resource = '-'.join(for_.__module__.split('.'))
- resource = "%s-%s-%s" % (resource, iname, name)
- ext = os.path.splitext(file)[1]
- if ext:
- resource += ext
-
- # give this module another name, so we can use the "resource" directive
- # in it that won't conflict with our local variable with the same name.
- from zope.browserresource import metaconfigure
- metaconfigure.resource(_context, file=file, name=resource, layer=layer)
- elif resource is None:
- raise ConfigurationError(
- "At least one of the file, and resource "
- "attributes for resource directives must be specified"
- )
-
- vfactory = IconViewFactory(resource, title, width, height)
-
- _context.action(
- discriminator = ('view', name, vfactory, layer),
- callable = handler,
- args = ('registerAdapter',
- vfactory, (for_, layer), Interface, name, _context.info)
- )
-
- _context.action(
- discriminator = None,
- callable = provideInterface,
- args = (for_.__module__+'.'+for_.getName(),
- for_)
- )
-
-
-class I18nResource(object):
-
- type = IBrowserRequest
- default_allowed_attributes = '__call__'
-
- def __init__(self, _context, name=None, defaultLanguage='en',
- layer=IDefaultBrowserLayer, permission=None):
- self._context = _context
- self.name = name
- self.defaultLanguage = defaultLanguage
- self.layer = layer
- self.permission = permission
- self.__data = {}
-
- def translation(self, _context, language, file=None, image=None):
-
- if file is not None and image is not None:
- raise ConfigurationError(
- "Can't use more than one of file, and image "
- "attributes for resource directives"
- )
- elif file is None and image is None:
- raise ConfigurationError(
- "At least one of the file, and image "
- "attributes for resource directives must be specified"
- )
-
- if image is not None:
- import warnings
- warnings.warn_explicit(
- 'The "image" attribute of i18n-resource directive is '
- 'deprecated in favor of simple files. Use the "file" '
- 'attribute instead.',
- DeprecationWarning,
- _context.info.file, _context.info.line)
- file = image
-
- self.__data[language] = File(_context.path(file), self.name)
-
-
- def __call__(self, require = None):
- if self.name is None:
- return
-
- if self.defaultLanguage not in self.__data:
- raise ConfigurationError(
- "A translation for the default language (%s) "
- "must be specified" % self.defaultLanguage
- )
-
- permission = self.permission
- factory = I18nFileResourceFactory(self.__data, self.defaultLanguage)
-
- if permission:
- if require is None:
- require = {}
-
- if permission == 'zope.Public':
- permission = CheckerPublic
-
- if require:
- checker = Checker(require)
-
- factory = self._proxyFactory(factory, checker)
-
- self._context.action(
- discriminator = ('i18n-resource', self.name, self.type, self.layer),
- callable = handler,
- args = ('registerAdapter',
- factory, (self.layer,), Interface, self.name,
- self._context.info)
- )
-
-
- def _proxyFactory(self, factory, checker):
- def proxyView(request,
- factory=factory, checker=checker):
- resource = factory(request)
-
- # We need this in case the resource gets unwrapped and
- # needs to be rewrapped
- resource.__Security_checker__ = checker
-
- return Proxy(resource, checker)
-
- return proxyView
Copied: zope.browserresource/tags/3.9.0/src/zope/browserresource/metaconfigure.py (from rev 103276, zope.browserresource/trunk/src/zope/browserresource/metaconfigure.py)
===================================================================
--- zope.browserresource/tags/3.9.0/src/zope/browserresource/metaconfigure.py (rev 0)
+++ zope.browserresource/tags/3.9.0/src/zope/browserresource/metaconfigure.py 2009-08-27 14:32:38 UTC (rev 103277)
@@ -0,0 +1,264 @@
+##############################################################################
+#
+# 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.
+#
+##############################################################################
+"""ZCML directive handlers for browser resources
+
+$Id$
+"""
+import os
+
+from zope.component import queryUtility
+from zope.component.interface import provideInterface
+from zope.component.zcml import handler
+from zope.configuration.exceptions import ConfigurationError
+from zope.interface import Interface, implements, classProvides
+from zope.publisher.interfaces.browser import IBrowserRequest
+from zope.publisher.interfaces.browser import IDefaultBrowserLayer
+from zope.security.checker import CheckerPublic, NamesChecker, Checker
+from zope.security.proxy import Proxy
+
+from zope.browserresource.directory import DirectoryResourceFactory
+from zope.browserresource.file import File, FileResourceFactory
+from zope.browserresource.i18nfile import I18nFileResourceFactory
+from zope.browserresource.icon import IconViewFactory
+from zope.browserresource.interfaces import IResourceFactory
+from zope.browserresource.interfaces import IResourceFactoryFactory
+
+allowed_names = ('GET', 'HEAD', 'publishTraverse', 'browserDefault',
+ 'request', '__call__')
+
+class ResourceFactoryWrapper(object):
+
+ implements(IResourceFactory)
+ classProvides(IResourceFactoryFactory)
+
+ def __init__(self, factory, checker, name):
+ self.__factory = factory
+ self.__checker = checker
+ self.__name = name
+
+ def __call__(self, request):
+ resource = self.__factory(request)
+ resource.__Security_checker__ = self.__checker
+ resource.__name__ = self.__name
+ return resource
+
+
+def resource(_context, name, layer=IDefaultBrowserLayer,
+ permission='zope.Public', factory=None,
+ file=None, image=None, template=None):
+
+ if permission == 'zope.Public':
+ permission = CheckerPublic
+
+ checker = NamesChecker(allowed_names, permission)
+
+ if (factory and (file or image or template)) or \
+ (file and (factory or image or template)) or \
+ (image and (factory or file or template)) or \
+ (template and (factory or file or image)):
+ raise ConfigurationError(
+ "Must use exactly one of factory or file or image or template"
+ " attributes for resource directives"
+ )
+
+ if image or template:
+ import warnings
+ warnings.warn_explicit(
+ '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,
+ _context.info.file, _context.info.line)
+ if image:
+ file = image
+ elif template:
+ file = template
+
+ _context.action(
+ discriminator = ('resource', name, IBrowserRequest, layer),
+ callable = resourceHandler,
+ args = (name, layer, checker, factory, file, _context.info),
+ )
+
+
+def resourceHandler(name, layer, checker, factory, file, context_info):
+ if factory is not None:
+ factory = ResourceFactoryWrapper(factory, checker, name)
+ else:
+ ext = os.path.splitext(os.path.normcase(file))[1][1:]
+ factory_factory = queryUtility(IResourceFactoryFactory, ext,
+ FileResourceFactory)
+ factory = factory_factory(file, checker, name)
+ handler('registerAdapter', factory, (layer,), Interface, name, context_info)
+
+
+def resourceDirectory(_context, name, directory, layer=IDefaultBrowserLayer,
+ permission='zope.Public'):
+ if permission == 'zope.Public':
+ permission = CheckerPublic
+
+ checker = NamesChecker(allowed_names + ('__getitem__', 'get'),
+ permission)
+
+ if not os.path.isdir(directory):
+ raise ConfigurationError(
+ "Directory %s does not exist" % directory
+ )
+
+ factory = DirectoryResourceFactory(directory, checker, name)
+ _context.action(
+ discriminator = ('resource', name, IBrowserRequest, layer),
+ callable = handler,
+ args = ('registerAdapter',
+ factory, (layer,), Interface, name, _context.info),
+ )
+
+
+def icon(_context, name, for_, file=None, resource=None,
+ layer=IDefaultBrowserLayer, title=None,
+ width=16, height=16):
+
+ iname = for_.getName()
+
+ if title is None:
+ title = iname
+ if title.startswith('I'):
+ title = title[1:] # Remove leading 'I'
+
+ if file is not None and resource is not None:
+ raise ConfigurationError(
+ "Can't use more than one of file, and resource "
+ "attributes for icon directives"
+ )
+ elif file is not None:
+ resource = '-'.join(for_.__module__.split('.'))
+ resource = "%s-%s-%s" % (resource, iname, name)
+ ext = os.path.splitext(file)[1]
+ if ext:
+ resource += ext
+
+ # give this module another name, so we can use the "resource" directive
+ # in it that won't conflict with our local variable with the same name.
+ from zope.browserresource import metaconfigure
+ metaconfigure.resource(_context, file=file, name=resource, layer=layer)
+ elif resource is None:
+ raise ConfigurationError(
+ "At least one of the file, and resource "
+ "attributes for resource directives must be specified"
+ )
+
+ vfactory = IconViewFactory(resource, title, width, height)
+
+ _context.action(
+ discriminator = ('view', name, vfactory, layer),
+ callable = handler,
+ args = ('registerAdapter',
+ vfactory, (for_, layer), Interface, name, _context.info)
+ )
+
+ _context.action(
+ discriminator = None,
+ callable = provideInterface,
+ args = (for_.__module__+'.'+for_.getName(),
+ for_)
+ )
+
+
+class I18nResource(object):
+
+ type = IBrowserRequest
+ default_allowed_attributes = '__call__'
+
+ def __init__(self, _context, name=None, defaultLanguage='en',
+ layer=IDefaultBrowserLayer, permission=None):
+ self._context = _context
+ self.name = name
+ self.defaultLanguage = defaultLanguage
+ self.layer = layer
+ self.permission = permission
+ self.__data = {}
+
+ def translation(self, _context, language, file=None, image=None):
+
+ if file is not None and image is not None:
+ raise ConfigurationError(
+ "Can't use more than one of file, and image "
+ "attributes for resource directives"
+ )
+ elif file is None and image is None:
+ raise ConfigurationError(
+ "At least one of the file, and image "
+ "attributes for resource directives must be specified"
+ )
+
+ if image is not None:
+ import warnings
+ warnings.warn_explicit(
+ 'The "image" attribute of i18n-resource directive is '
+ 'deprecated in favor of simple files. Use the "file" '
+ 'attribute instead.',
+ DeprecationWarning,
+ _context.info.file, _context.info.line)
+ file = image
+
+ self.__data[language] = File(_context.path(file), self.name)
+
+
+ def __call__(self, require = None):
+ if self.name is None:
+ return
+
+ if self.defaultLanguage not in self.__data:
+ raise ConfigurationError(
+ "A translation for the default language (%s) "
+ "must be specified" % self.defaultLanguage
+ )
+
+ permission = self.permission
+ factory = I18nFileResourceFactory(self.__data, self.defaultLanguage)
+
+ if permission:
+ if require is None:
+ require = {}
+
+ if permission == 'zope.Public':
+ permission = CheckerPublic
+
+ if require:
+ checker = Checker(require)
+
+ factory = self._proxyFactory(factory, checker)
+
+ self._context.action(
+ discriminator = ('i18n-resource', self.name, self.type, self.layer),
+ callable = handler,
+ args = ('registerAdapter',
+ factory, (self.layer,), Interface, self.name,
+ self._context.info)
+ )
+
+
+ def _proxyFactory(self, factory, checker):
+ def proxyView(request,
+ factory=factory, checker=checker):
+ resource = factory(request)
+
+ # We need this in case the resource gets unwrapped and
+ # needs to be rewrapped
+ resource.__Security_checker__ = checker
+
+ return Proxy(resource, checker)
+
+ return proxyView
Deleted: zope.browserresource/tags/3.9.0/src/zope/browserresource/metadirectives.py
===================================================================
--- zope.browserresource/trunk/src/zope/browserresource/metadirectives.py 2009-08-27 14:16:48 UTC (rev 103275)
+++ zope.browserresource/tags/3.9.0/src/zope/browserresource/metadirectives.py 2009-08-27 14:32:38 UTC (rev 103277)
@@ -1,247 +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.
-#
-##############################################################################
-"""Browser configuration code
-
-This module defines the schemas for browser directives.
-
-$Id$
-"""
-from zope.configuration.fields import GlobalObject, GlobalInterface
-from zope.configuration.fields import Path, MessageID
-from zope.interface import Interface
-from zope.schema import TextLine, Int
-from zope.security.zcml import Permission
-
-
-class IBasicResourceInformation(Interface):
- """
- This is the basic information for all browser resources.
- """
-
- layer = GlobalInterface(
- title=u"The layer the resource should be found in",
- description=u"""
- For information on layers, see the documentation for the skin
- directive. Defaults to "default".""",
- required=False
- )
-
- permission = Permission(
- title=u"The permission needed to access the resource.",
- description=u"""
- If a permission isn't specified, the resource will always be
- accessible.""",
- required=False
- )
-
-class IResourceDirective(IBasicResourceInformation):
- """
- Defines a browser resource
- """
-
- name = TextLine(
- title=u"The name of the resource",
- description=u"""
- This is the name used in resource urls. Resource urls are of
- the form site/@@/resourcename, where site is the url of
- "site", a folder with a site manager.
-
- We make resource urls site-relative (as opposed to
- content-relative) so as not to defeat caches.""",
- required=True
- )
-
- factory = GlobalObject(
- title=u"Resource Factory",
- description=u"The factory used to create the resource. The factory "
- u"should only expect to get the request passed when "
- u"called.",
- required=False
- )
-
- file = Path(
- title=u"File",
- description=u"The file containing the resource data. The resource "
- u"type that will be created depends on file extension. "
- u"The named IResourceFactoryFactory utilities are "
- u"registered per extension. If no factory is registered "
- u"for given file extension, the default FileResource "
- u"factory will be used.",
- required=False
- )
-
- image = Path(
- title=u"Image",
- description=u"""
- If the image attribute is used, then an image resource, rather
- than a file resource will be created.
-
- This attribute is deprecated in favor of pluggable resource types,
- registered per extension. Use the "file" attribute instead.
- """,
- required=False
- )
-
- template = Path(
- title=u"Template",
- description=u"""
- If the template attribute is used, then a page template resource,
- rather than a file resource will be created.
-
- This attribute is deprecated in favor of pluggable resource types,
- registered per extension. Use the "file" attribute instead. To
- use page template resources, you need to instal zope.ptresource
- package.
- """,
- required=False
- )
-
-class II18nResourceDirective(IBasicResourceInformation):
- """
- Defines an i18n'd resource.
- """
-
- name = TextLine(
- title=u"The name of the resource",
- description=u"""
- This is the name used in resource urls. Resource urls are of
- the form site/@@/resourcename, where site is the url of
- "site", a folder with a site manager.
-
- We make resource urls site-relative (as opposed to
- content-relative) so as not to defeat caches.""",
- required=True
- )
-
- defaultLanguage = TextLine(
- title=u"Default language",
- description=u"Defines the default language",
- required=False
- )
-
-class II18nResourceTranslationSubdirective(IBasicResourceInformation):
- """
- Subdirective to II18nResourceDirective.
- """
-
- language = TextLine(
- title=u"Language",
- description=u"Language of this translation of the resource",
- required=True
- )
-
- file = Path(
- title=u"File",
- description=u"The file containing the resource data.",
- required=False
- )
-
- image = Path(
- title=u"Image",
- description=u"""
- If the image attribute is used, then an image resource, rather
- than a file resource will be created.
-
- This attribute is deprecated, as images are now simply files.
- Use the "file" attribute instead.
- """,
- required=False
- )
-
-class IResourceDirectoryDirective(IBasicResourceInformation):
- """
- Defines a directory containing browser resource
- """
-
- name = TextLine(
- title=u"The name of the resource",
- description=u"""
- This is the name used in resource urls. Resource urls are of
- the form site/@@/resourcename, where site is the url of
- "site", a folder with a site manager.
-
- We make resource urls site-relative (as opposed to
- content-relative) so as not to defeat caches.""",
- required=True
- )
-
- directory = Path(
- title=u"Directory",
- description=u"The directory containing the resource data.",
- required=True
- )
-
-
-class IIconDirective(Interface):
- """
- Define an icon for an interface
- """
-
- name = TextLine(
- title=u"The name of the icon.",
- description=u"The name shows up in URLs/paths. For example 'foo'.",
- required=True
- )
-
- for_ = GlobalInterface(
- title=u"The interface this icon is for.",
- description=u"""
- The icon will be for all objects that implement this
- interface.""",
- required=True
- )
-
- file = Path(
- title=u"File",
- description=u"The file containing the icon.",
- required=False
- )
-
- resource = TextLine(
- title=u"Resource",
- description=u"A resource containing the icon.",
- required=False
- )
-
- title = MessageID(
- title=u"Title",
- description=u"Descriptive title",
- required=False
- )
-
- layer = GlobalInterface(
- title=u"The layer the icon should be found in",
- description=u"""
- For information on layers, see the documentation for the skin
- directive. Defaults to "default".""",
- required=False
- )
-
- width = Int(
- title=u"The width of the icon.",
- description=u"""
- The width will be used for the <img width="..." />
- attribute. Defaults to 16.""",
- required=False,
- default=16
- )
-
- height = Int(
- title=u"The height of the icon.",
- description=u"""
- The height will be used for the <img height="..." />
- attribute. Defaults to 16.""",
- required=False,
- default=16
- )
Copied: zope.browserresource/tags/3.9.0/src/zope/browserresource/metadirectives.py (from rev 103276, zope.browserresource/trunk/src/zope/browserresource/metadirectives.py)
===================================================================
--- zope.browserresource/tags/3.9.0/src/zope/browserresource/metadirectives.py (rev 0)
+++ zope.browserresource/tags/3.9.0/src/zope/browserresource/metadirectives.py 2009-08-27 14:32:38 UTC (rev 103277)
@@ -0,0 +1,245 @@
+#############################################################################
+#
+# 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.
+#
+##############################################################################
+"""ZCML directives for defining browser resources
+
+$Id$
+"""
+from zope.configuration.fields import GlobalObject, GlobalInterface
+from zope.configuration.fields import Path, MessageID
+from zope.interface import Interface
+from zope.schema import TextLine, Int
+from zope.security.zcml import Permission
+
+
+class IBasicResourceInformation(Interface):
+ """
+ This is the basic information for all browser resources.
+ """
+
+ layer = GlobalInterface(
+ title=u"The layer the resource should be found in",
+ description=u"""
+ For information on layers, see the documentation for the skin
+ directive. Defaults to "default".""",
+ required=False
+ )
+
+ permission = Permission(
+ title=u"The permission needed to access the resource.",
+ description=u"""
+ If a permission isn't specified, the resource will always be
+ accessible.""",
+ required=False
+ )
+
+class IResourceDirective(IBasicResourceInformation):
+ """
+ Defines a browser resource
+ """
+
+ name = TextLine(
+ title=u"The name of the resource",
+ description=u"""
+ This is the name used in resource urls. Resource urls are of
+ the form site/@@/resourcename, where site is the url of
+ "site", a folder with a site manager.
+
+ We make resource urls site-relative (as opposed to
+ content-relative) so as not to defeat caches.""",
+ required=True
+ )
+
+ factory = GlobalObject(
+ title=u"Resource Factory",
+ description=u"The factory used to create the resource. The factory "
+ u"should only expect to get the request passed when "
+ u"called.",
+ required=False
+ )
+
+ file = Path(
+ title=u"File",
+ description=u"The file containing the resource data. The resource "
+ u"type that will be created depends on file extension. "
+ u"The named IResourceFactoryFactory utilities are "
+ u"registered per extension. If no factory is registered "
+ u"for given file extension, the default FileResource "
+ u"factory will be used.",
+ required=False
+ )
+
+ image = Path(
+ title=u"Image",
+ description=u"""
+ If the image attribute is used, then an image resource, rather
+ than a file resource will be created.
+
+ This attribute is deprecated in favor of pluggable resource types,
+ registered per extension. Use the "file" attribute instead.
+ """,
+ required=False
+ )
+
+ template = Path(
+ title=u"Template",
+ description=u"""
+ If the template attribute is used, then a page template resource,
+ rather than a file resource will be created.
+
+ This attribute is deprecated in favor of pluggable resource types,
+ registered per extension. Use the "file" attribute instead. To
+ use page template resources, you need to instal zope.ptresource
+ package.
+ """,
+ required=False
+ )
+
+class II18nResourceDirective(IBasicResourceInformation):
+ """
+ Defines an i18n'd resource.
+ """
+
+ name = TextLine(
+ title=u"The name of the resource",
+ description=u"""
+ This is the name used in resource urls. Resource urls are of
+ the form site/@@/resourcename, where site is the url of
+ "site", a folder with a site manager.
+
+ We make resource urls site-relative (as opposed to
+ content-relative) so as not to defeat caches.""",
+ required=True
+ )
+
+ defaultLanguage = TextLine(
+ title=u"Default language",
+ description=u"Defines the default language",
+ required=False
+ )
+
+class II18nResourceTranslationSubdirective(IBasicResourceInformation):
+ """
+ Subdirective to II18nResourceDirective.
+ """
+
+ language = TextLine(
+ title=u"Language",
+ description=u"Language of this translation of the resource",
+ required=True
+ )
+
+ file = Path(
+ title=u"File",
+ description=u"The file containing the resource data.",
+ required=False
+ )
+
+ image = Path(
+ title=u"Image",
+ description=u"""
+ If the image attribute is used, then an image resource, rather
+ than a file resource will be created.
+
+ This attribute is deprecated, as images are now simply files.
+ Use the "file" attribute instead.
+ """,
+ required=False
+ )
+
+class IResourceDirectoryDirective(IBasicResourceInformation):
+ """
+ Defines a directory containing browser resource
+ """
+
+ name = TextLine(
+ title=u"The name of the resource",
+ description=u"""
+ This is the name used in resource urls. Resource urls are of
+ the form site/@@/resourcename, where site is the url of
+ "site", a folder with a site manager.
+
+ We make resource urls site-relative (as opposed to
+ content-relative) so as not to defeat caches.""",
+ required=True
+ )
+
+ directory = Path(
+ title=u"Directory",
+ description=u"The directory containing the resource data.",
+ required=True
+ )
+
+
+class IIconDirective(Interface):
+ """
+ Define an icon for an interface
+ """
+
+ name = TextLine(
+ title=u"The name of the icon.",
+ description=u"The name shows up in URLs/paths. For example 'foo'.",
+ required=True
+ )
+
+ for_ = GlobalInterface(
+ title=u"The interface this icon is for.",
+ description=u"""
+ The icon will be for all objects that implement this
+ interface.""",
+ required=True
+ )
+
+ file = Path(
+ title=u"File",
+ description=u"The file containing the icon.",
+ required=False
+ )
+
+ resource = TextLine(
+ title=u"Resource",
+ description=u"A resource containing the icon.",
+ required=False
+ )
+
+ title = MessageID(
+ title=u"Title",
+ description=u"Descriptive title",
+ required=False
+ )
+
+ layer = GlobalInterface(
+ title=u"The layer the icon should be found in",
+ description=u"""
+ For information on layers, see the documentation for the skin
+ directive. Defaults to "default".""",
+ required=False
+ )
+
+ width = Int(
+ title=u"The width of the icon.",
+ description=u"""
+ The width will be used for the <img width="..." />
+ attribute. Defaults to 16.""",
+ required=False,
+ default=16
+ )
+
+ height = Int(
+ title=u"The height of the icon.",
+ description=u"""
+ The height will be used for the <img height="..." />
+ attribute. Defaults to 16.""",
+ required=False,
+ default=16
+ )
Deleted: zope.browserresource/tags/3.9.0/src/zope/browserresource/resource.py
===================================================================
--- zope.browserresource/trunk/src/zope/browserresource/resource.py 2009-08-27 14:16:48 UTC (rev 103275)
+++ zope.browserresource/tags/3.9.0/src/zope/browserresource/resource.py 2009-08-27 14:32:38 UTC (rev 103277)
@@ -1,65 +0,0 @@
-##############################################################################
-#
-# Copyright (c) 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.
-#
-##############################################################################
-"""Browser Resource
-
-$Id$
-"""
-from zope.component import adapts, getMultiAdapter, queryMultiAdapter
-from zope.interface import implements, implementsOnly
-from zope.location import Location
-from zope.publisher.interfaces.browser import IBrowserRequest
-from zope.site.hooks import getSite
-from zope.traversing.browser.interfaces import IAbsoluteURL
-import zope.traversing.browser.absoluteurl
-
-from zope.browserresource.interfaces import IResource
-
-
-class Resource(Location):
-
- implements(IResource)
-
- def __init__(self, request):
- self.request = request
-
- def __call__(self):
- return str(getMultiAdapter((self, self.request), IAbsoluteURL))
-
-
-class AbsoluteURL(zope.traversing.browser.absoluteurl.AbsoluteURL):
-
- implementsOnly(IAbsoluteURL)
- adapts(IResource, IBrowserRequest)
-
- def __init__(self, context, request):
- self.context = context
- self.request = request
-
- def _createUrl(self, baseUrl, name):
- return "%s/@@/%s" % (baseUrl, name)
-
- def __str__(self):
- name = self.context.__name__
- if name.startswith('++resource++'):
- name = name[12:]
-
- site = getSite()
- base = queryMultiAdapter((site, self.request), IAbsoluteURL,
- name="resource")
- if base is None:
- url = str(getMultiAdapter((site, self.request), IAbsoluteURL))
- else:
- url = str(base)
-
- return self._createUrl(url, name)
Copied: zope.browserresource/tags/3.9.0/src/zope/browserresource/resource.py (from rev 103276, zope.browserresource/trunk/src/zope/browserresource/resource.py)
===================================================================
--- zope.browserresource/tags/3.9.0/src/zope/browserresource/resource.py (rev 0)
+++ zope.browserresource/tags/3.9.0/src/zope/browserresource/resource.py 2009-08-27 14:32:38 UTC (rev 103277)
@@ -0,0 +1,65 @@
+##############################################################################
+#
+# Copyright (c) 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.
+#
+##############################################################################
+"""Resource base class and AbsoluteURL adapter
+
+$Id$
+"""
+from zope.component import adapts, getMultiAdapter, queryMultiAdapter
+from zope.interface import implements, implementsOnly
+from zope.location import Location
+from zope.publisher.interfaces.browser import IBrowserRequest
+from zope.site.hooks import getSite
+from zope.traversing.browser.interfaces import IAbsoluteURL
+import zope.traversing.browser.absoluteurl
+
+from zope.browserresource.interfaces import IResource
+
+
+class Resource(Location):
+
+ implements(IResource)
+
+ def __init__(self, request):
+ self.request = request
+
+ def __call__(self):
+ return str(getMultiAdapter((self, self.request), IAbsoluteURL))
+
+
+class AbsoluteURL(zope.traversing.browser.absoluteurl.AbsoluteURL):
+
+ implementsOnly(IAbsoluteURL)
+ adapts(IResource, IBrowserRequest)
+
+ def __init__(self, context, request):
+ self.context = context
+ self.request = request
+
+ def _createUrl(self, baseUrl, name):
+ return "%s/@@/%s" % (baseUrl, name)
+
+ def __str__(self):
+ name = self.context.__name__
+ if name.startswith('++resource++'):
+ name = name[12:]
+
+ site = getSite()
+ base = queryMultiAdapter((site, self.request), IAbsoluteURL,
+ name="resource")
+ if base is None:
+ url = str(getMultiAdapter((site, self.request), IAbsoluteURL))
+ else:
+ url = str(base)
+
+ return self._createUrl(url, name)
More information about the Checkins
mailing list