SF.net SVN: fclient: [354] trunk/sandbox/fcp2/iohandler.py
Status: Pre-Alpha
Brought to you by:
jurner
From: <jU...@us...> - 2008-03-10 13:03:35
|
Revision: 354 http://fclient.svn.sourceforge.net/fclient/?rev=354&view=rev Author: jUrner Date: 2008-03-10 06:03:35 -0700 (Mon, 10 Mar 2008) Log Message: ----------- some fixes for mesages Modified Paths: -------------- trunk/sandbox/fcp2/iohandler.py Modified: trunk/sandbox/fcp2/iohandler.py =================================================================== --- trunk/sandbox/fcp2/iohandler.py 2008-03-10 13:03:23 UTC (rev 353) +++ trunk/sandbox/fcp2/iohandler.py 2008-03-10 13:03:35 UTC (rev 354) @@ -60,13 +60,13 @@ BufferSize = 4096 def __init__(self, **kwargs): + """ """ - @param kwargs: any additional keyword arguments passed to L{IOHandler.connect} - """ def connect(self, **kwargs): """Should connect to the io device + @param kwargs: any additional keyword arguments passed to L{IOHandler.connect} @return: always None @raise L{IOConnectFailed}: in case something goes wrong """ @@ -223,7 +223,7 @@ self.close() self._log.info(consts.LogMessages.Connecting + ' %r' % kwargs) - self.io = self._ioPrototype(**kwargs) + self.io = self._ioPrototype() yield False # have to yield at least once to make unittests work (io has to be created!!) try: self.io.connect(**kwargs) @@ -283,9 +283,8 @@ self._log.critical(consts.LogMessages.CaughtException + '\n' + traceback.traceback.format_exc()) self.close() raise Exception(details) + - - def readMessage(self): """Reads the next message from io device @return: (Message) next message from the socket @@ -299,7 +298,7 @@ # node end with "Data" if data is passed. Alternative would be to check for both # and rely on the 'DataLength' member to indicate if data is included. This # should work for all messages except 'DataFound' - hasData = False + mayHaveData = False eof = -1 while eof < 0: eof = self._receiveBuffer.find(self.TerminatorEndMessage) @@ -309,7 +308,7 @@ eof = self._receiveBuffer.find(self.TerminatorData) if eof > -1: eof += len(self.TerminatorData) - hasData = True + mayHaveData = True if eof < 0: self.readBytes(self.io.BufferSize) @@ -318,52 +317,25 @@ p = [i for i in chunk.split('\n') if i] # Fcp ignores empty lines, so do we p.pop() if not p: - raise MessageParseError('Missing message name') + raise MessageParseError('No message name present') msgName = p.pop(0) msgClass = message.MessagesAll.get(msgName, None) - # TODO: log? if msgClass is None: self._log.debug(consts.LogMessages.CreatingNewMessageType + ' "%s"' % msgClassname) msgClass = message.newMessageType(msgName) msg = msgClass() # process param --> value fields - # - #NOTE:usually if data is passed DataLength determines how much have to handle - # special case ClientPutComplexDir where it is passed in Files.(N).DataLength. - # Additionally Files.(N).DataLength is converted to int here. - clientPutComplexDirDataLength = 0 - isClientPutComplexDir = msgName == consts.Message.ClientPutComplexDir - for line in p: - paramName, sep, paramValue = line.partition('=') - - # covert fcp to python value if necessary - paramType = msg._param_types_.get(paramName, None) - if paramType is not None: - paramValue = paramType.fcpToPython(paramValue) - msg[paramName] = paramValue - - #TODO: move to message.ClientPutComplexDir - - # handle special case PutComplexDir - if isClientPutComplexDir: - tmp_paramName = paramName.split('.') - if len(tmp_paramName) == 3: - if tmp_paramName[-1] == 'DataLength': - n = types.FcpTypeInt.fcpToPython(paramValue) - clientPutComplexDirDataLength += n - msg[paramName] = n - + params = dict([line.split('=', 1) for line in p]) + if not msg._restoreParams(params): + raise MessageParseError('Invalid message parameters') + # get associated data if necessary - if hasData: - if isClientPutComplexDir: - n = clientPutComplexDirDataLength - else: - # make shure DataLength is int, otherwise we might loop here forever - try: - n = int(msg['DataLength']) - except ValueError: - raise MessageParseError('DataLength param must be type(int)') + if mayHaveData: + n = msg._getDataLength() + if not isinstance(n, (int, long)): + raise ValueError('DataLength must be type(int)') + if n > 0: while self._receiveBuffer: if len(self._receiveBuffer) >= n: This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |