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)
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)
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)
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)
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)
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)
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)
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]})
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)
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)
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)
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)