SF.net SVN: fclient: [455] trunk/fcp2/src/fcp2/client.py
Status: Pre-Alpha
Brought to you by:
jurner
|
From: <jU...@us...> - 2008-07-01 11:26:39
|
Revision: 455
http://fclient.svn.sourceforge.net/fclient/?rev=455&view=rev
Author: jUrner
Date: 2008-07-01 04:26:47 -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/client.py
Modified: trunk/fcp2/src/fcp2/client.py
===================================================================
--- trunk/fcp2/src/fcp2/client.py 2008-07-01 11:26:28 UTC (rev 454)
+++ trunk/fcp2/src/fcp2/client.py 2008-07-01 11:26:47 UTC (rev 455)
@@ -226,8 +226,10 @@
from fcp2.fcp_lib import uuid
-del hack
+del hack, _RelImportHack
#<-- rel import hack
+
+__all__ = ['Client', ]
#*************************************************************************************************
#
#*************************************************************************************************
@@ -257,11 +259,11 @@
MaxSizeKeyInfo = 32768
MinimumRunTime = 1 # FIX: 0001931
- consts = consts
- config = config
- message = message
- types = types
- key = key
+ #consts = consts
+ #config = config
+ #message = message
+ #types = types
+ #key = key
def __init__(self,
@@ -270,7 +272,7 @@
):
"""
@param connectionName: name of the connection or None to use an arbitrary connection name
- @param debugVerbosity: verbosity level for debugging. Default is L{consts.DebugVerbosity.Warning}
+ @param debugVerbosity: verbosity level for debugging. Default is L{consts.ConstDebugVerbosity.Warning}
"""
self._connectionName = self.setConnectionName(connectionName)
@@ -282,7 +284,7 @@
for event in self.events:
event += self._captureEvent
- self.setDebugVerbosity(consts.DebugVerbosity.Warning if debugVerbosity is None else debugVerbosity)
+ self.setDebugVerbosity(consts.ConstDebugVerbosity.Warning if debugVerbosity is None else debugVerbosity)
atexit.register(self.close)
###############################################################
@@ -292,9 +294,9 @@
###############################################################
def _captureEvent(self, event, request):
if event == self.events.Idle:
- consts.Logger.Event.log(consts.DebugVerbosity.Chatty, consts.LogMessages.EventTriggered + event.name)
+ consts.ConstLogger.Event.log(consts.ConstDebugVerbosity.Chatty, consts.ConstLogMessages.EventTriggered + event.name)
else:
- consts.Logger.Event.info(consts.LogMessages.EventTriggered + event.name)
+ consts.ConstLogger.Event.info(consts.ConstLogMessages.EventTriggered + event.name)
def _close(self, msg):
@@ -305,7 +307,7 @@
@todo: trigger ClientDisconnected() if the client is already closed? should be yes. otherwise
we'd have to distinguish between intentional and unintentional closing like on a broken io
"""
- consts.Logger.Client.info(consts.LogMessages.Closing)
+ consts.ConstLogger.Client.info(consts.ConstLogMessages.Closing)
# clean left over DDA test tmp files
for initialRequest in self._ddaTests:
@@ -328,21 +330,21 @@
@param request: request to finalize
@param event: event to trigger or None
- @note: this method sets the requests L{consts.RequestStatus.RemovedFromQueue} and
- L{consts.RequestStatus.Completed} flags accordingly
+ @note: this method sets the requests L{consts.ConstRequestStatus.RemovedFromQueue} and
+ L{consts.ConstRequestStatus.Completed} flags accordingly
@note: Fcp removes Get / Put requests with Persistence == connection emidiately
from its queue. Same goes all requests on ProtocolError. We inform the caller
that the request has been completed and remove it fom our queue if necessary.
Non Get / Put requests will be removed in any case.
"""
- removeRequest = msg == message.ProtocolError or msg == message.PersistentRequestRemoved # TODO: PersistentRequestRemoved???
+ removeRequest = msg == message.MsgProtocolError or msg == message.MsgPersistentRequestRemoved # TODO: PersistentRequestRemoved???
if not removeRequest:
#NOTE: non Get / Put related requests do not have a Persistence param
- removeRequest = request.params.get('Persistence', consts.Persistence.Connection) == consts.Persistence.Connection
+ removeRequest = request.params.get('Persistence', consts.ConstPersistence.Connection) == consts.ConstPersistence.Connection
if removeRequest:
- request['RequestStatus'] |= consts.RequestStatus.RemovedFromQueue
+ request['RequestStatus'] |= consts.ConstRequestStatus.RemovedFromQueue
- request['RequestStatus'] |= consts.RequestStatus.Completed
+ request['RequestStatus'] |= consts.ConstRequestStatus.Completed
if event is not None:
event(request)
@@ -370,13 +372,13 @@
identifier=None,
initTime=None,
persistentUserData='',
- filenameCollision=consts.FilenameCollision.HandleNever,
+ filenameCollision=consts.ConstFilenameCollision.HandleNever,
):
"""Registers a request
@param msg: message to register
- @param requestType: (L{consts.RequestType}) type of request to register
- @param filenameCollision: (L{consts.FilenameCollision}) how to handle filename collisions.
- Default is L{consts.FilenameCollision.HandleNever}
+ @param requestType: (L{consts.ConstRequestType}) type of request to register
+ @param filenameCollision: (L{consts.ConstFilenameCollision}) how to handle filename collisions.
+ Default is L{consts.ConstFilenameCollision.HandleNever}
@param identifier: (str) identifier of the request or None to create a new one
@param initTime: (int) init time of the request or None to set it to now
@param persistentUserData: (str) anyuser defined persistent data
@@ -390,39 +392,27 @@
# equip requests with some additional params
#TODO: keep an eye on additional params, they may collide with Fcp parameters
- Private = message.PrivateParam
-
- """
- @requestparam: B{ErrorMessage:} (L{messageMessage}) if an error occured
- @requestparam: B{Modified:} (dict)
- @requestparam: B{Modified:} (dict)
- @requestparam: B{PrivateKey:} None. Will contain the private key as soon as the key is generated
- @requestparam: B{PublicKey:} None. Will contain the public key as soon as the key is generated
- @requestparam: B{RequestStatus:} one or more of the L{consts.RequestStatus} flags
- @requestparam: B{RequestType:} one or more of the L{consts.RequestType} flags
- @requestparam: B{Identifier:} identifier of the request
- """
msg['Identifier'] = self._newUuid(uuids=self._requests) if identifier is None else identifier
msg['RequestType'] = requestType
msg['InitTime'] = time.time() if initTime is None else initTime
- if requestType & consts.RequestType.MaskGet:
+ if requestType & consts.ConstRequestType.MaskGet:
msg['FilenameCollision'] = filenameCollision
msg['UserData'] = userData
msg['PersistentUserData'] = persistentUserData
msg['ClientToken'] = ''
msg.updatePersistentParams()
- elif requestType & consts.RequestType.MaskPut:
+ elif requestType & consts.ConstRequestType.MaskPut:
msg['UserData'] = userData
msg['PersistentUserData'] = persistentUserData
msg['ClientToken'] = ''
msg.updatePersistentParams()
- elif requestType & consts.RequestType.MaskGenerateKeypair:
+ elif requestType & consts.ConstRequestType.MaskGenerateKeypair:
pass
- elif requestType & consts.RequestType.SubscribeUSK:
+ elif requestType & consts.ConstRequestType.SubscribeUSK:
msg['UserData'] = userData
- elif requestType & consts.RequestType.PluginInfo:
+ elif requestType & consts.ConstRequestType.PluginInfo:
pass
else:
raise ValueError('Can not register request: ' + msg.name)
@@ -438,15 +428,15 @@
"""Closes the client
@note: make shure to call close() when done with the client
"""
- msg = message.ClientDisconnected(
- DisconnectReason=consts.DisconnectReason.Close,
+ msg = message.MsgClientDisconnected(
+ DisconnectReason=consts.ConstDisconnectReason.Close,
)
self._close(msg)
def closeNode(self):
"""Shuts down the freenet node"""
- self.sendMessage(message.Shutdown())
+ self.sendMessage(message.MsgShutdown())
def connect(self, host=DefaultFcpHost, port=DefaultFcpPort, duration=20, timeout=0.5):
@@ -456,7 +446,7 @@
@param duration: (int) how many seconds try to connect before giving up
@param timeout: (int) how much time to wait before another attempt to connect
- @return: (L{message.Message}) NodeHello or None if no connection could be established
+ @return: (L{message.MsgMessage}) NodeHello or None if no connection could be established
"""
nodeHello = None
for nodeHello in self.iterConnect(host=host, port=port, duration=duration, timeout=timeout):
@@ -479,7 +469,7 @@
@param duration: (int) how many seconds try to connect before giving up
@param timeout: (int) how much time to wait before another attempt to connect
- @return: (L{message.Message}) NodeHello if successful, None otherwise for the next iteration
+ @return: (L{message.MsgMessage}) NodeHello if successful, None otherwise for the next iteration
@event: ClientConnected(event, message) is triggered as soon as the client is connected
"""
@@ -487,12 +477,12 @@
#TODO: we have to yield a few round here to make NodeHello injection work in unittests
# no idea exactly how many...
if self.ioHandler.isOpen():
- disconnectMsg = message.ClientDisconnected(
- DisconnectReason=consts.DisconnectReason.Reconnect,
+ disconnectMsg = message.MsgClientDisconnected(
+ DisconnectReason=consts.ConstDisconnectReason.Reconnect,
)
self._close(disconnectMsg)
- disconnectReason = consts.DisconnectReason.IOConnectFailed
+ disconnectReason = consts.ConstDisconnectReason.IOConnectFailed
t0 = time.time()
for result in self.ioHandler.iterConnect(duration=duration, timeout=timeout, host=host, port=port):
yield None
@@ -501,7 +491,7 @@
timeElapsed = time.time() - t0
if result:
self.sendMessage(
- message.ClientHello(
+ message.MsgClientHello(
Name=self._connectionName,
ExpectedVersion=self.ExpectedFcpVersion,
)
@@ -510,11 +500,11 @@
while timeElapsed <= duration:
yield None
msg = self.next(dispatch=False)
- if msg == message.ClientSocketTimeout:
- disconnectReason = consts.DisconnectReason.NoNodeHello
+ if msg == message.MsgClientSocketTimeout:
+ disconnectReason = consts.ConstDisconnectReason.NoNodeHello
timeElapsed += max(self.ioHandler.io.Timeout, 0.1)
yield None
- elif msg == message.NodeHello:
+ elif msg == message.MsgNodeHello:
self._nodeHelloMessage = msg
# check if version is ok
if self.versionCheckNodeHello(msg):
@@ -522,13 +512,13 @@
yield self._nodeHelloMessage
raise StopIteration
else:
- disconnectReason = consts.DisconnectReason.VersionMissmatch
+ disconnectReason = consts.ConstDisconnectReason.VersionMissmatch
break
else:
- disconnectReason = consts.DisconnectReason.UnknownNodeHello
+ disconnectReason = consts.ConstDisconnectReason.UnknownNodeHello
break
- disconnectMsg = message.ClientDisconnected(
+ disconnectMsg = message.MsgClientDisconnected(
DisconnectReason=disconnectReason,
)
self._close(disconnectMsg)
@@ -553,17 +543,17 @@
def getDebugVerbosity(self):
"""Returns the current verbosity level of the client
- @return: L{consts.DebugVerbosity}
+ @return: L{consts.ConstDebugVerbosity}
"""
- return consts.Logger.Client.getEffectiveLevel()
+ return consts.ConstLogger.Client.getEffectiveLevel()
def setDebugVerbosity(self, debugVerbosity):
"""Sets the verbosity level of the client
- @param debugVerbosity: L{consts.DebugVerbosity}
+ @param debugVerbosity: L{consts.ConstDebugVerbosity}
"""
- consts.Logger.Client.setLevel(debugVerbosity)
+ consts.ConstLogger.Client.setLevel(debugVerbosity)
@@ -616,7 +606,7 @@
## errors
##
####################################################
- if msg == message.IdentifierCollision:
+ if msg == message.MsgIdentifierCollision:
if initialRequest is None:
self.events.IdentifierCollision(msg)
return False
@@ -626,17 +616,17 @@
self._requests[newIdentifier] = initialRequest
del self._requests[requestIdentifier]
initialRequest['Identifier'] = newIdentifier
- initialRequest['Modified'] = {consts.RequestModified.Identifier: requestIdentifier}
+ initialRequest['Modified'] = {consts.ConstRequestModified.Identifier: requestIdentifier}
self.events.RequestModified(initialRequest)
self.sendMessage(initialRequest)
return True
- elif msg == message.ProtocolError:
+ elif msg == message.MsgProtocolError:
code = msg['Code']
- if code == consts.ProtocolError.ShuttingDown:
- disconnectMsg = message.ClientDisconnected(
- DisconnectReason=consts.DisconnectReason.NodeClosing,
+ if code == consts.ConstProtocolError.ShuttingDown:
+ disconnectMsg = message.MsgClientDisconnected(
+ DisconnectReason=consts.ConstDisconnectReason.NodeClosing,
)
self._close(disconnectMsg)
return True
@@ -651,9 +641,9 @@
return False
# handle DDA errors
- elif code == consts.ProtocolError.DDADenied:
- ddaRequestMsg = message.TestDDARequest()
- if initialRequest == message.ClientGet:
+ elif code == consts.ConstProtocolError.DDADenied:
+ ddaRequestMsg = message.MsgTestDDARequest()
+ if initialRequest == message.MsgClientGet:
ddaRequestMsg['WantWriteDirectory'] = True
directory = os.path.dirname(initialRequest['Filename'])
else:
@@ -675,31 +665,31 @@
# handle filename collisions
- elif code == consts.ProtocolError.DiskTargetExists:
- handleCollision = initialRequest.get('FilenameCollision', consts.FilenameCollision.HandleNever)
- collisionHandled = bool(handleCollision & consts.FilenameCollision.CollisionHandled)
+ elif code == consts.ConstProtocolError.DiskTargetExists:
+ handleCollision = initialRequest.get('FilenameCollision', consts.ConstFilenameCollision.HandleNever)
+ collisionHandled = bool(handleCollision & consts.ConstFilenameCollision.CollisionHandled)
# rename filename
- if handleCollision & consts.FilenameCollision.HandleRename:
+ if handleCollision & consts.ConstFilenameCollision.HandleRename:
filename = initialRequest['Filename']
- initialRequest['FilenameCollision'] |= consts.FilenameCollision.CollisionHandled
+ initialRequest['FilenameCollision'] |= consts.ConstFilenameCollision.CollisionHandled
newFilename = namespace.unique_filename(filename, extensions=1, ispostfixed=collisionHandled)
initialRequest['Filename'] = newFilename
- initialRequest['Modified'] = {consts.RequestModified.Filename: filename}
+ initialRequest['Modified'] = {consts.ConstRequestModified.Filename: filename}
self.sendMessage(initialRequest)
self.events.RequestModified(initialRequest)
return True
# don't handle
else:
- initialRequest['FilenameCollision'] &= ~consts.FilenameCollision.CollisionHandled
+ initialRequest['FilenameCollision'] &= ~consts.ConstFilenameCollision.CollisionHandled
# handle plugin related request failures
- elif code == consts.ProtocolError.NoSuchPlugin or code == consts.ProtocolError.AccessDenied:
- if initialRequest == message.GetPluginInfo:
+ elif code == consts.ConstProtocolError.NoSuchPlugin or code == consts.ConstProtocolError.AccessDenied:
+ if initialRequest == message.MsgGetPluginInfo:
initialRequest['ErrorMessage'] = msg
- initialRequest['RequestStatus'] |= consts.RequestStatus.Error
+ initialRequest['RequestStatus'] |= consts.ConstRequestStatus.Error
self._finalizeRequest(msg, initialRequest, self.events.PluginInfoFailed)
return True
@@ -707,7 +697,7 @@
# NOTE: Fcp already removed the request
initialRequest['ErrorMessage'] = msg
- initialRequest['RequestStatus'] |= consts.RequestStatus.Error
+ initialRequest['RequestStatus'] |= consts.ConstRequestStatus.Error
self._finalizeRequest(msg, initialRequest, self.events.RequestFailed)
return True
@@ -721,7 +711,7 @@
## TestDDA drill.
##
####################################################
- elif msg == message.TestDDAReply:
+ elif msg == message.MsgTestDDAReply:
directory = msg['Directory']
# find message that triggered the call
@@ -752,7 +742,7 @@
initialRequest['TestDDA']['TmpFile'] = fpathWrite
self.sendMessage(
- message.TestDDAResponse(
+ message.MsgTestDDAResponse(
Directory=msg['Directory'],
ReadContent=readContent,
)
@@ -760,7 +750,7 @@
return True
- elif msg == message.TestDDAComplete:
+ elif msg == message.MsgTestDDAComplete:
# clean up tmp file
directory = msg['Directory']
@@ -787,7 +777,7 @@
testFailed = not msg.params.get('ReadDirectoryAllowed', False)
if testFailed:
- initialRequest['RequestStatus'] = consts.RequestStatus.Error
+ initialRequest['RequestStatus'] = consts.ConstRequestStatus.Error
initialRequest['ErrorMessage'] = initialRequest['TestDDA']['ErrorMsg']
self._finalizeRequest(msg, initialRequest, self.events.RequestFailed)
return True
@@ -801,11 +791,11 @@
## config related
##
####################################################
- elif msg == message.ConfigData:
+ elif msg == message.MsgConfigData:
self.events.ConfigData(msg)
return True
- elif msg == message.NodeData:
+ elif msg == message.MsgNodeData:
self.events.NodeData(msg)
return True
@@ -814,20 +804,20 @@
## get / put related
##
####################################################
- elif msg == message.AllData:
+ elif msg == message.MsgAllData:
if initialRequest is None:
return False
- initialRequest['RequestStatus'] |= consts.RequestStatus.Success
+ initialRequest['RequestStatus'] |= consts.ConstRequestStatus.Success
initialRequest.data = msg.data
self._finalizeRequest(msg, initialRequest, self.events.RequestCompleted)
return True
- elif msg == message.DataFound:
+ elif msg == message.MsgDataFound:
if initialRequest is None:
return False
- initialRequest['RequestStatus'] |= consts.RequestStatus.Success
+ initialRequest['RequestStatus'] |= consts.ConstRequestStatus.Success
initialRequest['MetadataContentType'] = msg.get('Metadata.ContentType', '')
initialRequest['MetadataSize'] = msg.get('DataLength', '')
@@ -836,10 +826,10 @@
# For GetData with persistence != connection the node sends no All Data message
# whatever that is good for ..fix this here to get all GetData request to complete on
# All Data.
- if initialRequest['RequestType'] == consts.RequestType.GetData:
- if initialRequest['Persistence'] != consts.Persistence.Connection:
+ if initialRequest['RequestType'] == consts.ConstRequestType.GetData:
+ if initialRequest['Persistence'] != consts.ConstPersistence.Connection:
self.sendMessage(
- message.GetRequestStatus(
+ message.MsgGetRequestStatus(
Identifier=initialRequest['Identifier'],
Global=False,
OnlyData=True
@@ -851,37 +841,37 @@
return True
- elif msg == message.GetFailed:
+ elif msg == message.MsgGetFailed:
if initialRequest is None:
return False
code = msg['Code']
- if code == consts.FetchError.Canceled:
- initialRequest['RequestStatus'] |= consts.RequestStatus.Removed | consts.RequestStatus.Completed | consts.RequestStatus.RemovedFromQueue
+ if code == consts.ConstFetchError.Canceled:
+ initialRequest['RequestStatus'] |= consts.ConstRequestStatus.Removed | consts.ConstRequestStatus.Completed | consts.ConstRequestStatus.RemovedFromQueue
del self._requests[requestIdentifier]
self.events.RequestRemoved(initialRequest)
return True
# check if it is one of our requests for key information
- if code == consts.FetchError.TooBig and initialRequest['RequestType'] == consts.RequestType.GetKeyInfo:
+ if code == consts.ConstFetchError.TooBig and initialRequest['RequestType'] == consts.ConstRequestType.GetKeyInfo:
initialRequest['MetadataContentType'] = msg.get('ExpectedMetadata.ContentType', '')
initialRequest['DataLength'] = msg.get('ExpectedDataLength', -1)
- initialRequest['RequestStatus'] |= consts.RequestStatus.Success
+ initialRequest['RequestStatus'] |= consts.ConstRequestStatus.Success
self._finalizeRequest(msg, initialRequest, self.events.RequestCompleted)
else:
initialRequest['ErrorMessage'] = msg
- initialRequest['RequestStatus'] |= consts.RequestStatus.Error
+ initialRequest['RequestStatus'] |= consts.ConstRequestStatus.Error
self._finalizeRequest(msg, initialRequest, self.events.RequestFailed)
return True
- elif msg == message.PersistentGet or msg == message.PersistentPut or msg == message.PersistentPutDir:
+ elif msg == message.MsgPersistentGet or msg == message.MsgPersistentPut or msg == message.MsgPersistentPutDir:
# unknown request... try to restore it
if initialRequest is None:
if CancelPersistentRequests:
self.sendMessage(
- message.RemoveRequest(
+ message.MsgRemoveRequest(
Identifier=msg['Identifier'],
Global=msg['Global'],
)
@@ -889,13 +879,13 @@
return True
requestType = msg['RequestType']
- if msg == message.PersistentGet:
- initialRequest = message.ClientGet()
- elif msg == message.PersistentPut:
- initialRequest = message.ClientPut()
+ if msg == message.MsgPersistentGet:
+ initialRequest = message.MsgClientGet()
+ elif msg == message.MsgPersistentPut:
+ initialRequest = message.MsgClientPut()
else:
#NOTE: PutDiskDir is just a subtype of PutComplexDir. check PutDirType param to tell appart
- initialRequest = message.ClientPutComplexDir()
+ initialRequest = message.MsgClientPutComplexDir()
initialRequest.params.update(msg.params)
self._requests[initialRequest['Identifier']] = initialRequest
@@ -903,7 +893,7 @@
#FIX: remove Started param from PersistentGet / Put, not interesting
if 'Started' in initialRequest.params:
del initialRequest.params['Started']
- initialRequest['RequestStatus'] |= consts.RequestStatus.Restored
+ initialRequest['RequestStatus'] |= consts.ConstRequestStatus.Restored
self.events.RequestRestored(initialRequest)
return True
@@ -911,7 +901,7 @@
return False
- elif msg == message.PersistentRequestModified:
+ elif msg == message.MsgPersistentRequestModified:
if initialRequest is None:
return False
@@ -920,7 +910,7 @@
# check if PersistentUserData has changed
clientToken = msg.get('ClientToken', None)
if clientToken is not None:
- modified[consts.RequestModified.PersistentUserData] = None
+ modified[consts.ConstRequestModified.PersistentUserData] = None
#TODO: its more or less a guess that PersistentUserData has changed
# ...as long as no other param is changed at runtime we are ok
@@ -937,7 +927,7 @@
# check if PriorityClass has changed
priorityClass = msg.get('PriorityClass', None)
if priorityClass is not None:
- modified[consts.RequestModified.PriorityClass] = None
+ modified[consts.ConstRequestModified.PriorityClass] = None
initialRequest['PriorityClass'] = priorityClass
initialRequest['Modified'] = modified
@@ -945,16 +935,16 @@
return True
#NOTE: fcp sends a GetFailed / PutFailed if the request was still running (code=canceled)
- elif msg == message.PersistentRequestRemoved:
+ elif msg == message.MsgPersistentRequestRemoved:
if initialRequest is None:
return False
- initialRequest['RequestStatus'] |= consts.RequestStatus.Removed | consts.RequestStatus.Completed | consts.RequestStatus.RemovedFromQueue
+ initialRequest['RequestStatus'] |= consts.ConstRequestStatus.Removed | consts.ConstRequestStatus.Completed | consts.ConstRequestStatus.RemovedFromQueue
del self._requests[requestIdentifier]
self.events.RequestRemoved(initialRequest)
return True
- elif msg == message.SimpleProgress:
+ elif msg == message.MsgSimpleProgress:
if initialRequest is None:
return False
@@ -968,24 +958,24 @@
## put related
- elif msg == message.PutFailed:
+ elif msg == message.MsgPutFailed:
if initialRequest is None:
return False
code = msg['Code']
- if code == consts.InsertError.Canceled:
- initialRequest['RequestStatus'] |= consts.RequestStatus.Removed | consts.RequestStatus.Completed | consts.RequestStatus.RemovedFromQueue
+ if code == consts.ConstInsertError.Canceled:
+ initialRequest['RequestStatus'] |= consts.ConstRequestStatus.Removed | consts.ConstRequestStatus.Completed | consts.ConstRequestStatus.RemovedFromQueue
del self._requests[requestIdentifier]
self.events.RequestRemoved(initialRequest)
return True
- initialRequest['RequestStatus'] |= consts.RequestStatus.Error
+ initialRequest['RequestStatus'] |= consts.ConstRequestStatus.Error
initialRequest['ErrorMessage'] = msg
self._finalizeRequest(msg, initialRequest, self.events.RequestFailed)
return True
- elif msg == message.PutFetchable:
+ elif msg == message.MsgPutFetchable:
if initialRequest is None:
# something went wrong
return False
@@ -994,35 +984,35 @@
return True
- elif msg == message.PutSuccessful:
+ elif msg == message.MsgPutSuccessful:
if initialRequest is None:
return False
# TODO: StartupTime and CompletionTime are passed, but
# as long as no corrosponding params are passed in DataFound
# we ignore them
- initialRequest['RequestStatus'] |= consts.RequestStatus.Success
+ initialRequest['RequestStatus'] |= consts.ConstRequestStatus.Success
initialRequest['URI'] = msg['URI']
self._finalizeRequest(msg, initialRequest, self.events.RequestCompleted)
return True
- elif msg == message.URIGenerated:
+ elif msg == message.MsgURIGenerated:
if initialRequest is None:
return False
initialRequest['URI'] = msg['URI']
return True
- elif msg == message.FinishedCompression:
+ elif msg == message.MsgFinishedCompression:
if initialRequest is None:
return False
- initialRequest['RequestStatus'] |= consts.RequestStatus.Compressed
+ initialRequest['RequestStatus'] |= consts.ConstRequestStatus.Compressed
self.events.RequestCompressionCompleted(initialRequest)
return True
- elif msg == message.StartedCompression:
+ elif msg == message.MsgStartedCompression:
if initialRequest is None:
return False
- initialRequest['RequestStatus'] |= consts.RequestStatus.Compressing
+ initialRequest['RequestStatus'] |= consts.ConstRequestStatus.Compressing
self.events.RequestCompressionStarted(initialRequest)
return True
@@ -1031,31 +1021,31 @@
## Peer related messages
##
####################################################
- elif msg == message.EndListPeers:
+ elif msg == message.MsgEndListPeers:
self.events.EndListPeers(msg)
return True
- elif msg == message.EndListPeerNotes:
+ elif msg == message.MsgEndListPeerNotes:
self.events.EndListPeerNotes(msg.params)
return True
- elif msg == message.Peer:
+ elif msg == message.MsgPeer:
self.events.Peer(msg)
return True
- elif msg == message.PeerNote:
+ elif msg == message.MsgPeerNote:
self.events.PeerNote(msg)
return True
- elif msg == message.PeerRemoved:
+ elif msg == message.MsgPeerRemoved:
self.events.PeerRemoved(msg)
return True
- elif msg == message.UnknownNodeIdentifier:
+ elif msg == message.MsgUnknownNodeIdentifier:
self.events.PeerUnknown(msg)
return True
- elif msg == message.UnknownPeerNoteType:
+ elif msg == message.MsgUnknownPeerNoteType:
self.events.PeerNoteTypeUnknown(msg)
return True
####################################################
@@ -1063,15 +1053,15 @@
## plugins
##
####################################################
- elif msg == message.PluginInfo:
+ elif msg == message.MsgPluginInfo:
if initialRequest is None:
return False
- initialRequest['RequestStatus'] |= consts.RequestStatus.Success
+ initialRequest['RequestStatus'] |= consts.ConstRequestStatus.Success
self._finalizeRequest(msg, initialRequest, self.events.PluginInfo)
return True
- elif msg == message.FCPPluginReply:
+ elif msg == message.MsgFCPPluginReply:
self.events.PluginMessage(msg)
return True
@@ -1080,31 +1070,31 @@
## others
##
####################################################
- elif msg == message.CloseConnectionDuplicateClientName:
- disconnectMsg = message.ClientDisconnected(
- DisconnectReason=consts.DisconnectReason.DuplicateClientName,
+ elif msg == message.MsgCloseConnectionDuplicateClientName:
+ disconnectMsg = message.MsgClientDisconnected(
+ DisconnectReason=consts.ConstDisconnectReason.DuplicateClientName,
)
self._close(disconnectMsg)
return True
- elif msg == message.SSKKeypair:
+ elif msg == message.MsgSSKKeypair:
if initialRequest is None:
return False
insertURI = msg['InsertURI']
requestURI = msg['RequestURI']
- if initialRequest['RequestType'] == consts.RequestType.GenerateUSKKeypair:
- insertURI = key.USK(insertURI.keyData, filename=insertURI.filename)
- requestURI = key.USK(requestURI.keyData, filename=requestURI.filename)
+ if initialRequest['RequestType'] == consts.ConstRequestType.GenerateUSKKeypair:
+ insertURI = key.KeyUSK(insertURI.keyData, filename=insertURI.filename)
+ requestURI = key.KeyUSK(requestURI.keyData, filename=requestURI.filename)
initialRequest['InsertURI'] = insertURI
initialRequest['RequestURI'] = requestURI
- initialRequest['RequestStatus'] |= consts.RequestStatus.Success
+ initialRequest['RequestStatus'] |= consts.ConstRequestStatus.Success
self._finalizeRequest(msg, initialRequest, self.events.KeypairGenerated)
return True
- elif msg == message.SubscribedUSKUpdate:
+ elif msg == message.MsgSubscribedUSKUpdate:
if initialRequest is None:
return False
@@ -1127,24 +1117,24 @@
#FIX: [0002083] we may run into persistents of other clients by accident. the client can not handle them.
# so remove them, no matter what....
def hackyInvalidMessageCallback(msg, requests=self._requests):
- if msg == message.PersistentGet or msg == message.PersistentPut or msg == message.PersistentPutDir:
+ if msg == message.MsgPersistentGet or msg == message.MsgPersistentPut or msg == message.MsgPersistentPutDir:
requestIdentifier = msg['Identifier']
if requestIdentifier not in requests:
- msgRemove = message.RemoveRequest(Identifier=msg['Identifier'], Global=msg['Global'])
+ msgRemove = message.MsgRemoveRequest(Identifier=msg['Identifier'], Global=msg['Global'])
self.sendMessage(msgRemove)
try:
msg = self.ioHandler.readMessage(hackyInvalidMessageCallback=hackyInvalidMessageCallback)
- except consts.IOTimeoutError, details:
- msg = message.ClientSocketTimeout()
+ except consts.ErrorIOTimeout, details:
+ msg = message.MsgClientSocketTimeout()
if dispatch:
self.events.Idle(msg)
- except consts.IOBrokenError, details:
- msg = message.ClientDisconnected(
- DisconnectReason=consts.DisconnectReason.ConnectionDied,
+ except consts.ErrorIOBroken, details:
+ msg = message.MsgClientDisconnected(
+ DisconnectReason=consts.ConstDisconnectReason.ConnectionDied,
)
self._close(msg)
- raise consts.IOBrokenError(details)
+ raise consts.ErrorIOBroken(details)
else:
if dispatch:
self.handleMessage(msg)
@@ -1163,9 +1153,9 @@
try:
msg = self.next()
except KeyboardInterrupt:
- consts.Logger.Client.info(consts.LogMessages.KeyboardInterrupt)
+ consts.ConstLogger.Client.info(consts.ConstLogMessages.KeyboardInterrupt)
return
- if msg == message.ClientSocketDied:
+ if msg == message.MsgClientSocketDied:
return
#n = 0
@@ -1176,28 +1166,28 @@
# check if we have running requests. Assert False
haveRunningRequests = False
for request in self._requests.values():
- if not request['RequestStatus'] & consts.RequestStatus.Completed:
+ if not request['RequestStatus'] & consts.ConstRequestStatus.Completed:
haveRunningRequests = True
break
if not haveRunningRequests:
- consts.Logger.Client.info(consts.LogMessages.AllRequestsCompleted)
+ consts.ConstLogger.Client.info(consts.ConstLogMessages.AllRequestsCompleted)
break
try:
msg = self.next()
except KeyboardInterrupt:
- sconsts.Logger.Client.info(consts.LogMessages.KeyboardInterrupt)
+ sconsts.ConstLogger.Client.info(consts.ConstLogMessages.KeyboardInterrupt)
break
- if msg == message.ClientSocketDied:
+ if msg == message.MsgClientSocketDied:
break
def sendMessage(self, msg):
"""Sends a message to freenet
- @param msg: (L{message.Message}) message to send
- @return: (L{message.Message}) disconnect if something went wrong
+ @param msg: (L{message.MsgMessage}) message to send
+ @return: (L{message.MsgMessage}) disconnect if something went wrong
@note: If an error occurs the client is closed
@note: you can use this method to send a message to the node, bypassing all
@@ -1210,12 +1200,12 @@
# ...so assume data was send, cos there is no way to proove it was not send
try:
self.ioHandler.sendMessage(msg)
- except consts.IOBrokenError, details:
- errorMsg = message.ClientDisconnected(
- DisconnectReason=consts.DisconnectReason.ConnectionDied,
+ except consts.ErrorIOBroken, details:
+ errorMsg = message.MsgClientDisconnected(
+ DisconnectReason=consts.ConstDisconnectReason.ConnectionDied,
)
self._close(errorMsg)
- raise consts.IOBrokenError(details)
+ raise consts.ErrorIOBroken(details)
#########################################################
##
@@ -1236,7 +1226,7 @@
@event: ConfigData(event, msg)
"""
self.sendMessage(
- message.GetConfig(
+ message.MsgGetConfig(
WithSortOrder=withSortOrder,
WithCurrent=withCurrent,
WithDefaults=withDefaults,
@@ -1254,7 +1244,7 @@
"""Modifies node configuration values
@param params: (dict) containing parameters to modify
"""
- msg = message.ModifyConfig()
+ msg = message.MsgModifyConfig()
msg.params = params
self.sendMessage(msg)
@@ -1273,7 +1263,7 @@
):
"""Requests a key from the node
@param uri: (L{key.KeyBase}) key to request
- @param requestType: (L{consts.RequestType}) sub type of the message
+ @param requestType: (L{consts.ConstRequestType}) sub type of the message
@param userData: any non persistent data to associate to the request or None
@param persistentUserData: any string to associate to the request as persistent data or None
@param filenameCollision: what to do if the disk target alreaady exists. One of the FilenameCollision.* consts
@@ -1282,7 +1272,7 @@
@return: (str) request identifier
"""
- msg = message.ClientGet(URI=uri)
+ msg = message.MsgClientGet(URI=uri)
for paramName, value in messageParams.items():
if value is not None:
msg[paramName] = value
@@ -1308,8 +1298,8 @@
ignoreDS=False,
maxRetries=None,
maxSize=None,
- persistence=consts.Persistence.Connection,
- priorityClass=consts.Priority.Medium,
+ persistence=consts.ConstPersistence.Connection,
+ priorityClass=consts.ConstPriority.Medium,
userData=None,
persistentUserData='',
@@ -1324,8 +1314,8 @@
@param ignoreDS: (bool) if True, ignores the local data store
@param maxRetries: (int) maximum number of retries or -1 to retry forver or None to leave it to the node to decide
@param maxSize: (int) maximum size of the file in bytes or None to set no limited
- @param persistence: (L{consts.Persistence}) persistence of the request
- @param priorityClass: (L{consts.Priority}) priority of the request
+ @param persistence: (L{consts.ConstPersistence}) persistence of the request
+ @param priorityClass: (L{consts.ConstPriority}) priority of the request
@param userData: any non persistent data to associate to the request
@param persistentUserData: any string to associate to the request as persistent data
@@ -1338,15 +1328,15 @@
@note: the identifier of the request may change at any time. You should be prepaired to handle
this
- @note: if persistence is L{consts.Persistence.Connection} the request is removed from the client
+ @note: if persistence is L{consts.ConstPersistence.Connection} the request is removed from the client
as soon as it completes or failes
"""
return self.clientGet(
uri,
- consts.RequestType.GetData,
+ consts.ConstRequestType.GetData,
userData,
persistentUserData,
- consts.FilenameCollision.HandleNever,
+ consts.ConstFilenameCollision.HandleNever,
# Fcp params
AllowedMimeTypes = allowedMimeTypes,
@@ -1359,8 +1349,8 @@
MaxSize = maxSize,
Persistence=persistence,
PriorityClass=priorityClass,
- ReturnType=consts.ReturnType.Direct,
- Verbosity=consts.Verbosity.ReportProgress,
+ ReturnType=consts.ConstReturnType.Direct,
+ Verbosity=consts.ConstVerbosity.ReportProgress,
)
@@ -1375,12 +1365,12 @@
ignoreDS=False,
maxRetries=None,
maxSize=None,
- persistence=consts.Persistence.Connection,
- priorityClass=consts.Priority.Medium,
+ persistence=consts.ConstPersistence.Connection,
+ priorityClass=consts.ConstPriority.Medium,
userData=None,
persistentUserData='',
- filenameCollision=consts.FilenameCollision.HandleNever,
+ filenameCollision=consts.ConstFilenameCollision.HandleNever,
):
"""Requests a file from the node
@@ -1393,8 +1383,8 @@
@param ignoreDS: If True, ignores the local data store
@param maxRetries: (int) maximum number of retries or -1 to retry forver or None to leave it to the node to decide
@param maxSize: (int) maximum size of the file in bytes or None to set no limited
- @param persistence: (L{consts.Persistence}) persistence of the request
- @param priorityClass: (L{consts.Priority}) priority of the request
+ @param persistence: (L{consts.ConstPersistence}) persistence of the request
+ @param priorityClass: (L{consts.ConstPriority}) priority of the request
@param filenameCollision: what to do if the disk target alreaady exists. One of the FilenameCollision.* consts
@param userData: any non persistent data to associate to the request
@param persistentUserData: any string to associate to the request as persistent data
@@ -1407,12 +1397,12 @@
filename changes or the request is modified otherwise (see L{modifyRequest})
- @note: if persistence is L{consts.Persistence.Connection} the request is removed from the client
+ @note: if persistence is L{consts.ConstPersistence.Connection} the request is removed from the client
as soon as it completes or failes
"""
return self.clientGet(
uri,
- consts.RequestType.GetFile,
+ consts.ConstRequestType.GetFile,
userData,
persistentUserData,
filenameCollision,
@@ -1429,8 +1419,8 @@
MaxSize = maxSize,
Persistence=persistence,
PriorityClass=priorityClass,
- ReturnType=consts.ReturnType.Disk,
- Verbosity=consts.Verbosity.ReportProgress,
+ ReturnType=consts.ConstReturnType.Disk,
+ Verbosity=consts.ConstVerbosity.ReportProgress,
)
@@ -1441,8 +1431,8 @@
dsOnly=False,
ignoreDS=False,
maxRetries=None,
- persistence=consts.Persistence.Connection,
- priorityClass=consts.Priority.Medium,
+ persistence=consts.ConstPersistence.Connection,
+ priorityClass=consts.ConstPriority.Medium,
userData=None,
persistentUserData='',
@@ -1454,8 +1444,8 @@
@param dsOnly: if True, retrieves the file from the local data store only
@param ignoreDS: If True, ignores the local data store
@param maxRetries: (int) maximum number of retries or -1 to retry forver or None to leave it to the node to decide
- @param persistence: (L{consts.Persistence}) persistence of the request
- @param priorityClass: (L{consts.Priority}) priority of the request
+ @param persistence: (L{consts.ConstPersistence}) persistence of the request
+ @param priorityClass: (L{consts.ConstPriority}) priority of the request
@param userData: any non persistent data to associate to the request
@param persistentUserData: any string to associate to the request as persistent data
@@ -1467,16 +1457,16 @@
@event: RequestModified(event, message) trigggered if the request identifier changes
or the request is modified otherwise (see L{modifyRequest})
- @note: if persistence is L{consts.Persistence.Connection} the request is removed from the client
+ @note: if persistence is L{consts.ConstPersistence.Connection} the request is removed from the client
as soon as it completes or failes
"""
# how to retrieve meta info about a key? ...idea is to provoke a GetFailed (TooBig)
return self.clientGet(
uri,
- consts.RequestType.GetKeyInfo,
+ consts.ConstRequestType.GetKeyInfo,
userData,
persistentUserData,
- consts.FilenameCollision.HandleNever,
+ consts.ConstFilenameCollision.HandleNever,
# Fcp params
Global=False,
@@ -1487,8 +1477,8 @@
MaxSize=self.MaxSizeKeyInfo,
Persistence=persistence,
PriorityClass=priorityClass,
- ReturnType=consts.ReturnType.Nothing,
- Verbosity=consts.Verbosity.ReportProgress,
+ ReturnType=consts.ConstReturnType.Nothing,
+ Verbosity=consts.ConstVerbosity.ReportProgress,
)
@@ -1499,17 +1489,17 @@
@param dontPoll: if True, does whatever ???
@return: (str) identifer of the request
- @note: this request can not be removed or modified so the L{consts.RequestStatus.Completed}
+ @note: this request can not be removed or modified so the L{consts.ConstRequestStatus.Completed}
flag is always set
@todo: looks like USK subscribes will persist untill connection is closed. Can they be removed somehow?
"""
- msg = message.SubscribeUSK(
+ msg = message.MsgSubscribeUSK(
URI=uri,
DontPoll=dontPoll,
)
- self._registerRequest(msg, consts.RequestType.SubscribeUSK)
- msg['RequestStatus'] |= consts.RequestStatus.Completed
+ self._registerRequest(msg, consts.ConstRequestType.SubscribeUSK)
+ msg['RequestStatus'] |= consts.ConstRequestStatus.Completed
self.sendMessage(msg)
return msg['Identifier']
@@ -1529,22 +1519,22 @@
**msgParams
):
"""Uploads to the node
- @param requestType: (L{consts.RequestType}). Can be PutData, PutDir or PutMultiple
+ @param requestType: (L{consts.ConstRequestType}). Can be PutData, PutDir or PutMultiple
@param uri: (str) key or Uri
- @param data: (str) for L{consts.RequestType.PutData} data to upload or None
+ @param data: (str) for L{consts.ConstRequestType.PutData} data to upload or None
@param persistentUserData: (str) persistent data to be assosiated to the request
@param userData: (any) any data to be associated to the request at runtime
- @param items: for L{consts.RequestType.PutMultiple}, items to upload
+ @param items: for L{consts.ConstRequestType.PutMultiple}, items to upload
@param msgParams: (dict) Fcp parameters to pass along with the message
@note: the Fcp message parameter 'Metadata.ContentType' may be passed as 'ContentType'
to this method
@note: to upload multiple items at once pass a dict for each item containig the following members:
- - RequestType: L{consts.RequestType.PutData}, L{consts.RequestType.PutFile} or L{consts.RequestType.PutRedirect}
- - Data: if requestType is L{consts.RequestType.PutData}, data to upload
- - Filename: if requestType is L{consts.RequestType.PutFile}, filepath of the file to upload
- - TargetURI: if requestType is L{consts.RequestType.PutRedirect}, uri to redirect to
+ - RequestType: L{consts.ConstRequestType.PutData}, L{consts.ConstRequestType.PutFile} or L{consts.ConstRequestType.PutRedirect}
+ - Data: if requestType is L{consts.ConstRequestType.PutData}, data to upload
+ - Filename: if requestType is L{consts.ConstRequestType.PutFile}, filepath of the file to upload
+ - TargetURI: if requestType is L{consts.ConstRequestType.PutRedirect}, uri to redirect to
- Name: name under wich the item will be accesible via freenet
- Metadata.ContentType: (optional) may be passed as 'ContentType'
@@ -1559,18 +1549,18 @@
msgParams['Metadata.ContentType'] = contentType
# find out wich message to use
- if requestType & (consts.RequestType.PutData | consts.RequestType.PutFile | consts.RequestType.PutRedirect):
- msgClass = message.ClientPut
- elif requestType == consts.RequestType.PutDir:
- msgClass = message.ClientPutDiskDir
- elif requestType == consts.RequestType.PutMultiple:
- msgClass = message.ClientPutComplexDir
+ if requestType & (consts.ConstRequestType.PutData | consts.ConstRequestType.PutFile | consts.ConstRequestType.PutRedirect):
+ msgClass = message.MsgClientPut
+ elif requestType == consts.ConstRequestType.PutDir:
+ msgClass = message.MsgClientPutDiskDir
+ elif requestType == consts.ConstRequestType.PutMultiple:
+ msgClass = message.MsgClientPutComplexDir
else:
raise ValueError('Unsupported request type')
msg = msgClass(URI=uri)
# add params
- if uri.KeyType == consts.KeyType.CHK:
+ if uri.KeyType == consts.ConstKeyType.CHK:
if uri.filename is not None:
msg['TargetFilename'] = uri.filename
for param, value in msgParams.items():
@@ -1578,32 +1568,32 @@
msg[param] = value
if data is not None:
- if requestType != consts.RequestType.PutData:
+ if requestType != consts.ConstRequestType.PutData:
raise ValueError('Data can only be passed along with putData uploads')
msg.data = data
if items is not None:
- if requestType != consts.RequestType.PutMultiple:
+ if requestType != consts.ConstRequestType.PutMultiple:
raise ValueError('Items can only be passed along with PutMultiple uploads')
uploadTypeMapping = {
- consts.RequestType.PutData: consts.UploadFrom.Direct,
- consts.RequestType.PutFile: consts.UploadFrom.Disk,
- consts.RequestType.PutRedirect: consts.UploadFrom.Redirect,
+ consts.ConstRequestType.PutData: consts.ConstUploadFrom.Direct,
+ consts.ConstRequestType.PutFile: consts.ConstUploadFrom.Disk,
+ consts.ConstRequestType.PutRedirect: consts.ConstUploadFrom.Redirect,
}
# requestType --> [(allowedParam: boolParamIsRequired), ...]
paramMapping = {
- consts.RequestType.PutData: [
+ consts.ConstRequestType.PutData: [
('Name', True),
('Data', True),
('ContentType', False),
],
- consts.RequestType.PutFile: [
+ consts.ConstRequestType.PutFile: [
('Name', True),
('Filename', True),
('Metadata.ContentType', False),
],
- consts.RequestType.PutRedirect: [
+ consts.ConstRequestType.PutRedirect: [
('Name', True),
('TargetURI', True),
],
@@ -1668,8 +1658,8 @@
contentType=None,
dontCompress=None,
maxRetries=None,
- persistence=consts.Persistence.Connection,
- priorityClass=consts.Priority.Medium,
+ persistence=consts.ConstPersistence.Connection,
+ priorityClass=consts.ConstPriority.Medium,
userData=None,
persistentUserData='',
@@ -1682,7 +1672,7 @@
@param contentType: (str) content type. If not specified, the node will guess the content type
@param dontCompress: (bool) if True, the node won't try to compress the data
@param maxRetries: (int) maximum number of retries or -1 to retry forver or None to leave it to the node to decide
- @param priorityClass: (L{consts.Priority}) priority of the request
+ @param priorityClass: (L{consts.ConstPriority}) priority of the request
@param userData: any non persistent data to associate to the request
@param persistentUserData: any string to associate to the request as persistent data
@@ -1693,7 +1683,7 @@
@event: (L{events.Events.RequestCompressionStarted}) triggered when the request is about to be compressed
@event: (L{events.Events.RequestCompressionCompleted}) triggered as soon as compressing of the request is completed
- @note: if the upload is successful the node will create a L{consts.KeyType.CHK} key under wich
+ @note: if the upload is successful the node will create a L{consts.ConstKeyType.CHK} key under wich
the data can be retreieved. The key can be accessed as 'URI' member of the request as soon
as the L{events.Events.RequestFetchable} or the L{events.Events.RequestCompleted} event
is triggered.
@@ -1701,7 +1691,7 @@
@todo: EarlyEncode and GetCHKOnly message params not implemented
"""
return self.clientPut(
- consts.RequestType.PutData,
+ consts.ConstRequestType.PutData,
uri,
userData,
persistentUserData,
@@ -1718,8 +1708,8 @@
DontCompress=dontCompress,
Persistence=persistence,
PriorityClass=priorityClass,
- UploadFrom=consts.UploadFrom.Direct,
- Verbosity=consts.Verbosity.ReportProgress | consts.Verbosity.ReportCompression,
+ UploadFrom=consts.ConstUploadFrom.Direct,
+ Verbosity=consts.ConstVerbosity.ReportProgress | consts.ConstVerbosity.ReportCompression,
)
@@ -1732,8 +1722,8 @@
dontCompress=None,
maxRetries=None,
- persistence=consts.Persistence.Connection,
- priorityClass=consts.Priority.Medium,
+ persistence=consts.ConstPersistence.Connection,
+ priorityClass=consts.ConstPriority.Medium,
targetFilename=None,
userData=None,
@@ -1756,7 +1746,7 @@
@todo: 2MiB compressed zize allowed?
"""
return self.clientPut(
- consts.RequestType.PutDir,
+ consts.ConstRequestType.PutDir,
uri,
userData,
persistentUserData,
@@ -1773,8 +1763,8 @@
DontCompress=dontCompress,
Persistence=persistence,
PriorityClass=priorityClass,
- UploadFrom=consts.UploadFrom.Disk,
- Verbosity=consts.Verbosity.ReportProgress | consts.Verbosity.ReportCompression,
+ UploadFrom=consts.ConstUploadFrom.Disk,
+ Verbosity=consts.ConstVerbosity.ReportProgress | consts.ConstVerbosity.ReportCompression,
)
@@ -1784,8 +1774,8 @@
contentType=None,
dontCompress=None,
maxRetries=None,
- persistence=consts.Persistence.Connection,
- priorityClass=consts.Priority.Medium,
+ persistence=consts.ConstPersistence.Connection,
+ priorityClass=consts.ConstPriority.Medium,
userData=None,
persistentUserData='',
@@ -1800,7 +1790,7 @@
@todo: EarlyEncode and GetCHKOnly message params not implemented
"""
return self.clientPut(
- consts.RequestType.PutFile,
+ consts.ConstRequestType.PutFile,
uri,
userData,
persistentUserData,
@@ -1816,8 +1806,8 @@
DontCompress=dontCompress,
Persistence=persistence,
PriorityClass=priorityClass,
- UploadFrom=consts.UploadFrom.Disk,
- Verbosity=consts.Verbosity.ReportProgress | consts.Verbosity.ReportCompression,
+ UploadFrom=consts.ConstUploadFrom.Disk,
+ Verbosity=consts.ConstVerbosity.ReportProgress | consts.ConstVerbosity.ReportCompression,
)
def putMultiple(self,
@@ -1827,8 +1817,8 @@
defaultName=None,
dontCompress=None,
maxRetries=None,
- persistence=consts.Persistence.Connection,
- priorityClass=consts.Priority.Medium,
+ persistence=consts.ConstPersistence.Connection,
+ priorityClass=consts.ConstPriority.Medium,
targetFilename=None,
userData=None,
@@ -1843,10 +1833,10 @@
@note: for other params see L{putDir}
@note: to upload multiple items at once pass a dict for each item containig the following members:
- - RequestType: L{consts.RequestType.PutData}, L{consts.RequestType.PutFile} or L{consts.RequestType.PutRedirect}
- - Data: if requestType is L{consts.RequestType.PutData}, data to upload
- - Filename: if requestType is L{consts.RequestType.PutFile}, filepath of the file to upload
- - TargetURI: if requestType is L{consts.RequestType.PutRedirect}, uri to redirect to
+ - RequestType: L{consts.ConstRequestType.PutData}, L{consts.ConstRequestType.PutFile} or L{consts.ConstRequestType.PutRedirect}
+ - Data: if requestType is L{consts.ConstRequestType.PutData}, data to upload
+ - Filename: if requestType is L{consts.ConstRequestType.PutFile}, filepath of the file to upload
+ - TargetURI: if requestType is L{consts.ConstRequestType.PutRedirect}, uri to redirect to
- Name: name under wich the item will be accesible via freenet
- Metadata.ContentType: (optional) may be passed as 'ContentType'
@@ -1857,7 +1847,7 @@
@todo: EarlyEncode and GetCHKOnly message params not implemented
"""
return self.clientPut(
- consts.RequestType.PutMultiple,
+ consts.ConstRequestType.PutMultiple,
uri,
userData,
persistentUserData,
@@ -1873,8 +1863,8 @@
DontCompress=dontCompress,
Persistence=persistence,
PriorityClass=priorityClass,
- UploadFrom=consts.UploadFrom.Disk,
- Verbosity=consts.Verbosity.ReportProgress | consts.Verbosity.ReportCompression,
+ UploadFrom=consts.ConstUploadFrom.Disk,
+ Verbosity=consts.ConstVerbosity.ReportProgress | consts.ConstVerbosity.ReportCompression,
)
@@ -1883,8 +1873,8 @@
uri,
targetKey,
maxRetries=None,
- persistence=consts.Persistence.Connection,
- priorityClass=consts.Priority.Medium,
+ persistence=consts.ConstPersistence.Connection,
+ priorityClass=consts.ConstPriority.Medium,
userData=None,
persistentUserData='',
):
@@ -1892,21 +1882,21 @@
@param uri: (L{key.KSK}) to insert as redirect
@param targetKey: (key.KeyBase) key to redirect to
@param maxRetries: (int) maximum number of tretries or -1 to leave the decission up to the node
- @param persistence: (L{consts.Persistence}) of the request
- @param priorityClass: (L{consts.Priority}) priority of the request
+ @param persistence: (L{consts.ConstPersistence}) of the request
+ @param priorityClass: (L{consts.ConstPriority}) priority of the request
@param persistentUserData: (str) persistent data to be assosiated to the request
@param userData: (any) any data to be associated to the request at runtime
@return: (str) request identifier
"""
return self.clientPut(
- consts.RequestType.PutRedirect,
+ consts.ConstRequestType.PutRedirect,
uri,
userData,
persistentUserData,
Persistence=persistence,
PriorityClass=priorityClass,
TargetURI=targetKey,
- UploadFrom=consts.UploadFrom.Redirect,
+ UploadFrom=consts.ConstUploadFrom.Redirect,
)
########################################################
@@ -1917,7 +1907,7 @@
def getRequest(self, requestIdentifier):
"""Returns a (initial) message, given its identifier
@param requestIdentifier: identifier of the message
- @return: L{message.Message}
+ @return: L{message.MsgMessage}
"""
return self._requests[requestIdentifier]
@@ -1933,25 +1923,25 @@
"""Modifies a request
@param requestIdentifier: identifier of the request to modify
@param persistentUserData: (str) persistent user data or None
- @param priorityClass: (L{consts.Priority}) new priority or None
+ @param priorityClass: (L{consts.ConstPriority}) new priority or None
@note: you can use this method to modify get / put related requests
All attempts to modify other requests will fail
@note: a RequestModified event is triggered as soon as the request has actually been modified
- @note: you can not change the priority of requests with Persistence=L{consts.Persistence.Connection}.
+ @note: you can not change the priority of requests with Persistence=L{consts.ConstPersistence.Connection}.
All attempts to do so are ignored. Too bad, but doing so is not implemented in the client protocol.
@todo: currently we ignore any attempts to change priority class for requests with persistence == connection
Fcp does not provide means to do so.
"""
initialRequest = self._requests[requestIdentifier]
- if not initialRequest['RequestType'] & (consts.RequestType.MaskGet | consts.RequestType.MaskPut):
+ if not initialRequest['RequestType'] & (consts.ConstRequestType.MaskGet | consts.ConstRequestType.MaskPut):
raise ValueError('Can not modify request: %s' % initialRequest.name)
#FIX: [0002083]
# no way to change priority for non-persistent requests..this is simply not implemented in the protocol
# persistentUserData is ok, priority can not be changed. no idea how to handle this.
- if initialRequest['Persistence'] == consts.Persistence.Connection:
+ if initialRequest['Persistence'] == consts.ConstPersistence.Connection:
modified = {}
#if priorityClass is not None:
# raise ValueError('Can not modify priority of requests with Persistence=connection')
@@ -1959,14 +1949,14 @@
if persistentUserData is not None:
initialRequest['PersistentUserData'] = persistentUserData
initialRequest['ClientToken'] = initialRequest.updatePersistentParams()
- modified[consts.RequestModified.PersistentUserData] = None
+ modified[consts.ConstRequestModified.PersistentUserData] = None
initialRequest['Modified'] = modified
self.events.RequestModified(initialRequest)
return
#/FIX: [0002083]
- msg = message.ModifyPersistentRequest(
+ msg = message.MsgModifyPersistentRequest(
Identifier=initialRequest['Identifier'],
Global=False,
)
@@ -1984,10 +1974,10 @@
@param requestIdentifier: (str) identifier of the request to remove
"""
initialRequest = self._requests[requestIdentifier]
- initialRequest['RequestStatus'] |= consts.RequestStatus.Removed | consts.RequestStatus.Completed
- if initialRequest['RequestType'] & (consts.RequestType.MaskGet | consts.RequestType.MaskPut):
+ initialRequest['RequestStatus'] |= consts.ConstRequestStatus.Removed | consts.ConstRequestStatus.Completed
+ if initialRequest['RequestType'] & (consts.ConstRequestType.MaskGet | consts.ConstRequestType.MaskPut):
self.sendMessage(
- message.RemoveRequest(
+ message.MsgRemoveRequest(
Global=False,
Identifier=requestIdentifier,
)
@@ -2012,7 +2002,7 @@
@param giveOpennetRef: if True, the opennet reference is retuned instead of the darknet
"""
self.sendMessage(
- message.GetNode(
+ message.MsgGetNode(
WithPrivate=withPrivate,
WithVolatile=withVolatile,
GiveOpennetRef=giveOpennetRef,
@@ -2025,7 +2015,7 @@
@param identity: identity of the peer to request information for
"""
self.sendMessage(
- message.ListPeer(
+ message.MsgListPeer(
NodeIdentifier=identity,
)
)
@@ -2039,7 +2029,7 @@
@note: listPeerNotes() is only available for darknet nodes
"""
self.sendMessage(
- message.ListPeerNotes(
+ message.MsgListPeerNotes(
NodeIdentifier=identity
)
)
@@ -2054,7 +2044,7 @@
@event: EndListPeers(event, params).
"""
self.sendMessage(
- message.ListPeers(
+ message.MsgListPeers(
WithMetadata=withMetaData,
WithVolatile=withVolantile,
)
@@ -2071,7 +2061,7 @@
@note: you can only modify darknet peers
"""
msg = MessageEx(
- message.ModifyPeer(
+ message.MsgModifyPeer(
NodeIdentifier=identity,
)
)
@@ -2092,10 +2082,10 @@
@note: you can only modify notes of darknet peers
"""
self.sendMessage(
- message.ModifyPeerNote(
+ message.MsgModifyPeerNote(
NodeIdentifier=identity,
#NOTE: currently fcp supports only this one type
- PeerNoteType=consts.PeerNoteType.Private,
+ PeerNoteType=consts.ConstPeerNoteType.Private,
NoteText=note
)
)
@@ -2106,7 +2096,7 @@
@param identity: identity of the peer node to remove
"""
self.sendMessage(
- message.RemovePeer(
+ message.MsgRemovePeer(
NodeIdentifier=identity,
)
)
@@ -2122,11 +2112,11 @@
@param detailed: ...
[truncated message content] |