Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Deactivted all BBB to ensure that we use only the latest code in zope…
….app Made almost all tests pass again, except the few that heavily depended on the old way of doing things: apidoc, module, presentation
- Loading branch information
0 parents
commit cb1aa9e
Showing
24 changed files
with
4,296 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
############################################################################# | ||
# | ||
# 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-Presentation related Fields. | ||
$Id$ | ||
""" | ||
__docformat__ = 'restructuredtext' | ||
|
||
import zope.schema | ||
from zope.component.exceptions import ComponentLookupError | ||
from zope.configuration.exceptions import ConfigurationError | ||
from zope.configuration.fields import GlobalObject | ||
from zope.interface.interfaces import IInterface | ||
from zope.app.publisher.interfaces.browser import IMenuItemType | ||
|
||
from zope.app import zapi | ||
|
||
|
||
class MenuField(GlobalObject): | ||
r"""This fields represents a menu (item type). | ||
Besides being able to look up the menu by importing it, we also try | ||
to look up the name in the utility service. | ||
>>> from zope.interface import directlyProvides | ||
>>> from zope.interface.interface import InterfaceClass | ||
>>> menu1 = InterfaceClass('menu1', (), | ||
... __doc__='Menu Item Type: menu1', | ||
... __module__='zope.app.menus') | ||
>>> directlyProvides(menu1, IMenuItemType) | ||
>>> menus = None | ||
>>> class Resolver(object): | ||
... def resolve(self, path): | ||
... if path.startswith('zope.app.menus') and \ | ||
... hasattr(menus, 'menu1') or \ | ||
... path == 'zope.app.component.menus.menu1': | ||
... return menu1 | ||
... raise ConfigurationError, 'menu1' | ||
>>> field = MenuField() | ||
>>> field = field.bind(Resolver()) | ||
Test 1: Import the menu | ||
----------------------- | ||
>>> field.fromUnicode('zope.app.component.menus.menu1') is menu1 | ||
True | ||
Test 2: We have a shortcut name. Import the menu from `zope.app.menus1`. | ||
------------------------------------------------------------------------ | ||
>>> from types import ModuleType as module | ||
>>> import sys | ||
>>> menus = module('menus') | ||
>>> old = sys.modules.get('zope.app.menus', None) | ||
>>> sys.modules['zope.app.menus'] = menus | ||
>>> setattr(menus, 'menu1', menu1) | ||
>>> field.fromUnicode('menu1') is menu1 | ||
True | ||
>>> if old is not None: | ||
... sys.modules['zope.app.menus'] = old | ||
Test 3: Get the menu from the utility service | ||
--------------------------------------------- | ||
>>> from zope.app.testing import ztapi | ||
>>> ztapi.provideUtility(IMenuItemType, menu1, 'menu1') | ||
>>> field.fromUnicode('menu1') is menu1 | ||
True | ||
""" | ||
|
||
def fromUnicode(self, u): | ||
name = str(u.strip()) | ||
|
||
try: | ||
value = zapi.queryUtility(IMenuItemType, name) | ||
except ComponentLookupError: | ||
# The component architecture is not up and running. | ||
pass | ||
else: | ||
if value is not None: | ||
self.validate(value) | ||
return value | ||
|
||
try: | ||
value = self.context.resolve('zope.app.menus.'+name) | ||
except ConfigurationError, v: | ||
try: | ||
value = self.context.resolve(name) | ||
except ConfigurationError, v: | ||
raise zope.schema.ValidationError(v) | ||
|
||
self.validate(value) | ||
return value |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
############################################################################## | ||
# | ||
# 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$ | ||
""" | ||
from zope.configuration.exceptions import ConfigurationError | ||
from zope.interface import Interface | ||
from zope.publisher.interfaces.browser import IBrowserRequest | ||
from zope.publisher.interfaces.browser import IDefaultBrowserLayer | ||
from zope.security.proxy import Proxy | ||
from zope.security.checker import CheckerPublic, Checker | ||
|
||
from zope.app import zapi | ||
from zope.app.component.metaconfigure import handler | ||
from zope.app.publisher.fileresource import File, Image | ||
|
||
from i18nfileresource import I18nFileResourceFactory | ||
|
||
|
||
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 = {} | ||
self.__format = None | ||
|
||
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 not None: | ||
if self.__format is not None and self.__format != File: | ||
raise ConfigurationError( | ||
"Can't use both files and images in the same " | ||
"i18n-resource directive" | ||
) | ||
self.__data[language] = File(_context.path(file), self.name) | ||
self.__format = File | ||
elif image is not None: | ||
if self.__format is not None and self.__format != Image: | ||
raise ConfigurationError( | ||
"Can't use both files and images in the same " | ||
"i18n-resource directive" | ||
) | ||
self.__data[language] = Image(_context.path(image), self.name) | ||
self.__format = Image | ||
else: | ||
raise ConfigurationError( | ||
"At least one of the file, and image " | ||
"attributes for resource directives must be specified" | ||
) | ||
|
||
return () | ||
|
||
|
||
def __call__(self, require = None): | ||
if self.name is None: | ||
return () | ||
|
||
if not self.__data.has_key(self.defaultLanguage): | ||
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 = ('provideAdapter', | ||
(self.layer,), Interface, self.name, factory, | ||
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
############################################################################## | ||
# | ||
# 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. | ||
# | ||
############################################################################## | ||
"""Icon support | ||
$Id$ | ||
""" | ||
import os | ||
import re | ||
|
||
from zope.interface import Interface | ||
from zope.publisher.interfaces.browser import IDefaultBrowserLayer | ||
from zope.configuration.exceptions import ConfigurationError | ||
|
||
from zope.app import zapi | ||
from zope.app.component.interface import provideInterface | ||
from zope.app.component.metaconfigure import handler | ||
from zope.app.publisher.browser import metaconfigure | ||
from zope.app.traversing.namespace import getResource | ||
|
||
IName = re.compile('I[A-Z][a-z]') | ||
|
||
class IconView(object): | ||
|
||
def __init__(self, context, request, rname, alt): | ||
self.context = context | ||
self.request = request | ||
self.rname = rname | ||
self.alt = alt | ||
|
||
def __call__(self): | ||
# The context is important here, since it becomes the parent of the | ||
# icon, which is needed to generate the absolute URL. | ||
resource = getResource(self.context, self.rname, self.request) | ||
src = resource() | ||
|
||
return ('<img src="%s" alt="%s" width="16" height="16" border="0" />' | ||
% (src, self.alt)) | ||
|
||
def url(self): | ||
resource = getResource(self.context, self.rname, self.request) | ||
src = resource() | ||
return src | ||
|
||
class IconViewFactory(object): | ||
|
||
def __init__(self, rname, alt): | ||
self.rname = rname | ||
self.alt = alt | ||
|
||
def __call__(self, context, request): | ||
return IconView(context, request, self.rname, self.alt) | ||
|
||
def IconDirective(_context, name, for_, file=None, resource=None, | ||
layer=IDefaultBrowserLayer, alt=None): | ||
|
||
iname = for_.getName() | ||
|
||
if alt is None: | ||
alt = iname | ||
if IName.match(alt): | ||
alt = alt[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 | ||
metaconfigure.resource(_context, image=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, alt) | ||
|
||
_context.action( | ||
discriminator = ('view', name, vfactory, layer), | ||
callable = handler, | ||
args = ('provideAdapter', | ||
(for_, layer), Interface, name, vfactory, _context.info) | ||
) | ||
|
||
_context.action( | ||
discriminator = None, | ||
callable = provideInterface, | ||
args = (for_.__module__+'.'+for_.getName(), | ||
for_) | ||
) | ||
|
||
|
Oops, something went wrong.