SF.net SVN: fclient: [357] trunk/sandbox/fcp2/client.py
Status: Pre-Alpha
Brought to you by:
jurner
|
From: <jU...@us...> - 2008-03-11 01:01:28
|
Revision: 357
http://fclient.svn.sourceforge.net/fclient/?rev=357&view=rev
Author: jUrner
Date: 2008-03-10 18:01:33 -0700 (Mon, 10 Mar 2008)
Log Message:
-----------
a few fixes
Modified Paths:
--------------
trunk/sandbox/fcp2/client.py
Modified: trunk/sandbox/fcp2/client.py
===================================================================
--- trunk/sandbox/fcp2/client.py 2008-03-10 13:03:53 UTC (rev 356)
+++ trunk/sandbox/fcp2/client.py 2008-03-11 01:01:33 UTC (rev 357)
@@ -206,7 +206,6 @@
from fcp2 import consts
from fcp2 import config
from fcp2 import events
-from fcp2 import fcparams
from fcp2 import message
from fcp2 import iohandler
from fcp2 import types
@@ -254,7 +253,6 @@
consts = consts
config = config
message = message
- fcparams = fcparams
types = types
key = key
@@ -529,14 +527,14 @@
self._close(disconnectMsg)
raise StopIteration
-
+ #TESTED
def getConnectionName(self):
"""Returns the connection name used by the client
@return: (str) connection name
"""
return self._connectionName
-
-
+
+ #TESTED
def setConnectionName(self, connectionName=None):
"""Sets the connection name to be used by the client
@param connectionName: (str) connection name or None to use an arbitrary connection name
@@ -544,17 +542,26 @@
"""
self._connectionName = self._newUuid() if connectionName is None else connectionName
return self._connectionName
+
+ #TESTED
+ def getDebugVerbosity(self):
+ """Returns the current verbosity level of the client
+ @return: L{consts.DebugVerbosity}
+ """
+ for logger in self._loggers.values():
+ return logger.getEffectiveLevel()
-
+ #TESTED
def setDebugVerbosity(self, debugVerbosity):
"""Sets the verbosity level of the client
- @note: see L{consts.DebugVerbosity}
+ @param debugVerbosity: L{consts.DebugVerbosity}
"""
for logger in self._loggers.values():
logger.setLevel(debugVerbosity)
self.ioHandler.setDebugVerbosity(debugVerbosity)
+ #TESTED
def startNode(self, cmdline):
"""Starts the freenet node
@param cmdline: commandline to start freenet (like '/freenet/run.sh start' or 'c:\freenet\start.bat')
@@ -571,7 +578,7 @@
stdout, stderr = p.communicate()
return stdout
-
+ #TESTED
def versionCheckNodeHello(self, nodeHelloMessage):
"""Performa a version check of the client against the specified NodeHello message
@return: (bool) True if version is ok, False otherwise
@@ -588,13 +595,14 @@
## runtime related methods
##
#########################################################
+ #TESTED
def handleMessage(self, msg):
"""Handles a message from the freenet node
@param msg: (Message) to handle
@return: True if the message was handled, False otherwise
"""
- CancelPersistentRequests = 0 # for testing... if True, cancels all PersistentRequests
+ CancelPersistentRequests = 1 # for testing... if True, cancels all PersistentRequests
# check if we have an initial request corrosponding to msg
requestIdentifier = msg.get('Identifier', None)
@@ -865,6 +873,15 @@
# unknown request... try to restore it
if initialRequest is None:
+ if CancelPersistentRequests:
+ self.sendMessage(
+ message.RemovePersistentRequest(
+ Identifier=msg['Identifier'],
+ Global=msg['Global'],
+ )
+ )
+ return True
+
#NOTE: there is no distinction between ClientPutDiskDir and ClientPutComplexDir
# so a bit of additional work here
requestType = msg['RequestType']
@@ -1095,7 +1112,7 @@
# default
return False
-
+ #TESTED
def next(self, dispatch=True):
"""Pumps the next message waiting
@param dispatch: if True the message is dispatched to L{handleMessage}
@@ -1104,22 +1121,22 @@
"""
try:
msg = self.ioHandler.readMessage()
- except iohandler.IOTimeout, details:
+ except self.ioHandler.IOTimeout, details:
msg = message.ClientSocketTimeout()
if dispatch:
self.events.Idle(msg)
- except iohandler.IOBroken, details:
+ except self.ioHandler.IOBroken, details:
msg = message.ClientDisconnected(
DisconnectReason=consts.DisconnectReason.ConnectionDied,
)
self._close(msg)
- raise iohandler.IOBroken(details)
+ raise self.ioHandler.IOBroken(details)
else:
if dispatch:
self.handleMessage(msg)
return msg
-
+ #TESTED
def run(self):
"""Runs the client unconditionally untill all requests have completed
@note: a KeyboardInterrupt will stop the client
@@ -1162,7 +1179,7 @@
if msg == message.ClientSocketDied:
break
-
+ #TESTED
def sendMessage(self, msg):
"""Sends a message to freenet
@param msg: (L{message.Message}) message to send
@@ -1178,19 +1195,20 @@
# if socket dies on sendall ther is no way to determine if and how much data was send
# ...so assume data was send, cos there is no way to proove it was not send
try:
- self.ioHandler.sendMessageEx(msg)
- except iohandler.IOBroken, details:
+ self.ioHandler.sendMessage(msg)
+ except self.ioHandler.IOBroken, details:
errorMsg = message.ClientDisconnected(
DisconnectReason=consts.DisconnectReason.ConnectionDied,
)
self._close(errorMsg)
- raise iohandler.IOBroken(details)
+ raise self.ioHandler.IOBroken(details)
#########################################################
##
## config related methods
##
#########################################################
+ #TESTED
def getConfig(self,
withCurrent=True,
withDefaults=True,
@@ -1218,6 +1236,7 @@
)
+ #TESTED
def modifyConfig(self, params):
"""Modifies node configuration values
@param params: (dict) containing parameters to modify
@@ -1225,8 +1244,7 @@
msg = message.ModifyConfig()
msg.params = params
self.sendMessage(msg)
-
-
+
########################################################
##
## ClientGet related methods
@@ -1573,7 +1591,6 @@
data = ''
for n, item in enumerate(items):
- n += 10
requestType = item.get('RequestType', None)
if requestType is None:
raise ValueError('No request type specified for item: %s' % n)
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|