예제 #1
0
 def process_operation(self, op=None):
     if self.codec:
         res_str = ""
         if self.operations_to_send:
             msg = atlas.Messages(*self.operations_to_send)
             self.operations_to_send = []
             res_str = res_str + self.internal_send_string(
                 self.codec.encode(msg))
         if op != None:
             res_str = res_str + self.internal_send_string(
                 self.codec.encode(op))
         return res_str, atlas.Messages()
     if self.store_operations and op != None:
         self.operations_to_send.append(op)
     return self.process_string("")
예제 #2
0
 def read_all_as_list(self):
     objects = atlas.Messages()
     while 1:
         obj = self.read_object()
         if not obj: break
         objects.append(obj)
     self.check_negotiation_ok()
     return objects
예제 #3
0
 def parse_stream(self, msg):
     self.parse_init()
     self.msg = msg
     self.feed(msg)  #inherited from XMLParser
     if self.stream_flag:
         res = atlas.Messages(*tuple(self.msgList))
         self.msgList = []
         return res
     else:
         if self.msgList:
             res = self.msgList.pop(0)
         else:
             res = None
         return res
예제 #4
0
 def __init__(self, name, mode="r", codec_id=None):
     self.name = name
     self.fp = open(name, mode)
     self.mode = mode
     self.objects = atlas.Messages()
     if mode=="r":
         self.bridge = Bridge(NegotiationClient(), functions=self)
     else:
         if codec_id:
             self.codec_id = codec_id
         else:
             self.codec_id = codecs.get_default_codec().id
         self.bridge = Bridge(NegotiationServer(codecs=(self.codec_id,)), functions=self)
         self.other_negotiation = NegotiationClient()
예제 #5
0
 def process_string(self, data):
     res_str, res_op = ("", atlas.Messages())
     self.log("process_string", data)
     if self.codec:
         return res_str, self.decode_string(data)
     else:
         self.log("Negotiation", str(self.negotiation.state))
         if self.negotiation.state:
             self.negotiation(data)
             res_str = res_str + self.negotiation.get_send_str()
             self.internal_send_string(res_str)
             if not self.negotiation.state:
                 self.process_string("")
         elif self.negotiation.result_code == "fail":
             raise BridgeException("Negotiation failed")
         elif self.negotiation.result_code == "found":
             self.log("Codec negotiated", self.negotiation.selected_codec)
             self.codec = self.negotiation.get_codec()
             self.connection_ok()
             objects = self.decode_string(self.negotiation.str + data)
             res_str2, objects2 = self.process_operation()
             return res_str + res_str2, objects + objects2
     return res_str, res_op
예제 #6
0
def parse_stream(data):
    handler = AtlasParser()
    xml.sax.parseString(data, handler)
    res = atlas.Messages(*tuple(handler.msgList))
    return res