[Zope3-checkins] CVS: Zope3/src/zope/app/services - queryfield.py:1.1.2.1 adapter.py:1.6.2.1 auth.py:1.9.2.2 configure.zcml:1.13.2.1 errorr.py:1.4.2.1 event.py:1.8.2.1 view.py:1.4.2.1 viewpackage.py:1.3.2.1 zpt.py:1.4.2.1
Sidnei da Silva
sidnei@x3ng.com.br
Tue, 11 Feb 2003 09:42:01 -0500
Update of /cvs-repository/Zope3/src/zope/app/services
In directory cvs.zope.org:/tmp/cvs-serv18615/src/zope/app/services
Modified Files:
Tag: paris-copypasterename-branch
adapter.py auth.py configure.zcml errorr.py event.py view.py
viewpackage.py zpt.py
Added Files:
Tag: paris-copypasterename-branch
queryfield.py
Log Message:
Updating from HEAD to make sure everything still works before merging
=== Added File Zope3/src/zope/app/services/queryfield.py ===
##############################################################################
#
# Copyright (c) 2002, 2003 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (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.
#
##############################################################################
"""
$Id: queryfield.py,v 1.1.2.1 2003/02/11 14:41:29 sidnei Exp $
"""
from zope.app.services.field import locateComponent
from zope.schema import Tuple
from zope.schema.interfaces import ValidationError
from zope.component import getAdapter
from zope.interface.implements import implements
# See end of file for further imports
class QueryProcessorsField(Tuple):
def __init__(self, default=(), *args, **kw):
super(QueryProcessorsField, self).__init__(default=default,
*args, **kw)
def _validate(self, value):
super(QueryProcessorsField, self)._validate(value)
context = self.context
for location, adaptername in value:
component = locateComponent(location, context, IQueryProcessable)
processor = getAdapter(component, IQueryProcessor,
context=context, name=adaptername)
if processor is None:
if name:
message = 'No IQueryProcessor adapter named "%s" found'
else:
message = 'No IQueryProcessor adapter found'
raise ValidationError(message, location)
# Imported here to avoid circular imports
from zope.app.interfaces.services.query import IQueryProcessorsField
from zope.app.interfaces.services.query import IQueryProcessable
from zope.app.interfaces.services.query import IQueryProcessor
implements(QueryProcessorsField, IQueryProcessorsField)
=== Zope3/src/zope/app/services/adapter.py 1.6 => 1.6.2.1 ===
--- Zope3/src/zope/app/services/adapter.py:1.6 Thu Jan 16 07:00:00 2003
+++ Zope3/src/zope/app/services/adapter.py Tue Feb 11 09:41:29 2003
@@ -23,6 +23,7 @@
from zope.component.interfaces import IAdapterService
from zope.component.exceptions import ComponentLookupError
from zope.component import getServiceManager
+from zope.component.servicenames import Adapters
from zope.app.interfaces.services.configuration import IConfigurable
from zope.app.services.configuration import ConfigurationRegistry
from zope.app.services.configuration import SimpleConfiguration
@@ -125,7 +126,7 @@
adapter = registry.active().getAdapter(object)
return adapter
- adapters = getNextService(self, 'Adapters')
+ adapters = getNextService(self, Adapters)
return adapters.queryAdapter(object, interface, default)
@@ -147,7 +148,7 @@
__implements__ = IAdapterConfiguration, SimpleConfiguration.__implements__
- status = ConfigurationStatusProperty('Adapters')
+ status = ConfigurationStatusProperty(Adapters)
# XXX These should be positional arguments, except that forInterface
# isn't passed in if it is omitted. To fix this, we need a
=== Zope3/src/zope/app/services/auth.py 1.9.2.1 => 1.9.2.2 ===
--- Zope3/src/zope/app/services/auth.py:1.9.2.1 Wed Feb 5 06:00:35 2003
+++ Zope3/src/zope/app/services/auth.py Tue Feb 11 09:41:29 2003
@@ -23,6 +23,7 @@
from zope.exceptions import NotFoundError
from zope.component import getAdapter, queryAdapter
+from zope.component.servicenames import Authentication
from zope.app.interfaces.container import IContainer
@@ -75,7 +76,7 @@
return p
else:
return None
- next = getNextService(self, 'Authentication')
+ next = getNextService(self, Authentication)
return next.authenticate(request)
authenticate = ContextMethod(authenticate)
@@ -96,7 +97,7 @@
try:
return self._usersbyid[id]
except KeyError:
- next = getNextService(self, 'Authentication')
+ next = getNextService(self, Authentication)
return next.getPrincipal(id)
getPrincipal = ContextMethod(getPrincipal)
=== Zope3/src/zope/app/services/configure.zcml 1.13 => 1.13.2.1 ===
--- Zope3/src/zope/app/services/configure.zcml:1.13 Mon Feb 3 14:02:13 2003
+++ Zope3/src/zope/app/services/configure.zcml Tue Feb 11 09:41:29 2003
@@ -102,6 +102,27 @@
/>
</content>
+<adapter
+ for="zope.app.interfaces.services.interfaces.IZPTTemplate"
+ provides="zope.app.interfaces.file.IReadFile"
+ factory=".zpt.ReadFile"
+ permission="zope.ManageServices"
+ />
+
+<adapter
+ for="zope.app.interfaces.services.interfaces.IZPTTemplate"
+ provides="zope.app.interfaces.file.IWriteFile"
+ factory=".zpt.WriteFile"
+ permission="zope.ManageServices"
+ />
+
+<adapter
+ for="zope.app.interfaces.services.service.IViewPackage"
+ provides="zope.app.interfaces.file.IFileFactory"
+ factory=".zpt.ZPTFactory"
+ permission="zope.ManageServices"
+ />
+
<!-- Role Templates -->
<content class="zope.app.services.role.RoleService">
@@ -399,8 +420,9 @@
permission='zope.ManageServices' />
<require
permission="zope.View"
- attributes="notify lookupRuid lookupLocation getObject
- register unregister" />
+ attributes="notify getHubId getLocation getObject
+ register unregister numRegistrations
+ getRegistrations" />
<require
permission="zope.ManageServices"
attributes="bound unbound subscribe unsubscribe subscribeOnBind
=== Zope3/src/zope/app/services/errorr.py 1.4 => 1.4.2.1 ===
--- Zope3/src/zope/app/services/errorr.py:1.4 Tue Jan 7 07:18:35 2003
+++ Zope3/src/zope/app/services/errorr.py Tue Feb 11 09:41:29 2003
@@ -163,13 +163,17 @@
def _do_copy_to_zlog(self, now, strtype, url, info):
# XXX info is unused; logging.exception() will call sys.exc_info()
+ # work around this with an evil hack
when = _rate_restrict_pool.get(strtype,0)
if now > when:
next_when = max(when,
now - _rate_restrict_burst*_rate_restrict_period)
next_when += _rate_restrict_period
_rate_restrict_pool[strtype] = next_when
- logging.getLogger('SiteError').exception(str(url))
+ try:
+ raise info[0], info[1], info[2]
+ except:
+ logging.getLogger('SiteError').exception(str(url))
def getProperties(self):
return {
=== Zope3/src/zope/app/services/event.py 1.8 => 1.8.2.1 ===
--- Zope3/src/zope/app/services/event.py:1.8 Mon Feb 3 10:59:16 2003
+++ Zope3/src/zope/app/services/event.py Tue Feb 11 09:41:29 2003
@@ -28,6 +28,7 @@
from zope.component import getAdapter, queryAdapter, getService, queryService
from zope.component import ComponentLookupError
+from zope.component.servicenames import HubIds, Events, Subscription
from zope.app.component.nextservice import getNextService, queryNextService
from zope.proxy.context import ContextMethod, ContextSuper
@@ -37,7 +38,7 @@
def getSubscriptionService(context):
- return getService(context, "Subscription")
+ return getService(context, Subscription)
def subscribe(subscriber, event_type=IEvent, filter=None, context=None):
if context is None and not isinstance(subscriber, (int, str, unicode)):
@@ -81,7 +82,7 @@
def _notify(clean_self, wrapped_self, event):
subscriptionsForEvent = clean_self._registry.getAllForObject(event)
- hubGet = getService(wrapped_self, "HubIds").getObject
+ hubGet = getService(wrapped_self, HubIds).getObject
pathGet = getAdapter(wrapped_self, ITraverser).traverse
badSubscribers = {}
@@ -321,7 +322,7 @@
else:
publishedEvents.append(event)
if (clean_self.isPromotableEvent(event)):
- getNextService(wrapped_self, 'Events').publish(event)
+ getNextService(wrapped_self, Events).publish(event)
publishedEvents.remove(event)
publish = ContextMethod(publish)
@@ -336,12 +337,12 @@
def bound(wrapped_self, name):
"See IBindingAware"
ContextSuper(EventService, wrapped_self).bound(name)
- if name == "Subscription":
+ if name == Subscription:
clean_self = removeAllProxies(wrapped_self)
clean_self._serviceName = name # for LocalServiceSubscribable
if clean_self.subscribeOnBind:
try:
- es = getNextService(wrapped_self, "Subscription")
+ es = getNextService(wrapped_self, Subscription)
except ComponentLookupError:
pass
else:
@@ -350,7 +351,7 @@
def unbound(wrapped_self, name):
"See IBindingAware"
- if name == "Subscription":
+ if name == Subscription:
clean_self = removeAllProxies(wrapped_self)
clean_self._v_unbinding = True
try:
@@ -392,13 +393,13 @@
if ISubscriptionService.isImplementedBy(
removeAllProxies(clean_subscribable)):
try:
- context = getService(wrapped_self, "Subscription")
+ context = getService(wrapped_self, Subscription)
# we do this instead of getNextService because the order
# of unbinding and notification of unbinding is not
# guaranteed
while removeAllProxies(context) in (
clean_subscribable, clean_self):
- context = getNextService(context, "Subscription")
+ context = getNextService(context, Subscription)
except ComponentLookupError:
pass
else:
=== Zope3/src/zope/app/services/view.py 1.4 => 1.4.2.1 ===
--- Zope3/src/zope/app/services/view.py:1.4 Tue Jan 21 16:45:07 2003
+++ Zope3/src/zope/app/services/view.py Tue Feb 11 09:41:29 2003
@@ -43,6 +43,7 @@
from zope.app.interfaces.services.interfaces import IViewConfiguration, IPageConfiguration
from zope.app.services.adapter import PersistentAdapterRegistry
+from zope.configuration.exceptions import ConfigurationError
class ViewService(Persistent):
@@ -244,24 +245,46 @@
presentationType = IBrowserPresentation
def __init__(self,
- forInterface, viewName, permission,
- class_=None, template=None,
+ forInterface, viewName, permission,
+ class_=None, template=None, attribute=None,
layer='default'):
-
super(PageConfiguration, self).__init__(
forInterface, viewName, self.presentationType,
class_, permission, layer)
self.template = template
+ self.attribute = attribute
+
+ def _validate(self):
+ if self.template is not None and self.attribute is not None:
+ raise ConfigurationError(
+ "PageConfiguration for %s view name %s: "
+ "Cannot have both 'template' and 'attribute' at the same time." %
+ (self.forInterface, self.viewName))
+
+ if self.template is None and self.attribute is None:
+ raise ConfigurationError(
+ "PageConfiguration for %s view name %s: "
+ "Should have a 'template' or 'attribute' attribute." %
+ (self.forInterface, self.viewName))
+
+ if self.class_ is None and self.attribute is not None:
+ raise ConfigurationError(
+ "PageConfiguration for %s view name %s: "
+ "Cannot have an 'attribute' without a 'class_'." %
+ (self.forInterface, self.viewName))
def getView(self, object, request):
+
+
+ self._validate()
+
sm = getServiceManager(self)
if self.class_:
class_ = sm.resolve(self.class_)
class_ = type(class_.__name__, (class_, DefaultClass), {})
-
else:
class_ = DefaultClass
@@ -270,11 +293,15 @@
# This is needed because we need to do an unrestricted traverse
root = removeAllProxies(getPhysicalRoot(sm))
- template = traverse(root, self.template)
+ if self.attribute is not None:
+ template = getattr(view, self.attribute)
+ else:
+ template = traverse(root, self.template)
+ template = BoundTemplate(template, view)
checker = NamesChecker(__call__ = self.permission)
- return ProxyFactory(BoundTemplate(template, view), checker)
+ return ProxyFactory(template, checker)
getView = ContextMethod(getView)
=== Zope3/src/zope/app/services/viewpackage.py 1.3 => 1.3.2.1 ===
--- Zope3/src/zope/app/services/viewpackage.py:1.3 Mon Feb 3 12:29:09 2003
+++ Zope3/src/zope/app/services/viewpackage.py Tue Feb 11 09:41:29 2003
@@ -40,6 +40,8 @@
description = ''
title = ''
factoryName = None
+ attribute = None
+ template = None
def __init__(self):
super(ViewPackage, self).__init__()
@@ -47,7 +49,7 @@
def setObject(self, name, object):
if not IZPTTemplate.isImplementedBy(object):
- raise TypeError("Can only add packages")
+ raise TypeError("Can only add templates", object)
# super() does not work on a context wrapped instance
base = removeAllProxies(self)
@@ -55,10 +57,14 @@
name = super(ViewPackage, base).setObject(name, object)
template = getItem(self, name)
template = getPhysicalPathString(template)
- config = PageConfiguration(self.forInterface, name,
- self.permission,
- self.factoryName, template,
- self.layer)
+ config = PageConfiguration(
+ forInterface=self.forInterface,
+ viewName=name,
+ permission=self.permission,
+ class_=self.factoryName,
+ template=template,
+ layer=self.layer,
+ )
configure = traverse(self, 'configure')
id = configure.setObject('', config)
config = getItem(configure, id)
=== Zope3/src/zope/app/services/zpt.py 1.4 => 1.4.2.1 ===
--- Zope3/src/zope/app/services/zpt.py:1.4 Mon Feb 3 15:57:47 2003
+++ Zope3/src/zope/app/services/zpt.py Tue Feb 11 09:41:29 2003
@@ -30,6 +30,7 @@
from zope.app.pagetemplate.engine import AppPT
from zope.app.interfaces.services.interfaces import IZPTTemplate
from zope.app.interfaces.index.text import ISearchableText
+from zope.app.interfaces.file import IReadFile, IWriteFile, IFileFactory
class ZPTTemplate(AppPT, PageTemplate, Persistent):
@@ -87,3 +88,42 @@
text = tag.sub('', text)
return [text]
+
+# Adapters for file-system emulation
+
+class ReadFile:
+
+ __implements__ = IReadFile
+
+ def __init__(self, context):
+ self.context = context
+
+ def read(self):
+ return self.context.source
+
+ def size(self):
+ return len(self.context.source)
+
+
+class WriteFile:
+
+ __implements__ = IWriteFile
+
+ def __init__(self, context):
+ self.context = context
+
+ def write(self, data):
+ self.context.source = data
+
+
+class ZPTFactory:
+
+ __implements__ = IFileFactory
+
+ def __init__(self, context):
+ self.context = context
+
+ def __call__(self, name, content_type, data):
+ r = ZPTTemplate()
+ r.source = data
+ return r