Commit 921de30e authored by Jelte Jansen's avatar Jelte Jansen
Browse files

merged changes made for review of ticket #22

only minor refactors, no changelog necessary


git-svn-id: svn://bind10.isc.org/svn/bind10/trunk@3458 e5f2f494-b856-4b98-b285-d166d9295462
parents 59017da8 dee43579
......@@ -31,10 +31,8 @@ def remove_identical(a, b):
to_remove = []
if type(a) != dict or type(b) != dict:
raise DataTypeError("Not a dict in remove_identical()")
for ka in a.keys():
if ka in b and a[ka] == b[ka]:
to_remove.append(ka)
for id in to_remove:
duplicate_keys = [key for key in a.keys() if key in b and a[key] == b[key]]
for id in duplicate_keys:
del(a[id])
def merge(orig, new):
......@@ -43,17 +41,20 @@ def merge(orig, new):
new it will be removed in orig."""
if type(orig) != dict or type(new) != dict:
raise DataTypeError("Not a dict in merge()")
for kn in new.keys():
if kn in orig:
if new[kn]:
if type(new[kn]) == dict:
merge(orig[kn], new[kn])
else:
orig[kn] = new[kn]
else:
del orig[kn]
else:
orig[kn] = new[kn]
orig.update(new)
remove_null_items(orig)
def remove_null_items(d):
"""Recursively removes all (key,value) pairs from d where the
value is None"""
null_keys = []
for key in d.keys():
if type(d[key]) == dict:
remove_null_items(d[key])
elif d[key] is None:
null_keys.append(key)
for k in null_keys:
del d[k]
def find(element, identifier):
"""Returns the subelement in the given data element, raises DataNotFoundError if not found"""
......
......@@ -78,6 +78,8 @@ class Session:
raise SessionError("Session has been closed.")
if type(env) == dict:
env = isc.cc.message.to_wire(env)
if len(env) > 65535:
raise ProtocolError("Envelope too large")
if type(msg) == dict:
msg = isc.cc.message.to_wire(msg)
self._socket.setblocking(1)
......@@ -113,9 +115,6 @@ class Session:
if (seq == None and "reply" not in env) or (seq != None and "reply" in env and seq == env["reply"]):
return env, msg
else:
tmp = None
if "reply" in env:
tmp = env["reply"]
self._queue.append((env,msg))
return self.recvmsg(nonblock, seq)
else:
......
......@@ -137,6 +137,11 @@ class testSession(unittest.TestCase):
sess.close()
self.assertRaises(SessionError, sess.sendmsg, {}, {"hello": "a"})
def test_env_too_large(self):
sess = MySession()
largeenv = { "a": "b"*65535 }
self.assertRaises(ProtocolError, sess.sendmsg, largeenv, {"hello": "a"})
def test_session_sendmsg(self):
sess = MySession()
sess.sendmsg({}, {"hello": "a"})
......
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