def DCWorkflowDefinition_listObjectActions(self, info): ''' Allows this workflow to include actions to be displayed in the actions box. Called only when this workflow is applicable to info.object. Returns the actions to be displayed to the user. ''' fmt_data = None ob = info.object sdef = self._getWorkflowStateOf(ob) if sdef is None: return None res = [] for tid in sdef.transitions: tdef = self.transitions.get(tid, None) if tdef is not None and tdef.trigger_type == TRIGGER_USER_ACTION and \ tdef.actbox_name and self._checkTransitionGuard(tdef, ob): if fmt_data is None: fmt_data = TemplateDict() fmt_data._push(info) fmt_data._push({'transition_id': tid}) res.append((tid, { 'id': tid, 'name': tdef.actbox_name % fmt_data, 'url': tdef.actbox_url % fmt_data, 'icon': tdef.actbox_icon % fmt_data, 'permissions': (), # Predetermined. 'category': tdef.actbox_category, 'transition': tdef})) fmt_data._pop() res.sort() return [ result[1] for result in res ]
def render(self, md): expr = self.expr if isinstance(expr, str): v = md[expr] else: v = expr(md) if not self.mapping: if isinstance(v, tuple) and len(v) == 1: v = v[0] v = InstanceDict(v, md) if self.only: _md = md md = TemplateDict() if hasattr(_md, 'guarded_getattr'): md.guarded_getattr = _md.guarded_getattr if hasattr(_md, 'guarded_getitem'): md.guarded_getitem = _md.guarded_getitem md._push(v) try: return render_blocks(self.section, md, encoding=self.encoding) finally: md._pop(1)
def test7(self): "test7" def myCmp(s1, s2): return -cmp(s1, s2) # Create namespace... from DocumentTemplate.DT_Util import TemplateDict md = TemplateDict() # ... and push out function onto the namespace md._push({"myCmp": myCmp}) assert res7 == SortEx(wordlist, (("weight",), ("key", "myCmp", "desc")), md, mapping=1)
def test7(self): "test7" def myCmp(s1, s2): return -cmp(s1, s2) # Create namespace... from DocumentTemplate.DT_Util import TemplateDict md = TemplateDict() #... and push out function onto the namespace md._push({"myCmp": myCmp}) assert res7 == SortEx(wordlist, (("weight", ), ("key", "myCmp", "desc")), md, mapping=1)
def test7(self): def myCmp(s1, s2): if s1 > s2: return -1 if s1 < s2: return 1 return 0 # Create namespace... from DocumentTemplate.DT_Util import TemplateDict md = TemplateDict() # ... and push out function onto the namespace md._push({"myCmp": myCmp}) self.assertEqual( res7, SortEx(wordlist, (("weight",), ("key", "myCmp", "desc")), md, mapping=1))
def exprNamespace(object, workflow, status=None, transition=None, new_state=None, kwargs=None): md = TemplateDict() if kwargs is None: kwargs = {} if status is None: tool = aq_parent(aq_inner(workflow)) status = tool.getStatusOf(workflow.id, object) if status is None: status = {} md._push(status) md._push(ExprVars(object, workflow)) d = {'object': object, 'workflow': workflow, 'transition': transition, 'new_state': new_state, 'kwargs': kwargs, } md._push(d) md._push(workflow.scripts) # Make scripts automatically available. return md
def listGlobalActions(self, info): ''' Allows this workflow to include actions to be displayed in the actions box. Called on every request. Returns the actions to be displayed to the user. ''' if not self.worklists: return None # Optimization sm = getSecurityManager() portal = self._getPortalRoot() res = [] fmt_data = None for id, qdef in self.worklists.items(): if qdef.actbox_name: guard = qdef.guard if guard is None or guard.check(sm, self, portal): searchres = None var_match_keys = qdef.getVarMatchKeys() if var_match_keys: # Check the catalog for items in the worklist. catalog = getToolByName(self, 'portal_catalog') dict = {} for k in var_match_keys: v = qdef.getVarMatch(k) v_fmt = map(lambda x, info=info: x % info, v) dict[k] = v_fmt searchres = catalog.searchResults(**dict) if not searchres: continue if fmt_data is None: fmt_data = TemplateDict() fmt_data._push(info) searchres_len = lambda searchres=searchres: len(searchres) fmt_data._push({'count': searchres_len}) res.append(( id, { 'id': id, 'name': qdef.actbox_name % fmt_data, 'url': qdef.actbox_url % fmt_data, 'permissions': (), # Predetermined. 'category': qdef.actbox_category })) fmt_data._pop() res.sort() return map((lambda (id, val): val), res)
def listGlobalActions(self, info): ''' Allows this workflow to include actions to be displayed in the actions box. Called on every request. Returns the actions to be displayed to the user. ''' if not self.worklists: return None # Optimization sm = getSecurityManager() portal = self._getPortalRoot() res = [] fmt_data = None for id, qdef in self.worklists.items(): if qdef.actbox_name: guard = qdef.guard if guard is None or guard.check(sm, self, portal): searchres = None var_match_keys = qdef.getVarMatchKeys() if var_match_keys: # Check the catalog for items in the worklist. catalog = getUtility(ICatalogTool) kw = {} for k in var_match_keys: v = qdef.getVarMatch(k) kw[k] = [x % info for x in v] searchres = catalog.searchResults(**kw) if not searchres: continue if fmt_data is None: fmt_data = TemplateDict() fmt_data._push(info) fmt_data._push({'count': len(searchres)}) res.append(( id, { 'id': id, 'name': qdef.actbox_name % fmt_data, 'url': qdef.actbox_url % fmt_data, 'permissions': (), # Predetermined. 'category': qdef.actbox_category })) fmt_data._pop() res.sort() return [result[1] for result in res]
def listGlobalActions(self, info): ''' Allows this workflow to include actions to be displayed in the actions box. Called on every request. Returns the actions to be displayed to the user. ''' if not self.worklists: return None # Optimization sm = getSecurityManager() portal = self._getPortalRoot() res = [] fmt_data = None for id, qdef in self.worklists.items(): if qdef.actbox_name: guard = qdef.guard if guard is None or guard.check(sm, self, portal): searchres = None var_match_keys = qdef.getVarMatchKeys() if var_match_keys: # Check the catalog for items in the worklist. catalog = getToolByName(self, 'portal_catalog') dict = {} for k in var_match_keys: v = qdef.getVarMatch(k) v_fmt = map(lambda x, info=info: x%info, v) dict[k] = v_fmt searchres = catalog.searchResults(**dict) if not searchres: continue if fmt_data is None: fmt_data = TemplateDict() fmt_data._push(info) searchres_len = lambda searchres=searchres: len(searchres) fmt_data._push({'count': searchres_len}) res.append((id, {'id': id, 'name': qdef.actbox_name % fmt_data, 'url': qdef.actbox_url % fmt_data, 'permissions': (), # Predetermined. 'category': qdef.actbox_category})) fmt_data._pop() res.sort() return map((lambda (id, val): val), res)
def listGlobalActions(self, info): ''' Allows this workflow to include actions to be displayed in the actions box. Called on every request. Returns the actions to be displayed to the user. ''' if not self.worklists: return None # Optimization sm = getSecurityManager() portal = self._getPortalRoot() res = [] fmt_data = None for id, qdef in self.worklists.items(): if qdef.actbox_name: guard = qdef.guard if guard is None or guard.check(sm, self, portal): searchres = None var_match_keys = qdef.getVarMatchKeys() if var_match_keys: # Check the catalog for items in the worklist. catalog = getUtility(ICatalogTool) kw = {} for k in var_match_keys: v = qdef.getVarMatch(k) kw[k] = [ x % info for x in v ] searchres = catalog.searchResults(**kw) if not searchres: continue if fmt_data is None: fmt_data = TemplateDict() fmt_data._push(info) fmt_data._push({'count': len(searchres)}) res.append((id, {'id': id, 'name': qdef.actbox_name % fmt_data, 'url': qdef.actbox_url % fmt_data, 'permissions': (), # Predetermined. 'category': qdef.actbox_category})) fmt_data._pop() res.sort() return [ result[1] for result in res ]
# The boolean values behave as above, but the functions do not. # The value returned for attribute access is the result of # calling the function with the object and the attribute name. ContainerAssertions={ type(()): 1, type(''): 1, type(u''): 1, } class _dummy_class: pass from DocumentTemplate.DT_Util import TemplateDict # Temporarily create a DictInstance so that we can mark its type as # being a key in the ContainerAssertions. templateDict = TemplateDict() try: dictInstance = templateDict(dummy=1)[0] if type(dictInstance) is not type(_dummy_class()): ContainerAssertions[type(dictInstance)]=1 except: # Hmm, this may cause _() and _.namespace() to fail. # What to do? pass Containers = ContainerAssertions.get def allow_type(Type, allowed=1): """Allow a type and all of its methods and attributes to be used from restricted code. The argument Type must be a type.""" if type(Type) is not type:
def __call__(self, client=None, mapping={}, **kw): '''\ Generate a document from a document template. The document will be generated by inserting values into the format string specified when the document template was created. Values are inserted using standard python named string formats. The optional argument 'client' is used to specify a object containing values to be looked up. Values will be looked up using getattr, so inheritence of values is supported. Note that names beginning with '_' will not be looked up from the client. The optional argument, 'mapping' is used to specify a mapping object containing values to be inserted. Values to be inserted may also be specified using keyword arguments. Values will be inserted from one of several sources. The sources, in the order in which they are consulted, are: o Keyword arguments, o The 'client' argument, o The 'mapping' argument, o The keyword arguments provided when the object was created, and o The 'mapping' argument provided when the template was created. ''' # print '============================================================' # print '__called__' # print self.raw # print kw # print client # print mapping # print '============================================================' if mapping is None: mapping = {} if hasattr(mapping, 'taintWrapper'): mapping = mapping.taintWrapper() if not hasattr(self, '_v_cooked'): try: changed = self.__changed__() except: changed = 1 self.cook() if not changed: self.__changed__(0) pushed = None try: # Support Python 1.5.2, but work better in 2.1 if (mapping.__class__ is TemplateDict or isinstance(mapping, TemplateDict)): pushed = 0 except: pass globals = self.globals if pushed is not None: # We were passed a TemplateDict, so we must be a sub-template md = mapping push = md._push if globals: push(self.globals) pushed = pushed + 1 else: md = TemplateDict() push = md._push shared_globals = self.shared_globals if shared_globals: push(shared_globals) if globals: push(globals) if mapping: push(mapping) md.guarded_getattr = self.guarded_getattr md.guarded_getitem = self.guarded_getitem if client is not None: if type(client) == type(()): md.this = client[-1] else: md.this = client pushed = 0 level = md.level if level > 200: raise SystemError, ('infinite recursion in document template') md.level = level + 1 if client is not None: if type(client) == type(()): # if client is a tuple, it represents a "path" of clients # which should be pushed onto the md in order. for ob in client: push(InstanceDict(ob, md)) # Circ. Ref. 8-| pushed = pushed + 1 else: # otherwise its just a normal client object. push(InstanceDict(client, md)) # Circ. Ref. 8-| pushed = pushed + 1 if self._vars: push(self._vars) pushed = pushed + 1 if kw: push(kw) pushed = pushed + 1 try: value = self.ZDocumentTemplate_beforeRender(md, _marker) if value is _marker: try: result = render_blocks(self._v_blocks, md) except DTReturn, v: result = v.v self.ZDocumentTemplate_afterRender(md, result) return result else:
def DCWorkflowDefinition_getWorklistVariableMatchDict(self, info, check_guard=True): """ Return a dict which has an entry per worklist definition (worklist id as key) and which value is a dict composed of variable matches. """ if not self.worklists: return None portal = self.getPortalObject() def getPortalTypeListForWorkflow(workflow_id): workflow_tool = portal.portal_workflow result = [] append = result.append for type_info in workflow_tool._listTypeInfo(): portal_type = type_info.id if workflow_id in workflow_tool.getChainFor(portal_type): append(portal_type) return result _getPortalTypeListForWorkflow = CachingMethod( getPortalTypeListForWorkflow, id='_getPortalTypeListForWorkflow', cache_factory='erp5_ui_long') portal_type_list = _getPortalTypeListForWorkflow(self.id) if not portal_type_list: return None variable_match_dict = {} security_manager = getSecurityManager() workflow_id = self.id workflow_title = self.title for worklist_id, worklist_definition in self.worklists.items(): action_box_name = worklist_definition.actbox_name guard = worklist_definition.guard if action_box_name: variable_match = {} for key in worklist_definition.getVarMatchKeys(): var = worklist_definition.getVarMatch(key) if isinstance(var, Expression): evaluated_value = var( createExprContext( StateChangeInfo(portal, self, kwargs=info.__dict__.copy()))) if isinstance(evaluated_value, (str, int, long)): evaluated_value = [str(evaluated_value)] else: evaluated_value = [x % info for x in var] variable_match[key] = evaluated_value if 'portal_type' in variable_match and len( variable_match['portal_type']): portal_type_intersection = set(variable_match['portal_type'])\ .intersection(portal_type_list) # in case the current workflow is not associated with portal_types # defined on the worklist, don't display the worklist for this # portal_type. variable_match['portal_type'] = list(portal_type_intersection) variable_match.setdefault('portal_type', portal_type_list) if len(variable_match.get('portal_type', [])) == 0: continue is_permitted_worklist = 0 if guard is None: is_permitted_worklist = 1 elif (not check_guard) or \ Guard_checkWithoutRoles(guard, security_manager, self, portal): is_permitted_worklist = 1 variable_match[SECURITY_PARAMETER_ID] = guard.roles if is_permitted_worklist: format_data = TemplateDict() format_data._push(info) variable_match.setdefault(SECURITY_PARAMETER_ID, ()) format_data._push(dict((k, ('&%s:list=' % k).join(v)) for\ k, v in variable_match.iteritems())) variable_match[WORKLIST_METADATA_KEY] = { 'format_data': format_data, 'worklist_title': action_box_name, 'worklist_id': worklist_id, 'workflow_title': workflow_title, 'workflow_id': workflow_id, 'action_box_url': worklist_definition.actbox_url, 'action_box_category': worklist_definition.actbox_category } variable_match_dict[worklist_id] = variable_match if len(variable_match_dict) == 0: return None return variable_match_dict
def _listGlobalActions(user=None, id=None, portal_path=None): portal = self._getPortalRoot() portal_url = portal.portal_url portal_url = portal_url() sm = getSecurityManager() res = [] fmt_data = None # We want to display some actions depending on the current date # So, we can now put this kind of expression : <= "%(now)s" # May be this patch should be moved to listFilteredActions in the future info.now = DateTime() for id, qdef in self.worklists.items(): if qdef.actbox_name: guard = qdef.guard # Patch for ERP5 by JP Smets in order # to take into account the expression of the guard # and nothing else - ERP5Workflow definitely needed some day if guard is None or Guard_checkWithoutRoles( guard, sm, self, portal): dict = {} # Patch for ERP5 by JP Smets in order # to implement worklists and search of local roles searchres_len = 0 var_match_keys = qdef.getVarMatchKeys() if var_match_keys: # Check the catalog for items in the worklist. catalog = portal.portal_catalog for k in var_match_keys: v = qdef.getVarMatch(k) if isinstance(v, Expression): v_fmt = v( createExprContext( StateChangeInfo( portal, self, kwargs=info.__dict__.copy()))) else: v_fmt = map(lambda x, info=info: x % info, v) dict[k] = v_fmt # Patch to automatically filter workflists per portal type # so that the same state can be used for different # worklists and they are not merged if not dict.has_key('portal_type'): dict['portal_type'] = portal_type_list # Patch for ERP5 by JP Smets in order # to implement worklists and search of local roles # we do not take into account the guard here if guard is not None and guard.roles: dict['local_roles'] = guard.roles # Patch to use ZSQLCatalog and get high speed # LOG("PatchedDCWorkflowDefinition", 0, dict) searchres_len = int( apply(catalog.countResults, (), dict)[0][0]) if searchres_len == 0: continue if fmt_data is None: fmt_data = TemplateDict() fmt_data._push(info) fmt_data._push({'count': searchres_len}) # Patch for ERP5 by JP Smets in order to # filter per portal type more easily (ie. without # hardcoding it all) fmt_data._push({ 'portal_type': '&portal_type='.join(dict['portal_type']) }) # Patch for ERP5 by JP Smets in order # to implement worklists and search of local roles if dict.has_key('local_roles'): fmt_data._push({ 'local_roles': '&local_roles='.join(dict['local_roles']) }) else: fmt_data._push({'local_roles': ''}) res.append(( id, { 'name': qdef.actbox_name % fmt_data, 'url': '%s/%s' % (portal_url, qdef.actbox_url % fmt_data), 'worklist_id': id, 'workflow_title': self.title, 'workflow_id': self.id, 'permissions': (), # Predetermined. 'category': qdef.actbox_category })) fmt_data._pop() res.sort() return map((lambda (id, val): val), res)
def DCWorkflowDefinition_getWorklistVariableMatchDict(self, info, check_guard=True): """ Return a dict which has an entry per worklist definition (worklist id as key) and which value is a dict composed of variable matches. """ if not self.worklists: return None portal = self.getPortalObject() def getPortalTypeListForWorkflow(workflow_id): workflow_tool = portal.portal_workflow result = [] append = result.append for type_info in workflow_tool._listTypeInfo(): portal_type = type_info.id if workflow_id in workflow_tool.getChainFor(portal_type): append(portal_type) return result _getPortalTypeListForWorkflow = CachingMethod(getPortalTypeListForWorkflow, id='_getPortalTypeListForWorkflow', cache_factory = 'erp5_ui_long') portal_type_list = _getPortalTypeListForWorkflow(self.id) if not portal_type_list: return None variable_match_dict = {} security_manager = getSecurityManager() workflow_id = self.id workflow_title = self.title for worklist_id, worklist_definition in self.worklists.items(): action_box_name = worklist_definition.actbox_name guard = worklist_definition.guard if action_box_name: variable_match = {} for key in worklist_definition.getVarMatchKeys(): var = worklist_definition.getVarMatch(key) if isinstance(var, Expression): evaluated_value = var(createExprContext(StateChangeInfo(portal, self, kwargs=info.__dict__.copy()))) if isinstance(evaluated_value, (str, int, long)): evaluated_value = [str(evaluated_value)] else: evaluated_value = [x % info for x in var] variable_match[key] = evaluated_value if 'portal_type' in variable_match and len(variable_match['portal_type']): portal_type_intersection = set(variable_match['portal_type'])\ .intersection(portal_type_list) # in case the current workflow is not associated with portal_types # defined on the worklist, don't display the worklist for this # portal_type. variable_match['portal_type'] = list(portal_type_intersection) variable_match.setdefault('portal_type', portal_type_list) if len(variable_match.get('portal_type', [])) == 0: continue is_permitted_worklist = 0 if guard is None: is_permitted_worklist = 1 elif (not check_guard) or \ Guard_checkWithoutRoles(guard, security_manager, self, portal): is_permitted_worklist = 1 variable_match[SECURITY_PARAMETER_ID] = guard.roles if is_permitted_worklist: format_data = TemplateDict() format_data._push(info) variable_match.setdefault(SECURITY_PARAMETER_ID, ()) format_data._push(dict((k, ('&%s:list=' % k).join(v)) for\ k, v in variable_match.iteritems())) variable_match[WORKLIST_METADATA_KEY] = {'format_data': format_data, 'worklist_title': action_box_name, 'worklist_id': worklist_id, 'workflow_title': workflow_title, 'workflow_id': workflow_id, 'action_box_url': worklist_definition.actbox_url, 'action_box_category': worklist_definition.actbox_category} variable_match_dict[worklist_id] = variable_match if len(variable_match_dict) == 0: return None return variable_match_dict
def _listGlobalActions(user=None, id=None, portal_path=None): portal = self._getPortalRoot() portal_url = portal.portal_url portal_url = portal_url() sm = getSecurityManager() res = [] fmt_data = None # We want to display some actions depending on the current date # So, we can now put this kind of expression : <= "%(now)s" # May be this patch should be moved to listFilteredActions in the future info.now = DateTime() for id, qdef in self.worklists.items(): if qdef.actbox_name: guard = qdef.guard # Patch for ERP5 by JP Smets in order # to take into account the expression of the guard # and nothing else - ERP5Workflow definitely needed some day if guard is None or Guard_checkWithoutRoles( guard, sm, self, portal): dict = {} # Patch for ERP5 by JP Smets in order # to implement worklists and search of local roles searchres_len = 0 var_match_keys = qdef.getVarMatchKeys() if var_match_keys: # Check the catalog for items in the worklist. catalog = portal.portal_catalog for k in var_match_keys: v = qdef.getVarMatch(k) if isinstance(v, Expression): v_fmt = v(createExprContext(StateChangeInfo(portal, self, kwargs=info.__dict__.copy()))) else: v_fmt = map(lambda x, info=info: x%info, v) dict[k] = v_fmt # Patch to automatically filter workflists per portal type # so that the same state can be used for different # worklists and they are not merged if not dict.has_key('portal_type'): dict['portal_type'] = portal_type_list # Patch for ERP5 by JP Smets in order # to implement worklists and search of local roles # we do not take into account the guard here if guard is not None and guard.roles: dict['local_roles'] = guard.roles # Patch to use ZSQLCatalog and get high speed # LOG("PatchedDCWorkflowDefinition", 0, dict) searchres_len = int(apply(catalog.countResults, (), dict)[0][0]) if searchres_len == 0: continue if fmt_data is None: fmt_data = TemplateDict() fmt_data._push(info) fmt_data._push({'count': searchres_len}) # Patch for ERP5 by JP Smets in order to # filter per portal type more easily (ie. without # hardcoding it all) fmt_data._push({'portal_type': '&portal_type='.join(dict['portal_type'])}) # Patch for ERP5 by JP Smets in order # to implement worklists and search of local roles if dict.has_key('local_roles'): fmt_data._push({'local_roles': '&local_roles='.join(dict['local_roles'])}) else: fmt_data._push({'local_roles': ''}) res.append((id, {'name': qdef.actbox_name % fmt_data, 'url': '%s/%s' % (portal_url, qdef.actbox_url % fmt_data), 'worklist_id': id, 'workflow_title': self.title, 'workflow_id': self.id, 'permissions': (), # Predetermined. 'category': qdef.actbox_category})) fmt_data._pop() res.sort() return map((lambda (id, val): val), res)
def test_render_w_expr_nonesuch(self): from DocumentTemplate.DT_Raise import InvalidErrorTypeExpression from DocumentTemplate.DT_Util import TemplateDict raiser = self._makeOne(expr='NonesuchError') self.assertRaises(InvalidErrorTypeExpression, raiser.render, TemplateDict())
def test_render_w_expr_zExceptions_exception(self): from DocumentTemplate.DT_Util import TemplateDict from zExceptions import Redirect raiser = self._makeOne(expr='Redirect') self.assertRaises(Redirect, raiser.render, TemplateDict())
def test_render_w_expr_builtin_exception(self): from DocumentTemplate.DT_Util import TemplateDict raiser = self._makeOne(expr='SyntaxError') self.assertRaises(SyntaxError, raiser.render, TemplateDict())
def test_render_w_type_nonesuch(self): from DocumentTemplate.DT_Util import TemplateDict raiser = self._makeOne(type='NonesuchError') self.assertRaises(RuntimeError, raiser.render, TemplateDict())
def call_with_ns(f, ns, arg=1): td = TemplateDict() td.validate = validate td.this = ns['here'] td._push(ns['request']) td._push(InstanceDict(td.this, td)) td._push(ns) try: if arg==2: return f(None, td) else: return f(td) finally: td._pop(3)
def __call__(self,client=None,mapping={},**kw): '''\ Generate a document from a document template. The document will be generated by inserting values into the format string specified when the document template was created. Values are inserted using standard python named string formats. The optional argument 'client' is used to specify a object containing values to be looked up. Values will be looked up using getattr, so inheritence of values is supported. Note that names beginning with '_' will not be looked up from the client. The optional argument, 'mapping' is used to specify a mapping object containing values to be inserted. Values to be inserted may also be specified using keyword arguments. Values will be inserted from one of several sources. The sources, in the order in which they are consulted, are: o Keyword arguments, o The 'client' argument, o The 'mapping' argument, o The keyword arguments provided when the object was created, and o The 'mapping' argument provided when the template was created. ''' # print '============================================================' # print '__called__' # print self.raw # print kw # print client # print mapping # print '============================================================' if mapping is None: mapping = {} if hasattr(mapping, 'taintWrapper'): mapping = mapping.taintWrapper() if not hasattr(self,'_v_cooked'): try: changed=self.__changed__() except: changed=1 self.cook() if not changed: self.__changed__(0) pushed=None try: # Support Python 1.5.2, but work better in 2.1 if (mapping.__class__ is TemplateDict or isinstance(mapping, TemplateDict)): pushed=0 except: pass globals=self.globals if pushed is not None: # We were passed a TemplateDict, so we must be a sub-template md=mapping push=md._push if globals: push(self.globals) pushed=pushed+1 else: md=TemplateDict() push=md._push shared_globals=self.shared_globals if shared_globals: push(shared_globals) if globals: push(globals) if mapping: push(mapping) md.guarded_getattr=self.guarded_getattr md.guarded_getitem=self.guarded_getitem if client is not None: if type(client)==type(()): md.this=client[-1] else: md.this=client pushed=0 level=md.level if level > 200: raise SystemError, ( 'infinite recursion in document template') md.level=level+1 if client is not None: if type(client)==type(()): # if client is a tuple, it represents a "path" of clients # which should be pushed onto the md in order. for ob in client: push(InstanceDict(ob, md)) # Circ. Ref. 8-| pushed=pushed+1 else: # otherwise its just a normal client object. push(InstanceDict(client, md)) # Circ. Ref. 8-| pushed=pushed+1 if self._vars: push(self._vars) pushed=pushed+1 if kw: push(kw) pushed=pushed+1 try: value = self.ZDocumentTemplate_beforeRender(md, _marker) if value is _marker: try: result = render_blocks(self._v_blocks, md) except DTReturn, v: result = v.v self.ZDocumentTemplate_afterRender(md, result) return result else: return value finally: if pushed: md._pop(pushed) # Get rid of circular reference! md.level=level # Restore previous level