1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
|
from OFS.SimpleItem import Item
from Acquisition import Implicit
from Products.ZPatterns.Providers import NullProvider
from Products.ZPatterns.Agents import AgentMixin, GTMixin
from Products.ZPatterns.AttributeProviders import GAPMixin, NOT_FOUND
from Products.ZPatterns.Expressions import NamespaceStack, pushProxy, popProxy
from DocumentTemplate.DT_Util import InstanceDict
class Compute(GAPMixin,NullProvider,Item,Implicit):
"""
Compiler output for "WITH fromexpr COMPUTE assignments"
"""
def __init__(self,fromexpr,assignlist,is_query=None,defaults=(),
dependencies=()):
self._fromex = fromexpr
self.Attributes = assignlist
self.dependencies = dependencies
if defaults: self.Defaults = defaults
if is_query: self.IsQuery = is_query
class Trigger(GTMixin,AgentMixin,NullProvider,Item,Implicit):
"""
Compiler output for WHEN ... STORE/CALL ... SAVING ... type statements
"""
def __init__(self,events,saveattrs,callexpr,mementos,onlySave=None):
self._mementos = mementos
self.handle_set_for = saveattrs
self._expr = callexpr
self.applicable_events = events
if onlySave: self._onlySaveAttrs=1
class Initialize(NullProvider,Item,Implicit):
def __init__(self,computelist):
self.Attributes = computelist
def namesForRegistration(self,container):
return { 'provides': ('handlers',) }
def _objectCreating(self,client):
t = NamespaceStack()
pushProxy(self)
try:
data = {'self':client, 'NOT_FOUND':NOT_FOUND, 'RESULT':client}
t._push(InstanceDict(client, t))
t._push(data)
try:
c = client._getCache()
for a,e in self.Attributes:
c[a] = e.eval(t)
finally:
t._pop(2)
finally:
popProxy(self)
class PersistAttrs(NullProvider,Item,Implicit):
"""
Compiler output for "STORE attrs IN SELF" statements
"""
def __init__(self,attrlist):
self.Attributes = attrlist
def namesForRegistration(self,container):
return {
'provides':('attributes',),
'setattr': self.Attributes, 'delattr': self.Attributes
}
def _SetAttributeFor(self,client,name,value):
"""Set the attribute and return true if successful"""
client.__dict__[name]=value; client._p_changed = 1
return 1
def _DelAttributeFor(self,client,name):
"""Delete the attribute and return true if successful"""
if client._v_changedAttrs_[name] is NOT_FOUND: del client._v_changedAttrs_[name]
return 1 # Nothing else to do, since DataSkin has already deleted persistent attr
|