[svn] commit: r3458 - in /trunk: ./ src/bin/bind10/bind10.py.in src/lib/python/isc/cc/data.py src/lib/python/isc/cc/session.py src/lib/python/isc/cc/tests/session_test.py
BIND 10 source code commits
bind10-changes at lists.isc.org
Fri Nov 5 09:31:20 UTC 2010
Author: jelte
Date: Fri Nov 5 09:31:20 2010
New Revision: 3458
Log:
merged changes made for review of ticket #22
only minor refactors, no changelog necessary
Modified:
trunk/ (props changed)
trunk/src/bin/bind10/bind10.py.in (props changed)
trunk/src/lib/python/isc/cc/data.py
trunk/src/lib/python/isc/cc/session.py
trunk/src/lib/python/isc/cc/tests/session_test.py
Modified: trunk/src/lib/python/isc/cc/data.py
==============================================================================
--- trunk/src/lib/python/isc/cc/data.py (original)
+++ trunk/src/lib/python/isc/cc/data.py Fri Nov 5 09:31:20 2010
@@ -31,10 +31,8 @@
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 @@
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"""
Modified: trunk/src/lib/python/isc/cc/session.py
==============================================================================
--- trunk/src/lib/python/isc/cc/session.py (original)
+++ trunk/src/lib/python/isc/cc/session.py Fri Nov 5 09:31:20 2010
@@ -78,6 +78,8 @@
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 @@
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:
Modified: trunk/src/lib/python/isc/cc/tests/session_test.py
==============================================================================
--- trunk/src/lib/python/isc/cc/tests/session_test.py (original)
+++ trunk/src/lib/python/isc/cc/tests/session_test.py Fri Nov 5 09:31:20 2010
@@ -137,6 +137,11 @@
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"})
More information about the bind10-changes
mailing list