Commit 46d7e7d8 authored by Jelte Jansen's avatar Jelte Jansen
Browse files

move step 4.2;

fixed the calls to Message module to use the lowercased module name


git-svn-id: svn://bind10.isc.org/svn/bind10/branches/parkinglot@603 e5f2f494-b856-4b98-b285-d166d9295462
parent 2f23e95f
......@@ -198,7 +198,7 @@ class MsgQ:
return
try:
routingmsg = ISC.CC.Message.from_wire(routing)
routingmsg = ISC.CC.message.from_wire(routing)
except DecodeError as err:
self.kill_socket(fd, sock)
sys.stderr.write("Routing decode error: %s\n" % err)
......@@ -228,9 +228,9 @@ class MsgQ:
def preparemsg(self, env, msg = None):
if type(env) == dict:
env = ISC.CC.Message.to_wire(env)
env = ISC.CC.message.to_wire(env)
if type(msg) == dict:
msg = ISC.CC.Message.to_wire(msg)
msg = ISC.CC.message.to_wire(msg)
length = 2 + len(env);
if msg:
length += len(msg)
......
......@@ -17,7 +17,7 @@ import sys
import socket
import struct
from ISC.CC import Message
from ISC.CC import message
class ProtocolError(Exception): pass
class NetworkError(Exception): pass
......@@ -61,9 +61,9 @@ class Session:
if self._closed:
raise SessionError("Session has been closed.")
if type(env) == dict:
env = Message.to_wire(env)
env = message.to_wire(env)
if type(msg) == dict:
msg = Message.to_wire(msg)
msg = message.to_wire(msg)
self._socket.setblocking(1)
length = 2 + len(env);
if msg:
......@@ -82,9 +82,9 @@ class Session:
header_length = struct.unpack('>H', data[0:2])[0]
data_length = len(data) - 2 - header_length
if data_length > 0:
return Message.from_wire(data[2:header_length+2]), Message.from_wire(data[header_length + 2:])
return message.from_wire(data[2:header_length+2]), message.from_wire(data[header_length + 2:])
else:
return Message.from_wire(data[2:header_length+2]), None
return message.from_wire(data[2:header_length+2]), None
return None, None
def _receive_full_buffer(self, nonblock):
......@@ -151,7 +151,7 @@ class Session:
"group": group,
"instance": instance,
"seq": seq,
}, Message.to_wire(msg))
}, message.to_wire(msg))
return seq
def group_recvmsg(self, nonblock = True):
......@@ -172,7 +172,7 @@ class Session:
"instance": routing["instance"],
"seq": seq,
"reply": routing["seq"],
}, Message.to_wire(msg))
}, message.to_wire(msg))
return seq
if __name__ == "__main__":
......
......@@ -5,102 +5,102 @@ class TestCCWireEncoding(unittest.TestCase):
def setUp(self): pass
def test_to_wire_of_string(self):
wire = ISC.CC.Message.to_wire({ "simple" : "string" })
wire = ISC.CC.message.to_wire({ "simple" : "string" })
self.assertEqual(wire, b'Skan\x06simple(\x06string')
def test_from_wire_of_string(self):
wire = b'Skan\x06simple(\x06string'
decoded = ISC.CC.Message.from_wire(wire)
decoded = ISC.CC.message.from_wire(wire)
self.assertEqual(decoded["simple"], "string")
def test_to_wire_of_binary_string(self):
wire = ISC.CC.Message.to_wire({ "simple" : b'\x01\xff\x02\x85' })
wire = ISC.CC.message.to_wire({ "simple" : b'\x01\xff\x02\x85' })
self.assertEqual(wire, b'Skan\x06simple!\x04\x01\xff\x02\x85')
def test_from_wire_of_binary_string(self):
wire = b'Skan\x06simple!\x04\x01\xff\x02\x85'
decoded = ISC.CC.Message.from_wire(wire)
decoded = ISC.CC.message.from_wire(wire)
self.assertEqual(decoded["simple"], b'\x01\xff\x02\x85')
def test_to_wire_of_list(self):
wire = ISC.CC.Message.to_wire({ "simple" : [ "string" ] })
wire = ISC.CC.message.to_wire({ "simple" : [ "string" ] })
self.assertEqual(wire, b'Skan\x06simple#\x08(\x06string')
def test_from_wire_of_list(self):
wire = b'Skan\x06simple#\x08(\x06string'
decoded = ISC.CC.Message.from_wire(wire)
decoded = ISC.CC.message.from_wire(wire)
self.assertEqual(decoded["simple"], [ "string" ])
def test_to_wire_of_hash(self):
wire = ISC.CC.Message.to_wire({ "simple" : { "string" : 1 }})
wire = ISC.CC.message.to_wire({ "simple" : { "string" : 1 }})
self.assertEqual(wire, b'Skan\x06simple"\n\x06string&\x011')
def test_from_wire_of_hash(self):
wire = b'Skan\x06simple"\n\x06string(\x011'
decoded = ISC.CC.Message.from_wire(wire)
decoded = ISC.CC.message.from_wire(wire)
self.assertEqual(decoded["simple"], { "string" : '1' })
def test_to_wire_of_none(self):
wire = ISC.CC.Message.to_wire({ "simple" : None })
wire = ISC.CC.message.to_wire({ "simple" : None })
self.assertEqual(wire, b'Skan\x06simple\x04')
def test_from_wire_of_none(self):
wire = b'Skan\x06simple\x04'
decoded = ISC.CC.Message.from_wire(wire)
decoded = ISC.CC.message.from_wire(wire)
self.assertEqual(decoded["simple"], None)
def test_to_wire_of_empty_string(self):
wire = ISC.CC.Message.to_wire({ "simple" : "" })
wire = ISC.CC.message.to_wire({ "simple" : "" })
self.assertEqual(wire, b'Skan\x06simple(\x00')
def test_from_wire_of_empty_string(self):
wire = b'Skan\x06simple(\x00'
decoded = ISC.CC.Message.from_wire(wire)
decoded = ISC.CC.message.from_wire(wire)
self.assertEqual(decoded["simple"], "")
def test_to_wire_of_utf8_string(self):
wire = ISC.CC.Message.to_wire({ "simple" : "せんせい" })
wire = ISC.CC.message.to_wire({ "simple" : "せんせい" })
self.assertEqual(wire, b'Skan\x06simple(\x0c\xe3\x81\x9b\xe3\x82\x93\xe3\x81\x9b\xe3\x81\x84')
def test_from_wire_of_utf8_string(self):
wire = b'Skan\x06simple(\x0c\xe3\x81\x9b\xe3\x82\x93\xe3\x81\x9b\xe3\x81\x84'
decoded = ISC.CC.Message.from_wire(wire)
decoded = ISC.CC.message.from_wire(wire)
self.assertEqual(decoded["simple"], "せんせい")
def test_to_wire_of_utf8_label(self):
wire = ISC.CC.Message.to_wire({ "せんせい" : "string" })
wire = ISC.CC.message.to_wire({ "せんせい" : "string" })
self.assertEqual(wire, b'Skan\x0c\xe3\x81\x9b\xe3\x82\x93\xe3\x81\x9b\xe3\x81\x84(\x06string')
def test_from_wire_of_utf8_label(self):
wire = b'Skan\x0c\xe3\x81\x9b\xe3\x82\x93\xe3\x81\x9b\xe3\x81\x84(\x06string'
decoded = ISC.CC.Message.from_wire(wire)
decoded = ISC.CC.message.from_wire(wire)
self.assertEqual(decoded["せんせい"], "string")
def test_to_wire_of_bool_true(self):
wire = ISC.CC.Message.to_wire({ "bool": True })
wire = ISC.CC.message.to_wire({ "bool": True })
self.assertEqual(wire, b'Skan\x04bool%\x01\x01')
def test_to_wire_of_bool_false(self):
wire = ISC.CC.Message.to_wire({ "bool": False })
wire = ISC.CC.message.to_wire({ "bool": False })
self.assertEqual(wire, b'Skan\x04bool%\x01\x00')
def test_from_wire_of_bool_true(self):
wire = b'Skan\x04bool%\x01\x01'
decoded = ISC.CC.Message.from_wire(wire)
decoded = ISC.CC.message.from_wire(wire)
self.assertEqual(decoded["bool"], True)
def test_from_wire_of_bool_true(self):
wire = b'Skan\x04bool%\x01\x00'
decoded = ISC.CC.Message.from_wire(wire)
decoded = ISC.CC.message.from_wire(wire)
self.assertEqual(decoded["bool"], False)
def test_to_wire_of_int(self):
wire = ISC.CC.Message.to_wire({ "number": 123 })
wire = ISC.CC.message.to_wire({ "number": 123 })
self.assertEqual(wire, b'Skan\x06number&\x03123')
def test_from_wire_of_int(self):
wire = b'Skan\x06number&\x03123'
decoded = ISC.CC.Message.from_wire(wire)
decoded = ISC.CC.message.from_wire(wire)
self.assertEqual(decoded["number"], 123)
if __name__ == '__main__':
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment