29 """includes negotiation at start and codecs when sending/receiving
30 translation from Object to string: return string to be transmitted
31 (or at begin negotiation strings)
32 transltaion from string to Object: return Object received
33 (or at begin nothing until negotiation done)
34 raise bridge error on negotiation (TODO: or syntax error in encoding)
35 operations send before codec if negotiated is either stored to queue or discarded
37 Usage: replace send_string, operation_received, connection_ok, log
38 with your own functions/methods
39 Process incoming strings with process_string method:
40 returns string to send, operations received
41 (also calls 'Usage: methods' as needed)
42 Process outgoing operations with process_operation:
43 returns string to send
44 (also calls 'Usage: methods' as needed)
46 def __init__(self, negotiation=NegotiationClient, store_operations = 1, functions=None):
52 if hasattr(functions,
"send_string"):
54 if hasattr(functions,
"operation_received"):
56 if hasattr(functions,
"connection_ok"):
58 if hasattr(functions,
"log"):
59 self.
log = functions.log
62 def send_string(self, data):
63 """send string using transport specific method: specify your own"""
65 print(
"send_string:", data)
67 def operation_received(self, op):
68 """this is called for eac decoded operation"""
70 print(
"operation_received:", op)
72 def connection_ok(self):
73 """this is called after negotiation is done"""
75 print(
"connection_ok")
77 def log(self, type, data):
78 """various debug things"""
79 s =
"\n%s:\n%s" % (type, data)
91 def process_string(self, data):
93 self.
log(
"process_string", data)
100 res_str = res_str + self.
negotiation.get_send_str()
112 return res_str+res_str2, objects+objects2
113 return res_str, res_op
115 def process_operation(self, op=None):
131 def internal_send_string(self, data):
132 if not data:
return ""
133 self.
log(
"send_string", data)
137 def decode_string(self, data):
139 objects = self.
codec.decode(data)
140 self.
log(
"decode_string", objects)
142 self.
log(
"exception in decoding", data)