[mnet-devel] patch: tidy up printouts
Zooko O'Whielacronx
zooko at zooko.com
Tue Feb 17 16:50:32 GMT 2004
This patch does two things: 1. make the debugprintsouts consistent with regard
to whether message types are quoted or not. (After this patch, they're not.).
This could possibly be important for weather.pl or other log-grepping tools.
2. make chunks and widgets repr themselves in mnetbase32 instead of mojosixbit.
This isn't a very important patch, but on the other hand is very unlikely to
hurt anything.
--- common/ChunkObj.py 4 Mar 2003 12:49:56 -0000 1.17
+++ common/ChunkObj.py 17 Feb 2004 16:06:37 -0000
@@ -15,6 +15,7 @@ import exceptions, types
# pyutil modules
# from debugprint import debugprint
+import humread # required to update the value of "hr" in humanreadable. This is fixed in v0.7. --Zooko 2004-02-13
import humanreadable
import nummedobj
@@ -80,8 +83,8 @@ class ChunkObj(nummedobj.NummedObj):
else:
self.rebuilder = apply(blockshare.Rebuild, makerebuildparams(self.padded_chunk_len, totalsharesneeded=chunkmap.numneeded, totalsharesinpiece=chunkmap.numtotal))
self.chunkdata = None
- self.rep = "<%s %s %s, %s KB, %s/%s>" % ((self.__class__.__name__, self.objid,) + tuple(map(humanreadable.hr, (self.chunkmap.chunkId, self.chunkmap.chunklen/2**10, self.chunkmap.numneeded, self.chunkmap.numtotal,))))
+ self.rep = "<ChunkObj %s %s, %s KB, %s/%s>" % (humread.abbrev(self.chunkmap.chunkId), self.objid, self.chunkmap.chunklen/2**10, self.chunkmap.numneeded, self.chunkmap.numtotal,)
def __repr__(self):
return self.rep
--- common/Conversation.py 14 Feb 2004 18:44:50 -0000 1.23
+++ common/Conversation.py 17 Feb 2004 16:06:38 -0000
@@ -25,6 +25,8 @@ import DoQ
from debugprint import debugprint, debugstream
import nummedobj
import config
+import humread # required to update the value of "hr" in humanreadable. This is fixed in v0.7. --Zooko 2004-02-13
+import humanreadable
# Mnet modules
import Cache
@@ -37,7 +39,6 @@ import MojoKey
import MojoMessage
from confutils import confman
import idlib
-from human_readable import human_readable, hr
import mencode
import modval
import mojosixbit
@@ -132,11 +133,11 @@ class ConversationManager:
def initiate_and_return_first_message(self, counterparty_id, conversationtype, firstmsgbody, outcome_func, timeout = MojoConstants.DEFAULT_TIMEOUT, notes = None, mymetainfo=None, post_timeout_outcome_func=None):
"""
- @precondition `counterparty_id' must be an id.: idlib.is_sloppy_id(counterparty_id): "id: %s" % hr(id)
+ @precondition `counterparty_id' must be an id.: idlib.is_sloppy_id(counterparty_id): "id: %s" % humanreadable.hr(id)
returns a tuple of (message_id, binary_message_string)
"""
- assert idlib.is_sloppy_id(counterparty_id), "precondition: `counterparty_id' must be an id." + " -- " + "id: %s" % hr(id)
+ assert idlib.is_sloppy_id(counterparty_id), "precondition: `counterparty_id' must be an id." + " -- " + "id: %s" % humanreadable.hr(id)
counterparty_id = idlib.canonicalize(counterparty_id, "broker")
@@ -210,22 +211,22 @@ class ConversationManager:
"""
@param msgbody the message body to be sent back
- @precondition `prevmsgId' must be a binary id.: idlib.is_binary_id(prevmsgId): "prevmsgId: %s" % hr(prevmsgId)
- @precondition `msgbody' must be either None or else the full msg dict, containing either a "mojo header" subdict or a "mojo message" subdict or both.: (not msgbody) or is_mojo_message(msgbody): "msgbody: %s" % hr(msgbody)
- @precondition internal1: self._map_inmsgid_to_info.get(prevmsgId) is not None: "prevmsgId: %s" % hr(prevmsgId)
- @precondition internal2: (type(self._map_inmsgid_to_info.get(prevmsgId)) in (types.TupleType, types.ListType)): "self._map_inmsgid_to_info.get(prevmsgId): %s :: %s" % (hr(self._map_inmsgid_to_info.get(prevmsgId)), hr(type(self._map_inmsgid_to_info.get(prevmsgId))))
- @precondition internal3: self._map_inmsgid_to_info.get(prevmsgId)[2] == EXPECTING_RESPONSE: "self._map_inmsgid_to_info.get(prevmsgId): %s" % hr(self._map_inmsgid_to_info.get(prevmsgId))
- @precondition internal4: idlib.is_binary_id(self._map_inmsgid_to_info.get(prevmsgId)[0]): "self._map_inmsgid_to_info.get(prevmsgId)[0]: %s :: %s" % (hr(self._map_inmsgid_to_info.get(prevmsgId)[0]), hr(type(self._map_inmsgid_to_info.get(prevmsgId)[0])))
- """
- assert idlib.is_binary_id(prevmsgId), "precondition: `prevmsgId' must be a binary id." + " -- " + "prevmsgId: %s" % hr(prevmsgId)
- assert (not msgbody) or is_mojo_message(msgbody), "precondition: `msgbody' must be either None or else the full msg dict, containing either a \"mojo header\" subdict or a \"mojo message\" subdict or both." + " -- " + "msgbody: %s" % hr(msgbody)
- assert self._map_inmsgid_to_info.get(prevmsgId) is not None, "precondition: internal1" + " -- " + "prevmsgId: %s" % hr(prevmsgId)
- assert (type(self._map_inmsgid_to_info.get(prevmsgId)) in (types.TupleType, types.ListType)), "precondition: internal2" + " -- " + "self._map_inmsgid_to_info.get(prevmsgId): %s :: %s" % (hr(self._map_inmsgid_to_info.get(prevmsgId)), hr(type(self._map_inmsgid_to_info.get(prevmsgId))))
- assert self._map_inmsgid_to_info.get(prevmsgId)[2] == EXPECTING_RESPONSE, "precondition: internal3" + " -- " + "self._map_inmsgid_to_info.get(prevmsgId): %s" % hr(self._map_inmsgid_to_info.get(prevmsgId))
- assert idlib.is_binary_id(self._map_inmsgid_to_info.get(prevmsgId)[0]), "precondition: internal4" + " -- " + "self._map_inmsgid_to_info.get(prevmsgId)[0]: %s :: %s" % (hr(self._map_inmsgid_to_info.get(prevmsgId)[0]), hr(type(self._map_inmsgid_to_info.get(prevmsgId)[0])))
+ @precondition `prevmsgId' must be a binary id.: idlib.is_binary_id(prevmsgId): "prevmsgId: %s" % humanreadable.hr(prevmsgId)
+ @precondition `msgbody' must be either None or else the full msg dict, containing either a "mojo header" subdict or a "mojo message" subdict or both.: (not msgbody) or is_mojo_message(msgbody): "msgbody: %s" % humanreadable.hr(msgbody)
+ @precondition internal1: self._map_inmsgid_to_info.get(prevmsgId) is not None: "prevmsgId: %s" % humanreadable.hr(prevmsgId)
+ @precondition internal2: (type(self._map_inmsgid_to_info.get(prevmsgId)) in (types.TupleType, types.ListType)): "self._map_inmsgid_to_info.get(prevmsgId): %s :: %s" % (humanreadable.hr(self._map_inmsgid_to_info.get(prevmsgId)), humanreadable.hr(type(self._map_inmsgid_to_info.get(prevmsgId))))
+ @precondition internal3: self._map_inmsgid_to_info.get(prevmsgId)[2] == EXPECTING_RESPONSE: "self._map_inmsgid_to_info.get(prevmsgId): %s" % humanreadable.hr(self._map_inmsgid_to_info.get(prevmsgId))
+ @precondition internal4: idlib.is_binary_id(self._map_inmsgid_to_info.get(prevmsgId)[0]): "self._map_inmsgid_to_info.get(prevmsgId)[0]: %s :: %s" % (humanreadable.hr(self._map_inmsgid_to_info.get(prevmsgId)[0]), humanreadable.hr(type(self._map_inmsgid_to_info.get(prevmsgId)[0])))
+ """
+ assert idlib.is_binary_id(prevmsgId), "precondition: `prevmsgId' must be a binary id." + " -- " + "prevmsgId: %s" % humanreadable.hr(prevmsgId)
+ assert (not msgbody) or is_mojo_message(msgbody), "precondition: `msgbody' must be either None or else the full msg dict, containing either a \"mojo header\" subdict or a \"mojo message\" subdict or both." + " -- " + "msgbody: %s" % humanreadable.hr(msgbody)
+ assert self._map_inmsgid_to_info.get(prevmsgId) is not None, "precondition: internal1" + " -- " + "prevmsgId: %s" % humanreadable.hr(prevmsgId)
+ assert (type(self._map_inmsgid_to_info.get(prevmsgId)) in (types.TupleType, types.ListType)), "precondition: internal2" + " -- " + "self._map_inmsgid_to_info.get(prevmsgId): %s :: %s" % (humanreadable.hr(self._map_inmsgid_to_info.get(prevmsgId)), humanreadable.hr(type(self._map_inmsgid_to_info.get(prevmsgId))))
+ assert self._map_inmsgid_to_info.get(prevmsgId)[2] == EXPECTING_RESPONSE, "precondition: internal3" + " -- " + "self._map_inmsgid_to_info.get(prevmsgId): %s" % humanreadable.hr(self._map_inmsgid_to_info.get(prevmsgId))
+ assert idlib.is_binary_id(self._map_inmsgid_to_info.get(prevmsgId)[0]), "precondition: internal4" + " -- " + "self._map_inmsgid_to_info.get(prevmsgId)[0]: %s :: %s" % (humanreadable.hr(self._map_inmsgid_to_info.get(prevmsgId)[0]), humanreadable.hr(type(self._map_inmsgid_to_info.get(prevmsgId)[0])))
counterparty_id, inmsgtype, status = self._map_inmsgid_to_info.get(prevmsgId)
- assert idlib.is_binary_id(counterparty_id), "`counterparty_id' must be a binary id." + " -- " + "counterparty_id: %s" % hr(counterparty_id)
+ assert idlib.is_binary_id(counterparty_id), "`counterparty_id' must be a binary id." + " -- " + "counterparty_id: %s" % humanreadable.hr(counterparty_id)
self.drop_request_state(prevmsgId)
msgstr = MojoMessage.makeResponseMessage(inmsgtype + ' response', msgbody, prevmsgId, freshnessproof=self._map_cid_to_freshness_proof.get(counterparty_id), mymetainfo=mymetainfo)
@@ -242,12 +243,12 @@ class ConversationManager:
@throws MojoMessage.BadFormatError if the message isn't properly formatted in
MojoMessage format
- @precondition `counterparty_id' must be an id.: idlib.is_sloppy_id(counterparty_id): "counterparty_id: %s" % hr(counterparty_id)
+ @precondition `counterparty_id' must be an id.: idlib.is_sloppy_id(counterparty_id): "counterparty_id: %s" % humanreadable.hr(counterparty_id)
- @postcondition Result must not be `None'.: result is not None: "result: %s" % hr(result)
- @postcondition Result must be either MojoConstants.NO_RESPONSE or MojoConstants.ASYNC_RESPONSE or else a tuple whose first element is the full msg body dict and whose second element is a commshint, containing either a "mojo header" subdict or a "mojo message" subdict or both.: (result is MojoConstants.NO_RESPONSE) or (result is MojoConstants.ASYNC_RESPONSE) or ((type(result) in (types.TupleType, types.ListType,)) and (len(result) == 2) and is_mojo_message(result[0]) and CommHints.is_hint(result[1])): "result: %s" % hr(result)
+ @postcondition Result must not be `None'.: result is not None: "result: %s" % humanreadable.hr(result)
+ @postcondition Result must be either MojoConstants.NO_RESPONSE or MojoConstants.ASYNC_RESPONSE or else a tuple whose first element is the full msg body dict and whose second element is a commshint, containing either a "mojo header" subdict or a "mojo message" subdict or both.: (result is MojoConstants.NO_RESPONSE) or (result is MojoConstants.ASYNC_RESPONSE) or ((type(result) in (types.TupleType, types.ListType,)) and (len(result) == 2) and is_mojo_message(result[0]) and CommHints.is_hint(result[1])): "result: %s" % humanreadable.hr(result)
"""
- assert idlib.is_sloppy_id(counterparty_id), "precondition: `counterparty_id' must be an id." + " -- " + "counterparty_id: %s" % hr(counterparty_id)
+ assert idlib.is_sloppy_id(counterparty_id), "precondition: `counterparty_id' must be an id." + " -- " + "counterparty_id: %s" % humanreadable.hr(counterparty_id)
counterparty_id = idlib.canonicalize(counterparty_id, "broker")
@@ -272,9 +273,9 @@ class ConversationManager:
if config.MAX_VERBOSITY >= 5:
debugprint("<=== %s: receiving: %s, %s bytes uncomp\n" % (humread.abbrev(counterparty_id), MojoMessage.repr_msg(msg), len(msg),), v=5)
elif config.MAX_VERBOSITY >= 3:
- debugprint("<=== %s: receiving: (id: %s, type: %s, %s bytes uncomp, ...)\n", args=(counterparty_id, msgId, msgtype, len(msg)), v=3)
+ debugprint("<=== %s: receiving: (id: %s, type: %s, %s bytes uncomp, ...)\n" % (humanreadable.hr(counterparty_id), humanreadable.hr(msgId), msgtype, len(msg),), v=3)
elif config.MAX_VERBOSITY >= 2:
- debugprint("<=== %s: receiving: (type: %s, %s bytes uncomp, ...)\n", args=(counterparty_id, msgtype, len(msg),), v=2)
+ debugprint("<=== %s: receiving: (type: %s, %s bytes uncomp, ...)\n" % (humanreadable.hr(counterparty_id), msgtype, len(msg),), v=2)
elif config.MAX_VERBOSITY >= 1:
debugprint("<=== %s: receiving: (%s bytes uncomp, ...)\n", args=(counterparty_id, len(msg),), v=1)
@@ -312,7 +313,7 @@ class ConversationManager:
response = result
commhints = HINT_NO_HINT
- assert (response in (MojoConstants.NO_RESPONSE, MojoConstants.ASYNC_RESPONSE,)) or is_mojo_message(response), 'Result must be either None or else the full msg body dict, containing either a "mojo header" subdict or a "mojo message" subdict or both.' + ' -- ' + "result: %s" % hr(result)
+ assert (response in (MojoConstants.NO_RESPONSE, MojoConstants.ASYNC_RESPONSE,)) or is_mojo_message(response), 'Result must be either None or else the full msg body dict, containing either a "mojo header" subdict or a "mojo message" subdict or both.' + ' -- ' + "result: %s" % humanreadable.hr(result)
if response in (MojoConstants.NO_RESPONSE, MojoConstants.ASYNC_RESPONSE,):
return response
else:
@@ -390,9 +391,9 @@ class ConversationManager:
self._map_cid_to_freshness_proof[counterparty_id] = msgId
result = self._process(inmsg, msgId, counterparty_id, commstrat)
- assert result is not None, "Result must not be `None'." + " -- " + "result: %s" % hr(result)
- assert (result is MojoConstants.NO_RESPONSE) or (result is MojoConstants.ASYNC_RESPONSE) or ((type(result) in (types.TupleType, types.ListType,)) and (len(result) == 2) and is_mojo_message(result[0]) and CommHints.is_hint(result[1])), "postcondition: Result must be either MojoConstants.NO_RESPONSE or MojoConstants.ASYNC_RESPONSE or else a tuple whose first element is the full msg body dict, containing either a \"mojo header\" subdict or a \"mojo message\" subdict or both." + "--" + "result: %s" % hr(result)
+ assert result is not None, "Result must not be `None'." + " -- " + "result: %s" % humanreadable.hr(result)
+ assert (result is MojoConstants.NO_RESPONSE) or (result is MojoConstants.ASYNC_RESPONSE) or ((type(result) in (types.TupleType, types.ListType,)) and (len(result) == 2) and is_mojo_message(result[0]) and CommHints.is_hint(result[1])), "postcondition: Result must be either MojoConstants.NO_RESPONSE or MojoConstants.ASYNC_RESPONSE or else a tuple whose first element is the full msg body dict, containing either a \"mojo header\" subdict or a \"mojo message\" subdict or both." + "--" + "result: %s" % humanreadable.hr(result)
self._MTM._peerman.mark_as_live(counterparty_id)
-------------------------------------------------------
SF.Net is sponsored by: Speed Start Your Linux Apps Now.
Build and deploy apps & Web services for Linux with
a free DVD software kit from IBM. Click Now!
http://ads.osdn.com/?ad_id=1356&alloc_id=3438&op=click
_______________________________________________
mnet-devel mailing list
mnet-devel at lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mnet-devel
More information about the Mnet-devel
mailing list