Thread: SF.net SVN: fclient: [448] trunk/fcp2/src/fcp2/iohandler.py
Status: Pre-Alpha
Brought to you by:
jurner
|
From: <jU...@us...> - 2008-07-01 07:21:33
|
Revision: 448
http://fclient.svn.sourceforge.net/fclient/?rev=448&view=rev
Author: jUrner
Date: 2008-07-01 00:21:36 -0700 (Tue, 01 Jul 2008)
Log Message:
-----------
worked over exceptions
Modified Paths:
--------------
trunk/fcp2/src/fcp2/iohandler.py
Modified: trunk/fcp2/src/fcp2/iohandler.py
===================================================================
--- trunk/fcp2/src/fcp2/iohandler.py 2008-07-01 07:20:49 UTC (rev 447)
+++ trunk/fcp2/src/fcp2/iohandler.py 2008-07-01 07:21:36 UTC (rev 448)
@@ -251,7 +251,8 @@
try:
#TODO: if \r\n is possible in Fcp, replace it by \n
p = self.io.read(n)
- assert p, 'No bytes received and IO did not raise as expected?!?'
+ if not p:
+ raise RuntimeError('No bytes received and IO did not raise as expected?!?')
self._receiveBuffer += p
except consts.IOTimeoutError, details: # nothing in queue
raise consts.IOTimeoutError(details)
@@ -261,6 +262,10 @@
"""Reads the next message from io device
@return: (Message) next message from the socket
+ @raise IOBrokenError: (L{consts.IOBrokenError}) if the io breaks unexpectedly
+ @raise IOTimeoutError: (L{consts.IOTimeoutError}) if no message is in the io
+ @raise MessageParseError: (L{consts.IMessageParseError}) if the message is invalid
+
@note: if something goes wrong the according exception is raised
"""
# read message from io
@@ -294,7 +299,7 @@
msgClass = message.MessagesAll.get(msgName, None)
if msgClass is None:
consts.Logger.IOHandler.debug(consts.LogMessages.CreatingNewMessageType + ' "%s"' % msgClassname)
- msgClass = message.newMessageType(msgName)
+ msgClass = message.newMessageClass(msgName)
msg = msgClass()
# process param --> value fields
@@ -306,7 +311,7 @@
if mayHaveData:
n = msg._getDataLength()
if not isinstance(n, (int, long)):
- raise ValueError('DataLength must be type(int)')
+ raise consts.MessageParseError('DataLength must be type(int)')
if n > 0:
while self._receiveBuffer:
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jU...@us...> - 2008-07-01 08:03:18
|
Revision: 450
http://fclient.svn.sourceforge.net/fclient/?rev=450&view=rev
Author: jUrner
Date: 2008-07-01 01:03:27 -0700 (Tue, 01 Jul 2008)
Log Message:
-----------
added hack to handle persistents from other clients (kill them with fire ;-)
Modified Paths:
--------------
trunk/fcp2/src/fcp2/iohandler.py
Modified: trunk/fcp2/src/fcp2/iohandler.py
===================================================================
--- trunk/fcp2/src/fcp2/iohandler.py 2008-07-01 07:22:08 UTC (rev 449)
+++ trunk/fcp2/src/fcp2/iohandler.py 2008-07-01 08:03:27 UTC (rev 450)
@@ -258,8 +258,11 @@
raise consts.IOTimeoutError(details)
- def readMessage(self):
+ def readMessage(self, hackyInvalidMessageCallback=None):
"""Reads the next message from io device
+ @param hackyInvalidMessageCallback: in case a message drops in we can't handle this callback
+ will be called emidiately before raising, giving the caller a chance to do something about it.....
+
@return: (Message) next message from the socket
@raise IOBrokenError: (L{consts.IOBrokenError}) if the io breaks unexpectedly
@@ -305,12 +308,18 @@
# process param --> value fields
params = dict([line.split('=', 1) for line in p])
if not msg._restoreParams(params):
+ #HACK:
+ if hackyInvalidMessageCallback is not None:
+ hackyInvalidMessageCallback(msg)
raise consts.MessageParseError('Invalid message parameters: ' + msg.pprint(), consts.Logger.IOHandler.error)
# get associated data if necessary
if mayHaveData:
n = msg._getDataLength()
if not isinstance(n, (int, long)):
+ #HACK:
+ if hackyInvalidMessageCallback is not None:
+ ackyInvalidMessageCallback(msg)
raise consts.MessageParseError('DataLength must be type(int)')
if n > 0:
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jU...@us...> - 2008-07-01 11:27:20
|
Revision: 459
http://fclient.svn.sourceforge.net/fclient/?rev=459&view=rev
Author: jUrner
Date: 2008-07-01 04:27:28 -0700 (Tue, 01 Jul 2008)
Log Message:
-----------
for ease of use, all necessary symbols are now imported to main
Modified Paths:
--------------
trunk/fcp2/src/fcp2/iohandler.py
Modified: trunk/fcp2/src/fcp2/iohandler.py
===================================================================
--- trunk/fcp2/src/fcp2/iohandler.py 2008-07-01 11:27:21 UTC (rev 458)
+++ trunk/fcp2/src/fcp2/iohandler.py 2008-07-01 11:27:28 UTC (rev 459)
@@ -23,7 +23,7 @@
from fcp2 import message
from fcp2 import types
-del hack
+del hack, _RelImportHack
#<-- rel import hack
#*****************************************************************************
#
@@ -50,7 +50,7 @@
@return: always None
@raise L{consts.IOConnectFailedError}: in case something goes wrong
"""
- raise consts.IOConnectFailedError('Failed', consts.Logger.IO.error)
+ raise consts.ErrorIOConnectFailed('Failed', consts.ConstLogger.IO.error)
def read(self, n):
"""Should read n bytes from the device
@@ -59,7 +59,7 @@
@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)
+ raise consts.ErrorIOBroken('Broken', consts.ConstLogger.IO.error)
def write(self, bytes):
"""Should write bytes to the device
@@ -67,7 +67,7 @@
@return: always None
@raise L{consts.IOBrokenError}: in case something goes wrong
"""
- raise consts.IOBrokenError('Broken', consts.Logger.IO.error)
+ raise consts.ErrorIOBroken('Broken', consts.ConstLogger.IO.error)
def close(self):
"""Should close the io device
@@ -75,7 +75,7 @@
@return: always None
@raise L{consts.IOClosedError}: if the device is already closed
"""
- raise consts.IOClosedError('Closed', consts.Logger.IO.error)
+ raise consts.ErrorIOClosed('Closed', consts.ConstLogger.IO.error)
def isOpen(self):
"""Should check if the device is open
@@ -117,7 +117,7 @@
try:
self.socket.connect((host, port))
except socket.error, details:
- raise consts.IOConnectFailedError(details, consts.Logger.IO.error)
+ raise consts.ErrorIOConnectFailed(details, consts.ConstLogger.IO.error)
def read(self, n):
try:
@@ -125,10 +125,10 @@
if p == '':
raise socket.error('Socket closed by host')
except socket.timeout, details:
- raise consts.IOTimeoutError(details, consts.Logger.IO.log, consts.DebugVerbosity.Chatty)
+ raise consts.ErrorIOTimeout(details, consts.ConstLogger.IO.log, consts.DebugVerbosity.Chatty)
except socket.error, details:
self.close()
- raise consts.IOBrokenError(details, consts.Logger.IO.error)
+ raise consts.ErrorIOBroken(details, consts.ConstLogger.IO.error)
else:
return p
@@ -140,11 +140,11 @@
totalSend += n
except socket.error, details:
self.close()
- raise consts.IOBrokenError(details, consts.Logger.IO.error)
+ raise consts.ErrorIOBroken(details, consts.ConstLogger.IO.error)
def close(self):
if self.socket is None:
- raise consts.IOClosedError('Closed', consts.Logger.IO.error)
+ raise consts.ErrorIOClosed('Closed', consts.ConstLogger.IO.error)
self.socket.close()
self.socket = None
@@ -204,21 +204,21 @@
if self.isOpen():
self.close()
- consts.Logger.IOHandler.info(consts.LogMessages.Connecting + ' %r' % kwargs)
+ consts.ConstLogger.IOHandler.info(consts.ConstLogMessages.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 consts.IOConnectFailedError, details:
- consts.Logger.IOHandler.info(consts.LogMessages.ConnectingFailed + ' (%s)' % details)
+ except consts.ErrorIOConnectFailed, details:
+ consts.ConstLogger.IOHandler.info(consts.ConstLogMessages.ConnectingFailed + ' (%s)' % details)
yield False
else:
- consts.Logger.IOHandler.info(consts.LogMessages.Connected)
+ consts.ConstLogger.IOHandler.info(consts.ConstLogMessages.Connected)
yield True
break
# continue polling
- consts.Logger.IOHandler.info(consts.LogMessages.Retry)
+ consts.ConstLogger.IOHandler.info(consts.ConstLogMessages.Retry)
timeElapsed += timeout
time.sleep(timeout)
@@ -227,7 +227,7 @@
def close(self):
"""Closes the handler"""
- consts.Logger.IOHandler.debug(consts.LogMessages.Closing)
+ consts.ConstLogger.IOHandler.debug(consts.ConstLogMessages.Closing)
self._receiveBuffer = ''
if self.io is not None:
self.io.close()
@@ -254,8 +254,8 @@
if not p:
raise RuntimeError('No bytes received and IO did not raise as expected?!?')
self._receiveBuffer += p
- except consts.IOTimeoutError, details: # nothing in queue
- raise consts.IOTimeoutError(details)
+ except consts.ErrorIOTimeout, details: # nothing in queue
+ raise consts.ErrorIOTimeout(details)
def readMessage(self, hackyInvalidMessageCallback=None):
@@ -297,11 +297,11 @@
p = [i for i in chunk.split('\n') if i] # Fcp ignores empty lines, so do we
p.pop()
if not p:
- raise self.MessageParseError('No message name present')
+ raise self.ErrorMessageParse('No message name present')
msgName = p.pop(0)
msgClass = message.MessagesAll.get(msgName, None)
if msgClass is None:
- consts.Logger.IOHandler.debug(consts.LogMessages.CreatingNewMessageType + ' "%s"' % msgClassname)
+ consts.ConstLogger.IOHandler.debug(consts.ConstLogMessages.CreatingNewMessageType + ' "%s"' % msgClassname)
msgClass = message.newMessageClass(msgName)
msg = msgClass()
@@ -311,7 +311,7 @@
#HACK:
if hackyInvalidMessageCallback is not None:
hackyInvalidMessageCallback(msg)
- raise consts.MessageParseError('Invalid message parameters: ' + msg.pprint(), consts.Logger.IOHandler.error)
+ raise consts.ErrorMessageParse('Invalid message parameters: ' + msg.pprint(), consts.ConstLogger.IOHandler.error)
# get associated data if necessary
if mayHaveData:
@@ -320,7 +320,7 @@
#HACK:
if hackyInvalidMessageCallback is not None:
ackyInvalidMessageCallback(msg)
- raise consts.MessageParseError('DataLength must be type(int)')
+ raise consts.ErrorMessageParse('DataLength must be type(int)')
if n > 0:
while self._receiveBuffer:
@@ -329,11 +329,11 @@
break
try:
self.readBytes(self.io.BufferSize)
- except IOTimeout, details: # try again later
+ except ErrorIOTimeout, details: # try again later
self._receiveBuffer = chunk + self._receiveBuffer
- raise IOTimeout(details)
+ raise ErrorIOTimeout(details)
- consts.Logger.IOHandler.debug(consts.LogMessages.Received + msg.pprint())
+ consts.ConstLogger.IOHandler.debug(consts.ConstLogMessages.Received + msg.pprint())
return msg
@@ -343,7 +343,7 @@
@return: Message
@raise L{consts.IOBrokenError}: if the connection to the io dies unexpectedly
"""
- consts.Logger.IOHandler.debug(consts.LogMessages.Sending + msg.pprint())
+ consts.ConstLogger.IOHandler.debug(consts.ConstLogMessages.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-07-01 13:36:18
|
Revision: 472
http://fclient.svn.sourceforge.net/fclient/?rev=472&view=rev
Author: jUrner
Date: 2008-07-01 06:35:38 -0700 (Tue, 01 Jul 2008)
Log Message:
-----------
a few fixes
Modified Paths:
--------------
trunk/fcp2/src/fcp2/iohandler.py
Modified: trunk/fcp2/src/fcp2/iohandler.py
===================================================================
--- trunk/fcp2/src/fcp2/iohandler.py 2008-07-01 13:31:48 UTC (rev 471)
+++ trunk/fcp2/src/fcp2/iohandler.py 2008-07-01 13:35:38 UTC (rev 472)
@@ -125,7 +125,7 @@
if p == '':
raise socket.error('Socket closed by host')
except socket.timeout, details:
- raise consts.ErrorIOTimeout(details, consts.ConstLogger.IO.log, consts.DebugVerbosity.Chatty)
+ raise consts.ErrorIOTimeout(details, consts.ConstLogger.IO.log, consts.ConstDebugVerbosity.Chatty)
except socket.error, details:
self.close()
raise consts.ErrorIOBroken(details, consts.ConstLogger.IO.error)
@@ -301,7 +301,7 @@
msgName = p.pop(0)
msgClass = message.MessagesAll.get(msgName, None)
if msgClass is None:
- consts.ConstLogger.IOHandler.debug(consts.ConstLogMessages.CreatingNewMessageType + ' "%s"' % msgClassname)
+ consts.ConstLogger.IOHandler.debug(consts.ConstLogMessages.CreatingNewMessageType + ' "%s"' % msgName)
msgClass = message.newMessageClass(msgName)
msg = msgClass()
@@ -319,7 +319,7 @@
if not isinstance(n, (int, long)):
#HACK:
if hackyInvalidMessageCallback is not None:
- ackyInvalidMessageCallback(msg)
+ hackyInvalidMessageCallback(msg)
raise consts.ErrorMessageParse('DataLength must be type(int)')
if n > 0:
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jU...@us...> - 2008-07-02 07:05:09
|
Revision: 481
http://fclient.svn.sourceforge.net/fclient/?rev=481&view=rev
Author: jUrner
Date: 2008-07-02 00:05:11 -0700 (Wed, 02 Jul 2008)
Log Message:
-----------
fixed broken docstrings
Modified Paths:
--------------
trunk/fcp2/src/fcp2/iohandler.py
Modified: trunk/fcp2/src/fcp2/iohandler.py
===================================================================
--- trunk/fcp2/src/fcp2/iohandler.py 2008-07-02 07:05:02 UTC (rev 480)
+++ trunk/fcp2/src/fcp2/iohandler.py 2008-07-02 07:05:11 UTC (rev 481)
@@ -48,7 +48,7 @@
@param kwargs: any additional keyword arguments passed to L{IOHandler.connect}
@return: always None
- @raise L{consts.IOConnectFailedError}: in case something goes wrong
+ @raise L{consts.ErrorIOConnectFailed}: in case something goes wrong
"""
raise consts.ErrorIOConnectFailed('Failed', consts.ConstLogger.IO.error)
@@ -56,8 +56,8 @@
"""Should read n bytes from the device
@return: always None
- @raise L{consts.IOBrokenError}: in case something goes wrong
- @raise L{consts.IOTimeoutError}: if the read operation times out
+ @raise L{consts.ErrorIOBroken}: in case something goes wrong
+ @raise L{consts.ErrorIOTimeout}: if the read operation times out
"""
raise consts.ErrorIOBroken('Broken', consts.ConstLogger.IO.error)
@@ -65,7 +65,7 @@
"""Should write bytes to the device
@return: always None
- @raise L{consts.IOBrokenError}: in case something goes wrong
+ @raise L{consts.ErrorIOBroken}: in case something goes wrong
"""
raise consts.ErrorIOBroken('Broken', consts.ConstLogger.IO.error)
@@ -73,7 +73,7 @@
"""Should close the io device
@return: always None
- @raise L{consts.IOClosedError}: if the device is already closed
+ @raise L{consts.ErrorIOClosed}: if the device is already closed
"""
raise consts.ErrorIOClosed('Closed', consts.ConstLogger.IO.error)
@@ -265,9 +265,9 @@
@return: (Message) next message from the socket
- @raise IOBrokenError: (L{consts.IOBrokenError}) if the io breaks unexpectedly
- @raise IOTimeoutError: (L{consts.IOTimeoutError}) if no message is in the io
- @raise MessageParseError: (L{consts.IMessageParseError}) if the message is invalid
+ @raise IOBrokenError: (L{consts.ErrorIOBroken}) if the io breaks unexpectedly
+ @raise IOTimeoutError: (L{consts.ErrorIOTimeout}) if no message is in the io
+ @raise MessageParseError: (L{consts.ErrorMessageParse}) if the message is invalid
@note: if something goes wrong the according exception is raised
"""
@@ -341,7 +341,7 @@
"""Sends a message to freenet
@param msg: (Message) message to send
@return: Message
- @raise L{consts.IOBrokenError}: if the connection to the io dies unexpectedly
+ @raise L{consts.ErrorIOBroken}: if the connection to the io dies unexpectedly
"""
consts.ConstLogger.IOHandler.debug(consts.ConstLogMessages.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.
|