SF.net SVN: fclient: [84] trunk/sandbox/fcp/fcp2_0_message.py
Status: Pre-Alpha
Brought to you by:
jurner
|
From: <ju...@us...> - 2008-01-29 11:27:27
|
Revision: 84
http://fclient.svn.sourceforge.net/fclient/?rev=84&view=rev
Author: jurner
Date: 2008-01-29 03:27:31 -0800 (Tue, 29 Jan 2008)
Log Message:
-----------
Started implementing python <--> fcp value type mapping
Modified Paths:
--------------
trunk/sandbox/fcp/fcp2_0_message.py
Modified: trunk/sandbox/fcp/fcp2_0_message.py
===================================================================
--- trunk/sandbox/fcp/fcp2_0_message.py 2008-01-29 11:27:08 UTC (rev 83)
+++ trunk/sandbox/fcp/fcp2_0_message.py 2008-01-29 11:27:31 UTC (rev 84)
@@ -1,6 +1,8 @@
"""Freennet Client Protocol message"""
import socket
+
+from fcp2_0_consts import MessageParamTypes
#********************************************************************************
#
#********************************************************************************
@@ -151,6 +153,7 @@
msg = clss(None)
buf = []
+ paramTypes = None
#TODO: to buffer or not to buffer?
while True:
@@ -176,6 +179,8 @@
# first line == message name
if msg.name is None:
msg.name = line
+ paramTypes = MessageParamTypes.get(line, None)
+
# get data member
elif line == 'Data':
@@ -192,6 +197,13 @@
# get next paramater
else:
head, sep, tail = line.partition('=')
+
+ # covert fcp to python value if necessary
+ if paramTypes is not None:
+ paramType = paramTypes.get(head, None)
+ if paramType is not None:
+ tail = paramType.fcpToPython(tail)
+
msg.params[head] = tail
# TODO: errorchek params?
#if not sep: pass
@@ -217,9 +229,18 @@
def pprint(self):
"""Returns the message as nicely formated human readable string"""
out = ['', '>>' + self.name, ]
+ paramTypes = MessageParamTypes.get(self.name, None)
+
for param, value in self.params.items():
if param.startswith(self.ParamPrefixPrivate):
continue
+
+ # convert python to fcp value if necessary
+ if paramTypes is not None:
+ paramType = paramTypes.get(param, None)
+ if paramType is not None:
+ value = paramType.pythonToFcp(value)
+
out.append('>> %s=%s' % (param, value))
out.append('>>EndMessage')
return '\n'.join(out)
@@ -235,9 +256,18 @@
def toString(self):
"""Returns the message as formated string ready to be send"""
out = [self.name, ]
+ paramTypes = MessageParamTypes.get(self.name, None)
+
for param, value in self.params.items():
if param.startswith(self.ParamPrefixPrivate):
continue
+
+ # convert python to fcp value if necessary
+ if paramTypes is not None:
+ paramType = paramTypes.get(param, None)
+ if paramType is not None:
+ value = paramType.pythonToFcp(value)
+
out.append('%s=%s' % (param, value))
if self.data:
assert 'DataLength' in self.params, 'DataLength member required'
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|