Example #1
0
 def getcountsum(self, *mpaths):
     ''' return the sum for all values found in mpath. Eg total number of ordered quantities.'''
     if self.root.record is None:
         raise botslib.MappingRootError(_(
             u'get($mpath): "root" of incoming message is empty; either split messages or use inn.getloop'
         ),
                                        mpath=mpaths)
     return self.root.getcountsum(*mpaths)
Example #2
0
 def delete(self, *mpaths):
     ''' query tree (self.root) with mpath; delete if found. return True if deleted, return False if not deleted.'''
     if self.root.record is None:
         raise botslib.MappingRootError(_(
             u'delete($mpath): "root" of incoming message is empty; either split messages or use inn.getloop'
         ),
                                        mpath=mpaths)
     return self.root.delete(*mpaths)
Example #3
0
 def get(self, *mpaths):
     ''' query tree (self.root) with mpath; get value (string); get None if not found.'''
     if self.root.record is None:
         raise botslib.MappingRootError(_(
             u'get($mpath): "root" of incoming message is empty; either split messages or use inn.getloop'
         ),
                                        mpath=mpaths)
     return self.root.get(*mpaths)
Example #4
0
 def getdecimal(self, *mpaths):
     ''' like get, returns None is value is zero (0) or not numeric.
         Is sometimes usefull in mapping.'''
     if self.root.record is None:
         raise botslib.MappingRootError(
             _(u'getdecimal(%(mpath)s): "root" of incoming message is empty; either split messages or use inn.getloop'
               ), {'mpath': mpaths})
     return self.root.getdecimal(*mpaths)
Example #5
0
 def putloop(self,*mpaths):
     if not self.root.record:    #no input yet, and start with a putloop(): dummy root
         if len(mpaths) == 1:
             self.root.append(node.Node(mpaths[0]))
             return self.root.children[-1]
         else: #TODO: what if self.root.record is None and len(mpaths) > 1?
             raise botslib.MappingRootError(_(u'putloop($mpath): mpath too long???'),mpath=mpaths)
     return self.root.putloop(*mpaths)
Example #6
0
 def change(self, where, change):
     ''' query tree (self.root) with where; if found replace with change; return True if change, return False if not changed.'''
     if self.root.record is None:
         raise botslib.MappingRootError(_(
             u'change($where,$change"): "root" of incoming message is empty; either split messages or use inn.getloop'
         ),
                                        where=where,
                                        change=change)
     return self.root.change(where, change)
Example #7
0
 def putloop(self, *mpaths):
     if not self.root.record:  #no input yet, and start with a putloop(): dummy root
         if len(mpaths) == 1:
             self.root.append(node.Node(record=mpaths[0]))
             return self.root.children[-1]
         else:
             raise botslib.MappingRootError(
                 _(u'putloop(%(mpath)s): mpath too long???'),
                 {'mpath': mpaths})
     return self.root.putloop(*mpaths)
Example #8
0
 def putloop(self,*mpaths):
     #sanity check of mpaths
     if not mpaths or not isinstance(mpaths,tuple):
         raise botslib.MappingFormatError(_(u'Must be dicts in tuple: putloop(%(mpath)s)'),{'mpath':mpaths})
     for part in mpaths:
         if not isinstance(part,dict):
             raise botslib.MappingFormatError(_(u'Must be dicts in tuple: putloop(%(mpath)s)'),{'mpath':mpaths})
         if 'BOTSID' not in part:
             raise botslib.MappingFormatError(_(u'Section without "BOTSID": putloop(%(mpath)s)'),{'mpath':mpaths})
         for key,value in part.iteritems():
             if not isinstance(key,basestring):
                 raise botslib.MappingFormatError(_(u'Keys must be strings: putloop(%(mpath)s)'),{'mpath':mpaths})
             if value is None:
                 return False
             part[key] = unicode(value).strip()
         if 'BOTSIDnr' not in part:
             part['BOTSIDnr'] = u'1'
     if self._sameoccurence(mpaths[0]):
         if len(mpaths)==1:
             return self
         return self._putloopcore(mpaths[1:])
     else:
         raise botslib.MappingRootError(_(u'Error in root putloop "%(mpath)s".'),{'mpath':mpaths[0]})
Example #9
0
 def put(self,*mpaths):
     if self.root.record is None and self.root.children:
         raise botslib.MappingRootError(_(u'put($mpath): "root" of outgoing message is empty; use out.putloop'),mpath=mpaths)
     return self.root.put(*mpaths)
Example #10
0
 def sort(self,*mpaths):
     if self.root.record is None:
         raise botslib.MappingRootError(_(u'get($mpath): "root" of message is empty; either split messages or use inn.getloop'),mpath=mpaths)
     self.root.sort(*mpaths)
Example #11
0
 def put(self, *mpaths, **kwargs):
     if self.root.record is None and self.root.children:
         raise botslib.MappingRootError(
             _(u'put(%(mpath)s): "root" of outgoing message is empty; use out.putloop'
               ), {'mpath': mpaths})
     return self.root.put(*mpaths, **kwargs)
Example #12
0
 def getrecord(self, *mpaths):
     if self.root.record is None:
         raise botslib.MappingRootError(
             _(u'getrecord(%(mpath)s): "root" of incoming message is empty; either split messages or use inn.getloop'
               ), {'mpath': mpaths})
     return self.root.getrecord(*mpaths)