Thread: SF.net SVN: fclient: [310] trunk/sandbox/fcp2/iohandler.py
Status: Pre-Alpha
Brought to you by:
jurner
From: <ju...@us...> - 2008-03-06 11:57:29
|
Revision: 310 http://fclient.svn.sourceforge.net/fclient/?rev=310&view=rev Author: jurner Date: 2008-03-06 03:57:34 -0800 (Thu, 06 Mar 2008) Log Message: ----------- separated a module to handle message io Added Paths: ----------- trunk/sandbox/fcp2/iohandler.py Added: trunk/sandbox/fcp2/iohandler.py =================================================================== --- trunk/sandbox/fcp2/iohandler.py (rev 0) +++ trunk/sandbox/fcp2/iohandler.py 2008-03-06 11:57:34 UTC (rev 310) @@ -0,0 +1,385 @@ + + +import os, sys +import logging +import socket +import time + + +#--> rel import hack +class _RelImportHack(object): + def __init__(self, n): + fpath = os.path.abspath(__file__) + for i in xrange(n): fpath = os.path.dirname(fpath) + sys.path.insert(0, fpath) + def __del__(self): sys.path.pop(0) +hack = _RelImportHack(2) + +from fcp2 import consts +from fcp2 import message +from fcp2 import types + +del hack +#<-- rel import hack + +logging.basicConfig(stream=sys.stdout, level=logging.DEBUG) +logging.addLevelName(consts.DebugVerbosity.Quiet, '') +#***************************************************************************** +# +#***************************************************************************** +class MessageParseError(Exception): + """Exception raised when a message could not be parsed succesfuly""" + +class IOConnectFailed(Exception): + """Exception raised if the object can not be connected""" + +class IOClosed(Exception): + """Exception raised if the object is closed""" + +class IOBroken(Exception): + """Exception raised if the IO connection is broken""" + +class IOTimeout(Exception): + """Exception raised when the io connection is closed""" + + +class IOObject(object): + Timeout = 0 + BufferSize = 4096 + + def __init__(self, ): + pass + + def connect(self, **kwargs): + raise IOConnectFailed('Failed') + + def read(self, n): + raise IOBroken('Broken') + + def write(self, bytes): + raise IOBroken('Broken') + + def close(self): + raise IOClosed('Closed') + + def isOpen(self): + return False + + def setTimeout(self, n): + pass + + +#***************************************************************************** +# +#***************************************************************************** +class SocketIO(IOObject): + Timeout = 0.1 + BufferSize = 4096 + + def __init__(self): + self.socket = None + + def connect(self, **kwargs): + if self.isOpen(): + self.close() + self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + try: + self.socket.connect((kwargs['host'], kwargs['port'])) + except socket.error, details: + raise IOConnectFailed(details) + + def read(self, n): + try: + p = self.socket.recv(n) + if p == '': + raise socket.error('Socket closed by host') + except socket.timeout, details: + raise IOTimeout(details) + except socket.error, details: + self.close() + raise IOBroken(details) + else: + return p + + def write(self, bytes): + try: + self.socket.sendall(bytes) + except socket.error, details: + self.close() + raise IOBroken(details) + + def close(self): + if self.socket is None: + raise IOClosed('Closed') + self.socket.close() + self.socket = None + + def isOpen(self): + return self.socket is not None + + def setTimeout(self, n): + self.socket.settimeout(n) + +#***************************************************************************** +# +#***************************************************************************** +class IOHandler(object): + + TerminatorEndMessage = '\nEndMessage\n' + TerminatorData = '\nData\n' + + + def __init__(self, ioPrototype=SocketIO): + self._ioPrototype = ioPrototype + self._log = logging.getLogger(consts.LoggerNames.ClientIOHandler) + self._receiveBuffer = '' + + self.io = None + + def connect(self, duration=20, timeout=0.5, **kwargs): + for result in self.iterConnect(duration=duration, timeout=timeout, **kwargs): pass + return result + + + def iterConnect(self, duration=20, timeout=0.5, **kwargs): + + if not duration >= 0: + raise ValueError('duration must be >= 0') + if not timeout >= 0: + raise ValueError('timeout must be >= 0') + + if self.isOpen(): + self.close() + + timeElapsed = 0 + while timeElapsed <= duration: + + self._log.info(consts.LogMessages.Connecting + ' %r' % kwargs) + self.io = self._ioPrototype() + try: + self.io.connect(**kwargs) + except IOConnectFailed, details: + self._log.info(consts.LogMessages.ConnectingFailed + ' %s %s' % (IOConnectFailed, details)) + yield False + else: + self.io.setTimeout(self.io.Timeout) + self._log.info(consts.LogMessages.Connected) + yield True + break + + # continue polling + self._log.info(consts.LogMessages.Retry) + timeElapsed += timeout + time.sleep(timeout) + + raise StopIteration + + + def close(self): + self._log.debug(consts.LogMessages.Closing) + self._receiveBuffer = '' + if self.io is not None and self.io.isOpen(): + self.io.close() + self.io = None + + + def isOpen(self): + if self.io is not None: + return self.io.isOpen() + return False + + + def readBytes(self, n): + """Reads n bytes from socket + @param n: (int) number of bytes to read + @return: (tuple) (error-message, bytes-read). If no error was encountered, error-message will be None + """ + try: + #TODO: if \r\n is possible in Fcp, replace it by \n + p = self.io.read(n) + if not p: + raise ValueError('No bytes received and IO did not raise as expected?!?') + self._receiveBuffer += p + except IOBroken, details: + self.close() + self._log.critical(consts.LogMessages.SocketDied) + return IOBroken, details + except IOTimeout, details: # nothing in the queue + return IOTimeout, details + return None, None + + + def readMessage(self): + """Reads the next a message from io + @return: (Message) next message from the socket + + @note: if something goes wrong the according exception is raised + """ + # read message from io + # + #NOTE: messages carying data may end with 'EndMessage' or 'Data'. + # This is a bit messed up in Fcp. We assume here all messages from the + # 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 + eof = -1 + while eof < 0: + eof = self._receiveBuffer.find(self.TerminatorEndMessage) + if eof > -1: + eof += len(self.TerminatorEndMessage) + else: + eof = self._receiveBuffer.find(self.TerminatorData) + if eof > -1: + eof += len(self.TerminatorData) + hasData = True + if eof < 0: + exception, details = self.readBytes(self.io.BufferSize) + if exception is not None: + raise exception(details) + + # prep message + chunk, self._receiveBuffer = self._receiveBuffer[ :eof], self._receiveBuffer[eof: ] + 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') + msgName = p.pop(0) + msg = message.Message(msgName) + paramTypes = types.MessageParamTypes.get(msgName, None) + + # 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 + if paramTypes is not None: + paramType = paramTypes.get(paramName, None) + if paramType is not None: + paramValue = paramType.fcpToPython(paramValue) + msg[paramName] = paramValue + + # 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 + + # get associated data if necessary + if hasData: + if isClientPutComplexDir: + n = clientPutComplexDirDataLength + else: + n = msg['DataLength'] + if n > 0: + while self._receiveBuffer: + if len(self._receiveBuffer) >= n: + msg.data, self._receiveBuffer = self._receiveBuffer[ :n], self._receiveBuffer[n: ] + break + + exception, details = self.readBytes(self.io.BufferSize) + if exception == IOTimeout: # try again later + self._receiveBuffer = chunk + self._receiveBuffer + elif exception is not None: + raise exception(details) + + self._log.debug(consts.LogMessages.Received + msg.pprint()) + return msg + + + + def sendMessage(self, name, data=None, **params): + """Sends a message to freenet + @param name: name of the message to send + @param data: data to atatch to the message + @param params: {para-name: param-calue, ...} of parameters to pass along + with the message (see freenet protocol) + @raise SocketError: if the socket connection to the node dies unexpectedly + If an error handler is passed to the client it is called emidiately before the error + is raised. + + @note: you can use this method to send a message to the node, bypassing all + track keeping methods of the client + """ + return self.sendMessageEx(message.Message(name, data=data, **params)) + + + def sendMessageEx(self, msg): + """Sends a message to freenet + @param msg: (Message) message to send + @return: Message + @raise SocketError: if the socket connection to the node dies unexpectedly. + If an error handler is passed to the client it is called emidiately before the error + is raised. + + @note: you can use this method to send a message to the node, bypassing all + track keeping methods of the client + """ + self._log.debug(consts.LogMessages.Sending + msg.pprint()) + try: + self.io.write(msg.toString()) + except IOBroken, details: + self.close() + self._log.critical(consts.LogMessages.SocketDied) + raise IOBroken(details) + + + def setDebugVerbosity(self, debugVerbosity): + self._log.setLevel(debugVerbosity) + + + def setIOPrototype(self, ioObject): + """ + @note: if the connection is open the connection is closed in the call + """ + if self.isOpen(): + self.close() + + if ioObject.BufferSize <= 0: + raise ValueError('IOObject.BufferSize must be > 0') + self._ioPrototype = ioObject + + +#*********************************************************************************************** +# +#*********************************************************************************************** +if __name__ == '__main__': + + c = IOHandler() + def cb(event, *params): + print event + #print event == c.events.MessageReceived + #print event.msg + + + #for e in c.events: + # e += cb + + if c.connect(duration=1, host='127.0.0.1', port=9481): + + + c.sendMessageEx(message.Message(consts.Message.ClientHello, Name='foo', ExpectedVersion="2,0")) + msg = c.readMessage() + + + #print 222, c.nextMessage() + + c.close() + + + + + + + + + \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ju...@us...> - 2008-03-06 12:12:15
|
Revision: 321 http://fclient.svn.sourceforge.net/fclient/?rev=321&view=rev Author: jurner Date: 2008-03-06 04:12:21 -0800 (Thu, 06 Mar 2008) Log Message: ----------- removed test code Modified Paths: -------------- trunk/sandbox/fcp2/iohandler.py Modified: trunk/sandbox/fcp2/iohandler.py =================================================================== --- trunk/sandbox/fcp2/iohandler.py 2008-03-06 12:09:53 UTC (rev 320) +++ trunk/sandbox/fcp2/iohandler.py 2008-03-06 12:12:21 UTC (rev 321) @@ -68,7 +68,6 @@ def setTimeout(self, n): pass - #***************************************************************************** # #***************************************************************************** @@ -294,9 +293,8 @@ self._log.debug(consts.LogMessages.Received + msg.pprint()) return msg + - - def sendMessage(self, name, data=None, **params): """Sends a message to freenet @param name: name of the message to send @@ -353,33 +351,5 @@ # #*********************************************************************************************** if __name__ == '__main__': - - c = IOHandler() - def cb(event, *params): - print event - #print event == c.events.MessageReceived - #print event.msg - - - #for e in c.events: - # e += cb - - if c.connect(duration=1, host='127.0.0.1', port=9481): - - - c.sendMessageEx(message.Message(consts.Message.ClientHello, Name='foo', ExpectedVersion="2,0")) - msg = c.readMessage() - - - #print 222, c.nextMessage() - - c.close() - - - - - - - - + pass \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ju...@us...> - 2008-03-06 18:25:05
|
Revision: 326 http://fclient.svn.sourceforge.net/fclient/?rev=326&view=rev Author: jurner Date: 2008-03-06 10:25:06 -0800 (Thu, 06 Mar 2008) Log Message: ----------- added docs and a bit of this and that Modified Paths: -------------- trunk/sandbox/fcp2/iohandler.py Modified: trunk/sandbox/fcp2/iohandler.py =================================================================== --- trunk/sandbox/fcp2/iohandler.py 2008-03-06 17:45:43 UTC (rev 325) +++ trunk/sandbox/fcp2/iohandler.py 2008-03-06 18:25:06 UTC (rev 326) @@ -43,47 +43,94 @@ """Exception raised when the io connection is closed""" -class IOObject(object): +class IOObjectBase(object): + """Base class for io objects + + @cvar Timeout: (int) timeout for io operations + @cvar BufferSize: (int) buffer size for io operations (must be> 0) + + @note: implement this class to read / write messages from any device via L{IOHandler} + """ Timeout = 0 BufferSize = 4096 - def __init__(self, ): - pass + 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 + + @return: always None + @raise L{IOConnectFailed}: in case something goes wrong + """ raise IOConnectFailed('Failed') def read(self, n): + """Should read n bytes from the device + + @return: always None + @raise L{IOBroken}: in case something goes wrong + @raise L{IOTimeout}: if the read operation times out + """ raise IOBroken('Broken') def write(self, bytes): + """Should write bytes to the device + + @return: always None + @raise L{IOBroken}: in case something goes wrong + """ raise IOBroken('Broken') def close(self): + """Should close the io device + + @return: always None + @raise L{IOClosed}: if the device is already closed + """ raise IOClosed('Closed') def isOpen(self): + """Should check if the device is open + + @return: (bool) True if so, False otherwise + """ return False def setTimeout(self, n): + """Should set the timeout for io operations + + @return: always None + """ pass #***************************************************************************** # #***************************************************************************** -class SocketIO(IOObject): +class SocketIO(IOObjectBase): + """Handles message io over socket + """ + Timeout = 0.1 BufferSize = 4096 def __init__(self): self.socket = None - def connect(self, **kwargs): + def connect(self, host=None, port=None): + """Conects to socket + + @param host: (str) host to connect to + @param port: (int) port to use + """ + if self.isOpen(): self.close() self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) try: - self.socket.connect((kwargs['host'], kwargs['port'])) + self.socket.connect((host, port)) except socket.error, details: raise IOConnectFailed(details) @@ -123,25 +170,43 @@ # #***************************************************************************** class IOHandler(object): + """Handles message io + """ TerminatorEndMessage = '\nEndMessage\n' TerminatorData = '\nData\n' def __init__(self, ioPrototype=SocketIO): + """ + @paran ioPrototype: (L{IOObjectBase}) derrived class to handle message io + """ + self._ioPrototype = ioPrototype - self._log = logging.getLogger(consts.LoggerNames.ClientIOHandler) + self._log = logging.getLogger(consts.LoggerNames.IOHandler) self._receiveBuffer = '' self.io = None def connect(self, duration=20, timeout=0.5, **kwargs): + """Connect to the io device + + @return: (bool) True, if a connection could be established, False otherwise + @note: for details see L{iterConnect} + """ for result in self.iterConnect(duration=duration, timeout=timeout, **kwargs): pass return result def iterConnect(self, duration=20, timeout=0.5, **kwargs): + """Iterator to connect to the io device + @param duration: (int) how long should the handler try to connect to the device? + @param timeout: (int) how long dhould the handler wait in between connection attempts + @param kwargs: keyword arguments to pass to the contructor of the io object + + @return: (bool) True, if a connection could be established, False otherwise for the next attempt in turn + """ if not duration >= 0: raise ValueError('duration must be >= 0') if not timeout >= 0: @@ -175,6 +240,7 @@ def close(self): + """Closes the handler""" self._log.debug(consts.LogMessages.Closing) self._receiveBuffer = '' if self.io is not None and self.io.isOpen(): @@ -183,6 +249,9 @@ def isOpen(self): + """Checks if the io connection is open + @return: (bool) True if so, False otherwiese + """ if self.io is not None: return self.io.isOpen() return False @@ -209,7 +278,7 @@ def readMessage(self): - """Reads the next a message from io + """Reads the next message from io device @return: (Message) next message from the socket @note: if something goes wrong the according exception is raised @@ -301,12 +370,7 @@ @param data: data to atatch to the message @param params: {para-name: param-calue, ...} of parameters to pass along with the message (see freenet protocol) - @raise SocketError: if the socket connection to the node dies unexpectedly - If an error handler is passed to the client it is called emidiately before the error - is raised. - - @note: you can use this method to send a message to the node, bypassing all - track keeping methods of the client + @raise L{IOBroken}: if the connection to the io dies unexpectedly """ return self.sendMessageEx(message.Message(name, data=data, **params)) @@ -315,12 +379,7 @@ """Sends a message to freenet @param msg: (Message) message to send @return: Message - @raise SocketError: if the socket connection to the node dies unexpectedly. - If an error handler is passed to the client it is called emidiately before the error - is raised. - - @note: you can use this method to send a message to the node, bypassing all - track keeping methods of the client + @raise L{IOBroken}: if the connection to the io dies unexpectedly """ self._log.debug(consts.LogMessages.Sending + msg.pprint()) try: @@ -332,13 +391,16 @@ def setDebugVerbosity(self, debugVerbosity): + """Adjusts the debug verbosity. See L{consts.DebugVerbosity} + """ self._log.setLevel(debugVerbosity) def setIOPrototype(self, ioObject): + """Sets the io prototype to be used by the handler + + @note: if there is a current open connection, the connection is closed in the call """ - @note: if the connection is open the connection is closed in the call - """ if self.isOpen(): self.close() This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jU...@us...> - 2008-03-07 09:55:09
|
Revision: 334 http://fclient.svn.sourceforge.net/fclient/?rev=334&view=rev Author: jUrner Date: 2008-03-07 01:55:12 -0800 (Fri, 07 Mar 2008) Log Message: ----------- fixed a critical that could hang io forever Modified Paths: -------------- trunk/sandbox/fcp2/iohandler.py Modified: trunk/sandbox/fcp2/iohandler.py =================================================================== --- trunk/sandbox/fcp2/iohandler.py 2008-03-07 09:54:27 UTC (rev 333) +++ trunk/sandbox/fcp2/iohandler.py 2008-03-07 09:55:12 UTC (rev 334) @@ -347,7 +347,11 @@ if isClientPutComplexDir: n = clientPutComplexDirDataLength else: - n = msg['DataLength'] + # 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 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. |
From: <jU...@us...> - 2008-03-08 11:11:53
|
Revision: 338 http://fclient.svn.sourceforge.net/fclient/?rev=338&view=rev Author: jUrner Date: 2008-03-08 03:11:57 -0800 (Sat, 08 Mar 2008) Log Message: ----------- adapt to new message handling Modified Paths: -------------- trunk/sandbox/fcp2/iohandler.py Modified: trunk/sandbox/fcp2/iohandler.py =================================================================== --- trunk/sandbox/fcp2/iohandler.py 2008-03-08 11:10:20 UTC (rev 337) +++ trunk/sandbox/fcp2/iohandler.py 2008-03-08 11:11:57 UTC (rev 338) @@ -181,13 +181,13 @@ """ @paran ioPrototype: (L{IOObjectBase}) derrived class to handle message io """ - self._ioPrototype = ioPrototype self._log = logging.getLogger(consts.LoggerNames.IOHandler) self._receiveBuffer = '' - self.io = None - + self.io = None + + def connect(self, duration=20, timeout=0.5, **kwargs): """Connect to the io device @@ -313,9 +313,13 @@ if not p: raise MessageParseError('Missing message name') msgName = p.pop(0) - msg = message.Message(msgName) - paramTypes = types.MessageParamTypes.get(msgName, None) - + 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 @@ -327,12 +331,13 @@ paramName, sep, paramValue = line.partition('=') # covert fcp to python value if necessary - if paramTypes is not None: - paramType = paramTypes.get(paramName, None) - if paramType is not None: - paramValue = paramType.fcpToPython(paramValue) + 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('.') This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jU...@us...> - 2008-03-09 12:53:43
|
Revision: 348 http://fclient.svn.sourceforge.net/fclient/?rev=348&view=rev Author: jUrner Date: 2008-03-09 05:53:45 -0700 (Sun, 09 Mar 2008) Log Message: ----------- logging and python like style handling Modified Paths: -------------- trunk/sandbox/fcp2/iohandler.py Modified: trunk/sandbox/fcp2/iohandler.py =================================================================== --- trunk/sandbox/fcp2/iohandler.py 2008-03-09 12:28:33 UTC (rev 347) +++ trunk/sandbox/fcp2/iohandler.py 2008-03-09 12:53:45 UTC (rev 348) @@ -1,9 +1,14 @@ +"""Message io handling +The module can be used to handle reading and writing of messages io from sockeet, file or whatever + +""" import os, sys import logging import socket import time +import traceback #--> rel import hack @@ -211,15 +216,15 @@ raise ValueError('duration must be >= 0') if not timeout >= 0: raise ValueError('timeout must be >= 0') - - if self.isOpen(): - self.close() timeElapsed = 0 while timeElapsed <= duration: + if self.isOpen(): + self.close() self._log.info(consts.LogMessages.Connecting + ' %r' % kwargs) - self.io = self._ioPrototype() + self.io = self._ioPrototype(**kwargs) + yield False # have to yield at least once to make unittests work (io has to be created!!) try: self.io.connect(**kwargs) except IOConnectFailed, details: @@ -243,7 +248,7 @@ """Closes the handler""" self._log.debug(consts.LogMessages.Closing) self._receiveBuffer = '' - if self.io is not None and self.io.isOpen(): + if self.io is not None: self.io.close() self.io = None @@ -269,12 +274,16 @@ raise ValueError('No bytes received and IO did not raise as expected?!?') self._receiveBuffer += p except IOBroken, details: + self._log.critical(consts.LogMessages.SocketDied) self.close() - self._log.critical(consts.LogMessages.SocketDied) - return IOBroken, details + raise IOBroken(details) except IOTimeout, details: # nothing in the queue - return IOTimeout, details - return None, None + raise IOTimeout(details) + except Exception, details: + self._log.critical(consts.LogMessages.CaughtException + '\n' + traceback.traceback.format_exc()) + self.close() + raise Exception(details) + def readMessage(self): @@ -302,10 +311,8 @@ eof += len(self.TerminatorData) hasData = True if eof < 0: - exception, details = self.readBytes(self.io.BufferSize) - if exception is not None: - raise exception(details) - + self.readBytes(self.io.BufferSize) + # prep message chunk, self._receiveBuffer = self._receiveBuffer[ :eof], self._receiveBuffer[eof: ] p = [i for i in chunk.split('\n') if i] # Fcp ignores empty lines, so do we @@ -362,13 +369,12 @@ if len(self._receiveBuffer) >= n: msg.data, self._receiveBuffer = self._receiveBuffer[ :n], self._receiveBuffer[n: ] break - - exception, details = self.readBytes(self.io.BufferSize) - if exception == IOTimeout: # try again later + try: + self.readBytes(self.io.BufferSize) + except IOTimeout, details: # try again later self._receiveBuffer = chunk + self._receiveBuffer - elif exception is not None: - raise exception(details) - + raise IOTimeout(details) + self._log.debug(consts.LogMessages.Received + msg.pprint()) return msg @@ -394,9 +400,13 @@ try: self.io.write(msg.toString()) except IOBroken, details: + self._log.critical(consts.LogMessages.SocketDied) self.close() - self._log.critical(consts.LogMessages.SocketDied) raise IOBroken(details) + except Exception, details: + self._log.critical(consts.LogMessages.CaughtException + '\n' + traceback.traceback.format_exc()) + self.close() + raise Exception(details) def setDebugVerbosity(self, debugVerbosity): This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
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. |
From: <jU...@us...> - 2008-03-11 01:02:24
|
Revision: 358 http://fclient.svn.sourceforge.net/fclient/?rev=358&view=rev Author: jUrner Date: 2008-03-10 18:02:27 -0700 (Mon, 10 Mar 2008) Log Message: ----------- moved exceptions ti IOHandler for easier access Modified Paths: -------------- trunk/sandbox/fcp2/iohandler.py Modified: trunk/sandbox/fcp2/iohandler.py =================================================================== --- trunk/sandbox/fcp2/iohandler.py 2008-03-11 01:01:33 UTC (rev 357) +++ trunk/sandbox/fcp2/iohandler.py 2008-03-11 01:02:27 UTC (rev 358) @@ -32,22 +32,6 @@ #***************************************************************************** # #***************************************************************************** -class MessageParseError(Exception): - """Exception raised when a message could not be parsed succesfuly""" - -class IOConnectFailed(Exception): - """Exception raised if the object can not be connected""" - -class IOClosed(Exception): - """Exception raised if the object is closed""" - -class IOBroken(Exception): - """Exception raised if the IO connection is broken""" - -class IOTimeout(Exception): - """Exception raised when the io connection is closed""" - - class IOObjectBase(object): """Base class for io objects @@ -70,7 +54,7 @@ @return: always None @raise L{IOConnectFailed}: in case something goes wrong """ - raise IOConnectFailed('Failed') + raise IOHandler.IOConnectFailed('Failed') def read(self, n): """Should read n bytes from the device @@ -79,7 +63,7 @@ @raise L{IOBroken}: in case something goes wrong @raise L{IOTimeout}: if the read operation times out """ - raise IOBroken('Broken') + raise OHandler.IOBroken('Broken') def write(self, bytes): """Should write bytes to the device @@ -87,7 +71,7 @@ @return: always None @raise L{IOBroken}: in case something goes wrong """ - raise IOBroken('Broken') + raise OHandler.IOBroken('Broken') def close(self): """Should close the io device @@ -95,7 +79,7 @@ @return: always None @raise L{IOClosed}: if the device is already closed """ - raise IOClosed('Closed') + raise OHandler.IOClosed('Closed') def isOpen(self): """Should check if the device is open @@ -137,7 +121,7 @@ try: self.socket.connect((host, port)) except socket.error, details: - raise IOConnectFailed(details) + raise IOHandler.IOConnectFailed(details) def read(self, n): try: @@ -145,10 +129,10 @@ if p == '': raise socket.error('Socket closed by host') except socket.timeout, details: - raise IOTimeout(details) + raise IOHandler.IOTimeout(details) except socket.error, details: self.close() - raise IOBroken(details) + raise IOHandler.IOBroken(details) else: return p @@ -157,11 +141,11 @@ self.socket.sendall(bytes) except socket.error, details: self.close() - raise IOBroken(details) + raise IOHandler.IOBroken(details) def close(self): if self.socket is None: - raise IOClosed('Closed') + raise IOHandler.IOClosed('Closed') self.socket.close() self.socket = None @@ -178,6 +162,23 @@ """Handles message io """ + class MessageParseError(Exception): + """Exception raised when a message could not be parsed succesfuly""" + + class IOConnectFailed(Exception): + """Exception raised if the object can not be connected""" + + class IOClosed(Exception): + """Exception raised if the object is closed""" + + class IOBroken(Exception): + """Exception raised if the IO connection is broken""" + + class IOTimeout(Exception): + """Exception raised when the io connection is closed""" + + + TerminatorEndMessage = '\nEndMessage\n' TerminatorData = '\nData\n' @@ -227,8 +228,8 @@ yield False # have to yield at least once to make unittests work (io has to be created!!) try: self.io.connect(**kwargs) - except IOConnectFailed, details: - self._log.info(consts.LogMessages.ConnectingFailed + ' %s %s' % (IOConnectFailed, details)) + except self.IOConnectFailed, details: + self._log.info(consts.LogMessages.ConnectingFailed + ' %s %s' % (self.IOConnectFailed, details)) yield False else: self.io.setTimeout(self.io.Timeout) @@ -273,14 +274,14 @@ if not p: raise ValueError('No bytes received and IO did not raise as expected?!?') self._receiveBuffer += p - except IOBroken, details: + except self.IOBroken, details: self._log.critical(consts.LogMessages.SocketDied) self.close() - raise IOBroken(details) - except IOTimeout, details: # nothing in the queue - raise IOTimeout(details) + raise self.IOBroken(details) + except self.IOTimeout, details: # nothing in the queue + raise self.IOTimeout(details) except Exception, details: - self._log.critical(consts.LogMessages.CaughtException + '\n' + traceback.traceback.format_exc()) + self._log.critical(consts.LogMessages.CaughtException + '\n' + traceback.format_exc()) self.close() raise Exception(details) @@ -317,7 +318,7 @@ p = [i for i in chunk.split('\n') if i] # Fcp ignores empty lines, so do we p.pop() if not p: - raise MessageParseError('No message name present') + raise self.MessageParseError('No message name present') msgName = p.pop(0) msgClass = message.MessagesAll.get(msgName, None) if msgClass is None: @@ -328,7 +329,7 @@ # process param --> value fields params = dict([line.split('=', 1) for line in p]) if not msg._restoreParams(params): - raise MessageParseError('Invalid message parameters') + raise self.MessageParseError('Invalid message parameters') # get associated data if necessary if mayHaveData: @@ -351,19 +352,8 @@ return msg - def sendMessage(self, name, data=None, **params): + def sendMessage(self, msg): """Sends a message to freenet - @param name: name of the message to send - @param data: data to atatch to the message - @param params: {para-name: param-calue, ...} of parameters to pass along - with the message (see freenet protocol) - @raise L{IOBroken}: if the connection to the io dies unexpectedly - """ - return self.sendMessageEx(message.Message(name, data=data, **params)) - - - def sendMessageEx(self, msg): - """Sends a message to freenet @param msg: (Message) message to send @return: Message @raise L{IOBroken}: if the connection to the io dies unexpectedly @@ -371,12 +361,12 @@ self._log.debug(consts.LogMessages.Sending + msg.pprint()) try: self.io.write(msg.toString()) - except IOBroken, details: + except self.IOBroken, details: self._log.critical(consts.LogMessages.SocketDied) self.close() - raise IOBroken(details) + raise self.IOBroken(details) except Exception, details: - self._log.critical(consts.LogMessages.CaughtException + '\n' + traceback.traceback.format_exc()) + self._log.critical(consts.LogMessages.CaughtException + '\n' + traceback.format_exc()) self.close() raise Exception(details) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jU...@us...> - 2008-04-08 10:06:41
|
Revision: 371 http://fclient.svn.sourceforge.net/fclient/?rev=371&view=rev Author: jUrner Date: 2008-04-08 03:06:09 -0700 (Tue, 08 Apr 2008) Log Message: ----------- some fixes Modified Paths: -------------- trunk/sandbox/fcp2/iohandler.py Modified: trunk/sandbox/fcp2/iohandler.py =================================================================== --- trunk/sandbox/fcp2/iohandler.py 2008-04-08 10:05:01 UTC (rev 370) +++ trunk/sandbox/fcp2/iohandler.py 2008-04-08 10:06:09 UTC (rev 371) @@ -11,7 +11,7 @@ import traceback -#--> rel import hack +#--> rel import hack, so we don't have to put the package on sys.path class _RelImportHack(object): def __init__(self, n): fpath = os.path.abspath(__file__) @@ -138,7 +138,10 @@ def write(self, bytes): try: - self.socket.sendall(bytes) + totalSend = 0 + while totalSend < len(bytes): + n = self.io.write(bytes[totalSend: ]) + totalSend += n except socket.error, details: self.close() raise IOHandler.IOBroken(details) @@ -225,6 +228,7 @@ self._log.info(consts.LogMessages.Connecting + ' %r' % kwargs) self.io = self._ioPrototype() + self.io.setTimeout(self.io.Timeout) yield False # have to yield at least once to make unittests work (io has to be created!!) try: self.io.connect(**kwargs) @@ -232,7 +236,6 @@ self._log.info(consts.LogMessages.ConnectingFailed + ' %s %s' % (self.IOConnectFailed, details)) yield False else: - self.io.setTimeout(self.io.Timeout) self._log.info(consts.LogMessages.Connected) yield True break This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jU...@us...> - 2008-04-08 21:43:52
|
Revision: 377 http://fclient.svn.sourceforge.net/fclient/?rev=377&view=rev Author: jUrner Date: 2008-04-08 14:43:58 -0700 (Tue, 08 Apr 2008) Log Message: ----------- socket io was broken. fixed Modified Paths: -------------- trunk/sandbox/fcp2/iohandler.py Modified: trunk/sandbox/fcp2/iohandler.py =================================================================== --- trunk/sandbox/fcp2/iohandler.py 2008-04-08 10:12:57 UTC (rev 376) +++ trunk/sandbox/fcp2/iohandler.py 2008-04-08 21:43:58 UTC (rev 377) @@ -114,10 +114,10 @@ @param host: (str) host to connect to @param port: (int) port to use """ - if self.isOpen(): self.close() self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + self.socket.settimeout(self.Timeout) try: self.socket.connect((host, port)) except socket.error, details: @@ -140,7 +140,7 @@ try: totalSend = 0 while totalSend < len(bytes): - n = self.io.write(bytes[totalSend: ]) + n = self.socket.send(bytes[totalSend: ]) totalSend += n except socket.error, details: self.close() @@ -228,7 +228,6 @@ self._log.info(consts.LogMessages.Connecting + ' %r' % kwargs) self.io = self._ioPrototype() - self.io.setTimeout(self.io.Timeout) yield False # have to yield at least once to make unittests work (io has to be created!!) try: self.io.connect(**kwargs) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jU...@us...> - 2008-04-09 07:31:43
|
Revision: 380 http://fclient.svn.sourceforge.net/fclient/?rev=380&view=rev Author: jUrner Date: 2008-04-09 00:31:51 -0700 (Wed, 09 Apr 2008) Log Message: ----------- moved errors and loggers to consts for easier access Modified Paths: -------------- trunk/sandbox/fcp2/iohandler.py Modified: trunk/sandbox/fcp2/iohandler.py =================================================================== --- trunk/sandbox/fcp2/iohandler.py 2008-04-09 07:31:36 UTC (rev 379) +++ trunk/sandbox/fcp2/iohandler.py 2008-04-09 07:31:51 UTC (rev 380) @@ -54,7 +54,7 @@ @return: always None @raise L{IOConnectFailed}: in case something goes wrong """ - raise IOHandler.IOConnectFailed('Failed') + raise consts.IOConnectFailedError('Failed', consts.Logger.IO.error) def read(self, n): """Should read n bytes from the device @@ -63,7 +63,7 @@ @raise L{IOBroken}: in case something goes wrong @raise L{IOTimeout}: if the read operation times out """ - raise OHandler.IOBroken('Broken') + raise consts.IOBrokenError('Broken', consts.Logger.IO.error) def write(self, bytes): """Should write bytes to the device @@ -71,7 +71,7 @@ @return: always None @raise L{IOBroken}: in case something goes wrong """ - raise OHandler.IOBroken('Broken') + raise consts.IOBrokenError('Broken', consts.Logger.IO.error) def close(self): """Should close the io device @@ -79,7 +79,7 @@ @return: always None @raise L{IOClosed}: if the device is already closed """ - raise OHandler.IOClosed('Closed') + raise consts.IOClosedError('Closed', consts.Logger.IO.error) def isOpen(self): """Should check if the device is open @@ -121,7 +121,7 @@ try: self.socket.connect((host, port)) except socket.error, details: - raise IOHandler.IOConnectFailed(details) + raise consts.IOConnectFailedError(details, consts.Logger.IO.error) def read(self, n): try: @@ -129,10 +129,10 @@ if p == '': raise socket.error('Socket closed by host') except socket.timeout, details: - raise IOHandler.IOTimeout(details) + raise consts.IOTimeoutError(details, consts.Logger.IO.error) except socket.error, details: self.close() - raise IOHandler.IOBroken(details) + raise consts.IOBrokenError(details, consts.Logger.IO.error) else: return p @@ -144,11 +144,11 @@ totalSend += n except socket.error, details: self.close() - raise IOHandler.IOBroken(details) + raise consts.IOBrokenError(details, consts.Logger.IO.error) def close(self): if self.socket is None: - raise IOHandler.IOClosed('Closed') + raise consts.IOClosedError('Closed', consts.Logger.IO.error) self.socket.close() self.socket = None @@ -165,23 +165,6 @@ """Handles message io """ - class MessageParseError(Exception): - """Exception raised when a message could not be parsed succesfuly""" - - class IOConnectFailed(Exception): - """Exception raised if the object can not be connected""" - - class IOClosed(Exception): - """Exception raised if the object is closed""" - - class IOBroken(Exception): - """Exception raised if the IO connection is broken""" - - class IOTimeout(Exception): - """Exception raised when the io connection is closed""" - - - TerminatorEndMessage = '\nEndMessage\n' TerminatorData = '\nData\n' @@ -191,7 +174,6 @@ @paran ioPrototype: (L{IOObjectBase}) derrived class to handle message io """ self._ioPrototype = ioPrototype - self._log = logging.getLogger(consts.LoggerNames.IOHandler) self._receiveBuffer = '' self.io = None @@ -226,21 +208,21 @@ if self.isOpen(): self.close() - self._log.info(consts.LogMessages.Connecting + ' %r' % kwargs) + consts.Logger.IOHandler.info(consts.LogMessages.Connecting + ' %r' % 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) - except self.IOConnectFailed, details: - self._log.info(consts.LogMessages.ConnectingFailed + ' %s %s' % (self.IOConnectFailed, details)) + except consts.IOConnectFailedError, details: + consts.Logger.IOHandler.info(consts.LogMessages.ConnectingFailed + ' (%s)' % details) yield False else: - self._log.info(consts.LogMessages.Connected) + consts.Logger.IOHandler.info(consts.LogMessages.Connected) yield True break # continue polling - self._log.info(consts.LogMessages.Retry) + consts.Logger.IOHandler.info(consts.LogMessages.Retry) timeElapsed += timeout time.sleep(timeout) @@ -249,7 +231,7 @@ def close(self): """Closes the handler""" - self._log.debug(consts.LogMessages.Closing) + consts.Logger.IOHandler.debug(consts.LogMessages.Closing) self._receiveBuffer = '' if self.io is not None: self.io.close() @@ -273,21 +255,12 @@ try: #TODO: if \r\n is possible in Fcp, replace it by \n p = self.io.read(n) - if not p: - raise ValueError('No bytes received and IO did not raise as expected?!?') + assert p, 'No bytes received and IO did not raise as expected?!?' self._receiveBuffer += p - except self.IOBroken, details: - self._log.critical(consts.LogMessages.SocketDied) - self.close() - raise self.IOBroken(details) - except self.IOTimeout, details: # nothing in the queue - raise self.IOTimeout(details) - except Exception, details: - self._log.critical(consts.LogMessages.CaughtException + '\n' + traceback.format_exc()) - self.close() - raise Exception(details) + except consts.IOTimeoutError, details: # nothing in queue + raise consts.IOTimeoutError(details) + - def readMessage(self): """Reads the next message from io device @return: (Message) next message from the socket @@ -324,14 +297,14 @@ msgName = p.pop(0) msgClass = message.MessagesAll.get(msgName, None) if msgClass is None: - self._log.debug(consts.LogMessages.CreatingNewMessageType + ' "%s"' % msgClassname) + consts.Logger.IOHandler.debug(consts.LogMessages.CreatingNewMessageType + ' "%s"' % msgClassname) msgClass = message.newMessageType(msgName) msg = msgClass() # process param --> value fields params = dict([line.split('=', 1) for line in p]) if not msg._restoreParams(params): - raise self.MessageParseError('Invalid message parameters') + raise consts.MessageParseError('Invalid message parameters: ' + msg.pprint(), consts.Logger.IOHandler.error) # get associated data if necessary if mayHaveData: @@ -350,7 +323,7 @@ self._receiveBuffer = chunk + self._receiveBuffer raise IOTimeout(details) - self._log.debug(consts.LogMessages.Received + msg.pprint()) + consts.Logger.IOHandler.debug(consts.LogMessages.Received + msg.pprint()) return msg @@ -360,25 +333,10 @@ @return: Message @raise L{IOBroken}: if the connection to the io dies unexpectedly """ - self._log.debug(consts.LogMessages.Sending + msg.pprint()) - try: - self.io.write(msg.toString()) - except self.IOBroken, details: - self._log.critical(consts.LogMessages.SocketDied) - self.close() - raise self.IOBroken(details) - except Exception, details: - self._log.critical(consts.LogMessages.CaughtException + '\n' + traceback.format_exc()) - self.close() - raise Exception(details) - + consts.Logger.IOHandler.debug(consts.LogMessages.Sending + msg.pprint()) + self.io.write(msg.toString()) - def setDebugVerbosity(self, debugVerbosity): - """Adjusts the debug verbosity. See L{consts.DebugVerbosity} - """ - self._log.setLevel(debugVerbosity) - - + def setIOPrototype(self, ioObject): """Sets the io prototype to be used by the handler This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jU...@us...> - 2008-04-09 07:35:10
|
Revision: 383 http://fclient.svn.sourceforge.net/fclient/?rev=383&view=rev Author: jUrner Date: 2008-04-09 00:35:09 -0700 (Wed, 09 Apr 2008) Log Message: ----------- adapt docs Modified Paths: -------------- trunk/sandbox/fcp2/iohandler.py Modified: trunk/sandbox/fcp2/iohandler.py =================================================================== --- trunk/sandbox/fcp2/iohandler.py 2008-04-09 07:32:18 UTC (rev 382) +++ trunk/sandbox/fcp2/iohandler.py 2008-04-09 07:35:09 UTC (rev 383) @@ -60,8 +60,8 @@ """Should read n bytes from the device @return: always None - @raise L{IOBroken}: in case something goes wrong - @raise L{IOTimeout}: if the read operation times out + @raise L{consts.IOBrokenError}: in case something goes wrong + @raise L{consts.IOTimeoutError}: if the read operation times out """ raise consts.IOBrokenError('Broken', consts.Logger.IO.error) @@ -69,7 +69,7 @@ """Should write bytes to the device @return: always None - @raise L{IOBroken}: in case something goes wrong + @raise L{consts.IOBrokenError}: in case something goes wrong """ raise consts.IOBrokenError('Broken', consts.Logger.IO.error) @@ -77,7 +77,7 @@ """Should close the io device @return: always None - @raise L{IOClosed}: if the device is already closed + @raise L{consts.IOClosedError}: if the device is already closed """ raise consts.IOClosedError('Closed', consts.Logger.IO.error) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jU...@us...> - 2008-04-09 07:45:28
|
Revision: 387 http://fclient.svn.sourceforge.net/fclient/?rev=387&view=rev Author: jUrner Date: 2008-04-09 00:45:33 -0700 (Wed, 09 Apr 2008) Log Message: ----------- moved more logging stuff to consts Modified Paths: -------------- trunk/sandbox/fcp2/iohandler.py Modified: trunk/sandbox/fcp2/iohandler.py =================================================================== --- trunk/sandbox/fcp2/iohandler.py 2008-04-09 07:45:07 UTC (rev 386) +++ trunk/sandbox/fcp2/iohandler.py 2008-04-09 07:45:33 UTC (rev 387) @@ -8,7 +8,6 @@ import logging import socket import time -import traceback #--> rel import hack, so we don't have to put the package on sys.path @@ -26,9 +25,6 @@ del hack #<-- rel import hack - -logging.basicConfig(stream=sys.stdout, level=logging.DEBUG) -logging.addLevelName(consts.DebugVerbosity.Quiet, '') #***************************************************************************** # #***************************************************************************** This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jU...@us...> - 2008-04-09 22:33:34
|
Revision: 397 http://fclient.svn.sourceforge.net/fclient/?rev=397&view=rev Author: jUrner Date: 2008-04-09 14:46:20 -0700 (Wed, 09 Apr 2008) Log Message: ----------- fixed docs Modified Paths: -------------- trunk/sandbox/fcp2/iohandler.py Modified: trunk/sandbox/fcp2/iohandler.py =================================================================== --- trunk/sandbox/fcp2/iohandler.py 2008-04-09 21:46:05 UTC (rev 396) +++ trunk/sandbox/fcp2/iohandler.py 2008-04-09 21:46:20 UTC (rev 397) @@ -48,7 +48,7 @@ @param kwargs: any additional keyword arguments passed to L{IOHandler.connect} @return: always None - @raise L{IOConnectFailed}: in case something goes wrong + @raise L{consts.IOConnectFailedError}: in case something goes wrong """ raise consts.IOConnectFailedError('Failed', consts.Logger.IO.error) @@ -167,7 +167,7 @@ def __init__(self, ioPrototype=SocketIO): """ - @paran ioPrototype: (L{IOObjectBase}) derrived class to handle message io + @param ioPrototype: (L{IOObjectBase}) derrived class to handle message io """ self._ioPrototype = ioPrototype self._receiveBuffer = '' @@ -327,7 +327,7 @@ """Sends a message to freenet @param msg: (Message) message to send @return: Message - @raise L{IOBroken}: if the connection to the io dies unexpectedly + @raise L{consts.IOBrokenError}: if the connection to the io dies unexpectedly """ consts.Logger.IOHandler.debug(consts.LogMessages.Sending + msg.pprint()) self.io.write(msg.toString()) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jU...@us...> - 2008-05-05 07:59:29
|
Revision: 401 http://fclient.svn.sourceforge.net/fclient/?rev=401&view=rev Author: jUrner Date: 2008-05-05 00:59:34 -0700 (Mon, 05 May 2008) Log Message: ----------- adjusted debug level Modified Paths: -------------- trunk/sandbox/fcp2/iohandler.py Modified: trunk/sandbox/fcp2/iohandler.py =================================================================== --- trunk/sandbox/fcp2/iohandler.py 2008-05-05 07:58:55 UTC (rev 400) +++ trunk/sandbox/fcp2/iohandler.py 2008-05-05 07:59:34 UTC (rev 401) @@ -125,7 +125,7 @@ if p == '': raise socket.error('Socket closed by host') except socket.timeout, details: - raise consts.IOTimeoutError(details, consts.Logger.IO.error) + raise consts.IOTimeoutError(details, consts.Logger.IO.debug) except socket.error, details: self.close() raise consts.IOBrokenError(details, consts.Logger.IO.error) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jU...@us...> - 2008-06-29 15:19:21
|
Revision: 427 http://fclient.svn.sourceforge.net/fclient/?rev=427&view=rev Author: jUrner Date: 2008-06-29 08:19:30 -0700 (Sun, 29 Jun 2008) Log Message: ----------- logging Modified Paths: -------------- trunk/sandbox/fcp2/iohandler.py Modified: trunk/sandbox/fcp2/iohandler.py =================================================================== --- trunk/sandbox/fcp2/iohandler.py 2008-06-29 15:19:20 UTC (rev 426) +++ trunk/sandbox/fcp2/iohandler.py 2008-06-29 15:19:30 UTC (rev 427) @@ -125,7 +125,7 @@ if p == '': raise socket.error('Socket closed by host') except socket.timeout, details: - raise consts.IOTimeoutError(details, consts.Logger.IO.debug) + raise consts.IOTimeoutError(details, consts.Logger.IO.log, consts.DebugVerbosity.Chatty) except socket.error, details: self.close() raise consts.IOBrokenError(details, consts.Logger.IO.error) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |