Пример #1
0
 def setSpaceForTag(self):
   """On the first run of a transform or if another transform in the same module has been called, 
      (which dirties injected namespace variable) we'll need to 'refresh' the namespace 
      before return. that's what this does.
   """
   self_space = self.space
   StackShell = self.request.StackShell
   [setattr(self_space, x, StackShell.get(x, -1)) for x in StackShell.keys()]
Пример #2
0
 def perTag(self, tag):
   self.tag = tag
   self_trans = self.trans
   self_request_req = self.request.req
   self_space = self.space
   
   #perform the logic that allows the saveas attribute to "inherit" from a calling node: if saveas isn't provided
   #but the calling context has saveas, then use that. By this point it will already have that name, if provided, 
   #which is why if self.saveas is false, we set it to 'all' which is where unnamed transform data lives.
   try:
     savename = tag.getAttribute(self_trans.attrname)
   except:
     raise self_trans.name
   match = self.matchSaveName.search(savename)
   if match == None:
     if not self.saveas: self.saveas = 'all'
   else:
     span = match.span()
     self.saveas = savename[1:span[1]-2]
     tag.setAttribute(self_trans.attrname, savename[span[1]:])
   
   self.uid = '%s_%s'%(self.trans.scoredname, self.saveas)
   
   autoGenTable = self_space.AUTOGENTABLE
   autoGenTableABS = self.request.autoGenTableABS
   try:    autoGenTable[self_trans.name] += 1
   except: autoGenTable[self_trans.name] = 0
   runnum = autoGenTable[self_trans.name]
   try:    autoGenTableABS[self_trans.name] += 1
   except: autoGenTableABS[self_trans.name] = 0
   reqrunnum = autoGenTableABS[self_trans.name]
   self.uidAndNum = str("%s%s"%(self.uid,runnum)).replace('.', '_')
   
   pass #dbug("in apply:"+self_trans.name + ' name is ' + self.saveas + ' saveas attr is: [' + self.tag.getAttribute('saveas') + ']')
   
   #! THESE CHANGE EVERY TIME A TAG IS EVALUATED
   if not self_space.SELFS.has_key(self.uid):
     self_space.SELFS[self.uid] = DictToObjWrapper({})
 
   StackShell = self.request.StackShell
   #This is the autonumbering code! this in it's simple self is the heart of self-referential javascript
   StackShell.add(
     {
       'NUM':str(runnum), 
       'REQNUM': str(reqrunnum),
       'NAME': self_trans.atomicname,
       'AUTO':AutoShell(self.uidAndNum).prepare(StackShell),
       'TAG':self.tag, 
       'INST':self.saveas,
       'ARGV':ArgvShell(self.tag.getAttribute(self_trans.attrname)).using(self.request.passstack),
       'ATTR':AttrShell(self.tag),
       'HERE':self.request.zodb['here'][self_trans.atomicname][self_request_req.acl.user][self.saveas],
       'self':DictToObjWrapper(self_space.SELFS[self.uid])
     }
   )
     
   #copy 'em into the transform namespace for quick use.
   #also call to reinitialze environment on return from subcall
   self.setSpaceForTag()
   #if there is a default block, take what isn't passed as an argument and fill it in
   #before executing..
   if self_trans.defaultHandler.rules[0][2]:
     defaults = self_trans.defaultHandler.rules[0][2]
     passed = StackShell.get('ARGV', -1)
     passedin = passed.keys()
     for key in defaults.keys():
       if key not in passedin:
         passed[key] = defaults[key]
   
   #zero out the various state trackers used as the transform rules are evaluated.
   self.modulesToUse = []
   self.loopstate = []
   self.loopindexes = []
   self.abandonedTags = []
   self.lastConditionState = []
   self.currRule = None
   self._i = 0
   return self