Пример #1
0
 def add_child(self, **kwargs):
     name = kwargs.get('name')
     address = kwargs.get('address', '')
     if len(address) and address[0] == '/':
         if not self.is_root_node:
             return self.get_root_node().add_child(**kwargs)
     parent = kwargs.get('parent', self)
     def do_add_node(**nkwargs):
         nkwargs.setdefault('parent', self)
         new_node = OSCNode(**nkwargs)
         #print 'new_node: parent=%s, name=%s, root=%s' % (self.name, new_node.name, new_node.is_root_node)
         self.children[new_node.name] = new_node
         new_node.bind(name=self.on_childnode_name_set, 
                       children=self.on_childnode_children_update)
         return new_node
     if parent != self:
         return parent.add_child(**kwargs)
     if not isinstance(address, Address):
         address = Address(address)
     if name is not None:
         address = address.append(name)
     #print address
     #elif 'name' in kwargs:
     #    address = Address(name)
     current, address = address.pop()
     #print 'current=%s, address=%s' % (current, address)
     node = self.children.get(current)
     if not node:
         node = do_add_node(name=current)
     if not len(address.split()):
         return node
     return node.add_child(address=address)
Пример #2
0
 def match_address(self, address):
     if not isinstance(address, Address):
         address = Address(address)
     if self.is_root_node:
         current, address = address.pop()
     #print self.name, ' match: ', address
     current, address = address.pop()
     if not len(current):
         return set([self])
     matched = set()
     nodes = set()
     node = self.children.get(current)
     if node:
         nodes.add(node)
     nodes |= self.match_wildcard(current)
     for node in nodes:
         matched |= node.match_address(address)
     return matched