Ejemplo n.º 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)
Ejemplo n.º 2
0
 def get_full_path(self, address=None):
     if address is None:
         address = Address(self.name)
     else:
         address = address.append_right(self.name)
     if self.is_root_node:
         #print 'full path: ', address
         return address.as_root()
     return self.parent.get_full_path(address)
Ejemplo n.º 3
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
Ejemplo n.º 4
0
 def _sendAddr(self):
     addr = AddrPacket()
     a = Address()
     a.ip = self.external_ip
     a.isIPv4 = True
     a.port = self.port
     a.services = 1
     a.timestamp = time()
     addr.addresses.append(a)
     buf = BytesIO()
     addr.toWire(buf)
     self.broadcast("addr", addr)