[Nym3-commit] r280 - trunk/nym3/Client
jr at conuropsis.org
jr at conuropsis.org
Mon Jun 6 00:12:08 CEST 2005
Author: jr
Date: 2005-06-06 00:12:07 +0200 (Mon, 06 Jun 2005)
New Revision: 280
Modified:
trunk/nym3/Client/Main.py
Log:
-change decode_message_reference signature to allow lazy calculation of the
references tables
-a mid's length is exactly midLen
Modified: trunk/nym3/Client/Main.py
===================================================================
--- trunk/nym3/Client/Main.py 2005-06-01 11:08:53 UTC (rev 279)
+++ trunk/nym3/Client/Main.py 2005-06-05 22:12:07 UTC (rev 280)
@@ -165,35 +165,59 @@
ds = binascii.unhexlify(s)
except TypeError:
return False
- return len(ds) <= Common.midLength
+ return len(ds) == Common.midLength
-def decode_message_references(ui, refs, keys, h):
+class DecodeException(Exception): pass
+ """Exception thrown by a decoding function in case of error"""
+
+def decode_message_references(refs, keys, h):
"""Generate a list of mids from a list of message references, refs,
a list of keys and a hashtable.
- a reference is either a mid or a string of the format <key>:<val>,
+ Return the list of mid if all the mids can be decoded.
+ Throw an DecodeException with as argument a string describing the cause of
+ error.
+
+ A reference is either a mid or a string of the format <key>:<val>,
where key is in keys and does not contain the caracter ':'.
- h is a hashtable of hashtable: h[<key>][<str>] contains the mid
- corresponding to a given str for one key."""
+ h is a hashtable: h[<key>] contains a 2-uple (f, a)
+ where f is a function to call with the arguments in the tuple a to
+ get a hash h'. h'[s] contains the mid corresponding to the string s
+ for the key <key>."""
+
+ #we chose this signature so that we can have lazy loading of the
+ #correspondance table.
l = []
+ loaded_h = {}
for e in refs:
if ':' not in e:
if is_hex_mid(e):
l.append(binascii.unhexlify(e))
else:
- ui.display("%s: not a valid mid" % e)
+ throw DecodeException("%s: not a valid mid" % e)
else:
s = e.split(':', 1)
if s[0] not in keys:
- ui.display("%s: not a valid index key" % s[0])
- continue
+ throw DecodeException("%s: not a valid index key" % s[0])
try:
- e2 = h[s[0]][s[1]]
+ if not loaded_h.has_key(s[0]):
+ if not h.has_key(s[0]):
+ throw DecodeException("%s: no correspondance table " +
+ "callback provided for this key" % s[0])
+ f, a = h[s[0]]
+ try:
+ loaded_h[s[0]] = f(*a)
+ except:
+ throw DecodeException("%s: defective callback " +
+ "provided for this key" % s[0])
+ e2 = loaded_h[s[0]][s[1]]
if len(e2) == Common.midLength:
l.append(e2)
else:
- ui.display("%s: dereferenced value not a valid mid" % e)
+ throw DecodeException("%s: dereferenced value not " +
+ "a valid mid" % e)
except KeyError:
- ui.display("%s: not a valid index for key %s" % (s[1], s[0]))
+ throw DecodeException("%s: not a valid index for key %s" %
+ (s[1], s[0]))
return l
def processMessage(msg, config, ui, nickname):
More information about the Nym3-commit
mailing list