def pns_walk_continue (self, model, routes): # handle the result of the semantic walk for all kind of # statements coming from all directions, including the user # command (,p,o). # if model[0] == '': # user command, send response to the PNS/TCP session # as an ordered set of contexts and related names. model[3] = encode (netunicode.encode ([ u"%d:%s,%s" % ( len (c), c, netunicode.encode (n) ) for w, c, n in routes ]), 'UTF-8') self.pns_peer.pns_tcp_continue (model, '_') return # statements if model[3] and (len (model) > 4 or model[2] == ''): # named statement, index the subject and map it to # its original context if the statement comes from # a PNS/TCP session or is a question # self.pns_map (model) if len (model) > 4: # echo only PNS/TCP statements routed, not PNS/UDP # statements relayed. # self.pns_peer.pns_tcp_continue (model, '.') if len (routes) == 0: return # if any, find the best routes subscribed best = routes[0][0] circles = ( self.pns_peer.pns_subscribed[context] for context in ( encode (r, 'UTF-8') for w, r, n in routes if w == best ) if self.pns_peer.pns_subscribed.has_key (context) ) if not model[1]: # route protocol statement to circles joined only circles = [ c for c in circles if self.pns_peer.pns_udp.pns_joined.has_key ( c.pns_right ) ] # route to the best circles for circle in circles: circle.pns_statement (model)
def valid (encoded, field, horizon): "validate encoded Public Names in a field and below a given horizon" # try to decode the articulated public names, strip voids names = tuple (netunicode.decode (encoded, False)) if not names: # inarticulated names if encoded in field: # allready in the field return u"" # new in this field field.add (encoded) return encoded # articulated Public Names valids = [] for name in names: # recursively validate each articulated name name = valid (name, field, horizon) if name: valids.append (name) if len (field) >= horizon: break # but only under this horizon if len (valids) > 1: # sort Public Names and encode valids.sort () return netunicode.encode (valids) if len (valids) > 0: # return a "singleton" return valids[0] return u"" # nothing valid to articulate
def valid(encoded, field, horizon): "validate encoded Public Names in a field and below a given horizon" # try to decode the articulated public names, strip voids names = tuple(netunicode.decode(encoded, False)) if not names: # inarticulated names if encoded in field: # allready in the field return u"" # new in this field field.add(encoded) return encoded # articulated Public Names valids = [] for name in names: # recursively validate each articulated name name = valid(name, field, horizon) if name: valids.append(name) if len(field) >= horizon: break # but only under this horizon if len(valids) > 1: # sort Public Names and encode valids.sort() return netunicode.encode(valids) if len(valids) > 0: # return a "singleton" return valids[0] return u"" # nothing valid to articulate
def pns_walk_continue(self, model, routes): # handle the result of the semantic walk for all kind of # statements coming from all directions, including the user # command (,p,o). # if model[0] == '': # user command, send response to the PNS/TCP session # as an ordered set of contexts and related names. model[3] = encode( netunicode.encode([ u"%d:%s,%s" % (len(c), c, netunicode.encode(n)) for w, c, n in routes ]), 'UTF-8') self.pns_peer.pns_tcp_continue(model, '_') return # statements if model[3] and (len(model) > 4 or model[2] == ''): # named statement, index the subject and map it to # its original context if the statement comes from # a PNS/TCP session or is a question # self.pns_map(model) if len(model) > 4: # echo only PNS/TCP statements routed, not PNS/UDP # statements relayed. # self.pns_peer.pns_tcp_continue(model, '.') if len(routes) == 0: return # if any, find the best routes subscribed best = routes[0][0] circles = (self.pns_peer.pns_subscribed[context] for context in (encode(r, 'UTF-8') for w, r, n in routes if w == best) if self.pns_peer.pns_subscribed.has_key(context)) if not model[1]: # route protocol statement to circles joined only circles = [ c for c in circles if self.pns_peer.pns_udp.pns_joined.has_key(c.pns_right) ] # route to the best circles for circle in circles: circle.pns_statement(model)
def pns_walk_out(self, model, routes): # continue the commands, drop the statements routes = pns_weight_routes(routes) assert None == self.select_trigger_log( '<walk-out routes="%d"/>' '<![CDATA[%s]]!><![CDATA[%s]]!>' % (len(routes), netstring.encode(model), encode(netunicode.encode([r[1] for r in routes]), 'UTF-8')), '') self.select_trigger((self.pns_walk_continue, (model, routes)))
def pns_walk_out (self, model, routes): # continue the commands, drop the statements routes = pns_weight_routes (routes) assert None == self.select_trigger_log ( '<walk-out routes="%d"/>' '<![CDATA[%s]]!><![CDATA[%s]]!>' % ( len (routes), netstring.encode (model), encode (netunicode.encode ( [r[1] for r in routes] ), 'UTF-8') ), '' ) self.select_trigger (( self.pns_walk_continue, (model, routes) ))