SF.net SVN: fclient: [432] trunk/sandbox/fcp2/client.py
Status: Pre-Alpha
Brought to you by:
jurner
|
From: <jU...@us...> - 2008-06-30 08:56:40
|
Revision: 432
http://fclient.svn.sourceforge.net/fclient/?rev=432&view=rev
Author: jUrner
Date: 2008-06-30 01:56:39 -0700 (Mon, 30 Jun 2008)
Log Message:
-----------
all methods now have a test case
++ some fixes
Modified Paths:
--------------
trunk/sandbox/fcp2/client.py
Modified: trunk/sandbox/fcp2/client.py
===================================================================
--- trunk/sandbox/fcp2/client.py 2008-06-30 08:55:28 UTC (rev 431)
+++ trunk/sandbox/fcp2/client.py 2008-06-30 08:56:39 UTC (rev 432)
@@ -431,7 +431,6 @@
## connection related methods
##
###############################################################
- #TESTED
def close(self):
"""Closes the client
@note: make shure to call close() when done with the client
@@ -441,7 +440,7 @@
)
self._close(msg)
- #TESTED
+
def closeNode(self):
"""Shuts down the freenet node"""
self.sendMessage(message.Shutdown())
@@ -461,7 +460,7 @@
pass
return nodeHello
- #TESTED
+
def isOpen(self):
"""Checks if the clients connection is open
@return: (bool) True if so, False otherwise
@@ -469,7 +468,7 @@
return self.ioHandler.isOpen()
- #TESTED
+
def iterConnect(self, host=DefaultFcpHost, port=DefaultFcpPort, duration=20, timeout=0.5):
"""Iterator to stablish a connection to a freenet node
@param host: (str) host of th node
@@ -532,14 +531,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
@@ -548,7 +547,7 @@
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}
@@ -556,7 +555,7 @@
return consts.Logger.Client.getEffectiveLevel()
- #TESTED
+
def setDebugVerbosity(self, debugVerbosity):
"""Sets the verbosity level of the client
@param debugVerbosity: L{consts.DebugVerbosity}
@@ -564,7 +563,7 @@
consts.Logger.Client.setLevel(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')
@@ -581,7 +580,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
@@ -598,7 +597,6 @@
## runtime related methods
##
#########################################################
- #TESTED
def handleMessage(self, msg):
"""Handles a message from the freenet node
@param msg: (Message) to handle
@@ -952,19 +950,16 @@
self.events.RequestModified(initialRequest)
return True
-
- # don't handle PersistentRequestRemoved. instead we handle it in Get/PutFailed
- # ??? why ???
- #
- #elif msg == message.PersistentRequestRemoved:
- # if initialRequest is None:
- # return False
+ #NOTE: fcp sends a GetFailed / PutFailed if the request was still running (code=canceled)
+ elif msg == message.PersistentRequestRemoved:
+ if initialRequest is None:
+ return False
- # initialRequest['RequestStatus'] |= consts.RequestStatus.Removed
- # self._finalizeRequest(msg, initialRequest, self.events.RequestRemoved)
- # return True
-
-
+ initialRequest['RequestStatus'] |= consts.RequestStatus.Removed | consts.RequestStatus.Completed | consts.RequestStatus.RemovedFromQueue
+ del self._requests[requestIdentifier]
+ self.events.RequestRemoved(initialRequest)
+ return True
+
elif msg == message.SimpleProgress:
if initialRequest is None:
return False
@@ -1103,16 +1098,14 @@
if initialRequest is None:
return False
- #TODO:no idea if the node may pass uris with prefixes like 'freenet:'... strip it anyways
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)
-
- initialRequest['PrivateKey'] = insertURI
- initialRequest['PublicKey'] = requestURI
+ initialRequest['InsertURI'] = insertURI
+ initialRequest['RequestURI'] = requestURI
initialRequest['RequestStatus'] |= consts.RequestStatus.Success
self._finalizeRequest(msg, initialRequest, self.events.KeypairGenerated)
return True
@@ -1129,7 +1122,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}
@@ -1153,7 +1146,7 @@
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
@@ -1196,7 +1189,7 @@
if msg == message.ClientSocketDied:
break
- #TESTED
+
def sendMessage(self, msg):
"""Sends a message to freenet
@param msg: (L{message.Message}) message to send
@@ -1225,7 +1218,6 @@
## config related methods
##
#########################################################
- #TESTED
def getConfig(self,
withCurrent=True,
withDefaults=True,
@@ -1253,7 +1245,7 @@
)
- #TESTED
+
def modifyConfig(self, params):
"""Modifies node configuration values
@param params: (dict) containing parameters to modify
@@ -1268,7 +1260,7 @@
##
########################################################
def clientGet(self,
- key,
+ uri,
requestType,
userData,
persistentUserData,
@@ -1276,7 +1268,7 @@
**messageParams
):
"""Requests a key from the node
- @param key: (L{key.KeyBase}) key to request
+ @param uri: (L{key.KeyBase}) key to request
@param requestType: (L{consts.RequestType}) 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
@@ -1286,7 +1278,7 @@
@return: (str) request identifier
"""
- msg = message.ClientGet(URI=key)
+ msg = message.ClientGet(URI=uri)
for paramName, value in messageParams.items():
if value is not None:
msg[paramName] = value
@@ -1302,9 +1294,9 @@
return msg['Identifier']
- #TESTED
+
def getData(self,
- key,
+ uri,
allowedMimeTypes=None,
binaryBlob=False,
@@ -1320,7 +1312,7 @@
):
"""Requests datae from the node
- @param key: (L{key.KeyBase}) key to request
+ @param uri: (L{key.KeyBase}) key to request
@param allowedMimeTypes: (str) list of allowed mime types
@param binaryBlob: (bool) if True, the file is retrieved as binary blob file
@@ -1346,7 +1338,7 @@
as soon as it completes or failes
"""
return self.clientGet(
- key,
+ uri,
consts.RequestType.GetData,
userData,
persistentUserData,
@@ -1368,9 +1360,9 @@
)
- #TESTED
+
def getFile(self,
- key,
+ uri,
filename,
allowedMimeTypes=None,
@@ -1388,7 +1380,7 @@
):
"""Requests a file from the node
- @param key: (L{key.KeyBase}) key to request
+ @param uri: (L{key.KeyBase}) key to request
@param filename: (full path) filename to store the file to
@param allowedMimeTypes: (str) list of allowed mime types
@@ -1415,7 +1407,7 @@
as soon as it completes or failes
"""
return self.clientGet(
- key,
+ uri,
consts.RequestType.GetFile,
userData,
persistentUserData,
@@ -1438,9 +1430,9 @@
)
- #TESTED
+
def getKeyInfo(self,
- key,
+ uri,
dsOnly=False,
ignoreDS=False,
@@ -1453,7 +1445,7 @@
):
"""Requests info about a key
- @param key: (L{key.KeyBase}) key to request
+ @param uri: (L{key.KeyBase}) key to request
@param dsOnly: if True, retrieves the file from the local data store only
@param ignoreDS: If True, ignores the local data store
@@ -1476,7 +1468,7 @@
"""
# how to retrieve meta info about a key? ...idea is to provoke a GetFailed (TooBig)
return self.clientGet(
- key,
+ uri,
consts.RequestType.GetKeyInfo,
userData,
persistentUserData,
@@ -1496,8 +1488,8 @@
)
- #TESTED
- def subscribeUSK(self, key, dontPoll=True):
+
+ def subscribeUSK(self, uri, dontPoll=True):
"""Asks the node to notify the client when an USK is updated
@param key: (L{key.USK}) key to subscribe to
@param dontPoll: if True, does whatever ???
@@ -1509,7 +1501,7 @@
@todo: looks like USK subscribes will persist untill connection is closed. Can they be removed somehow?
"""
msg = message.SubscribeUSK(
- URI=key,
+ URI=uri,
DontPoll=dontPoll,
)
self._registerRequest(msg, consts.RequestType.SubscribeUSK)
@@ -1525,7 +1517,7 @@
########################################################
def clientPut(self,
requestType,
- key,
+ uri,
userData,
persistentUserData,
data=None,
@@ -1534,7 +1526,7 @@
):
"""Uploads to the node
@param requestType: (L{consts.RequestType}). Can be PutData, PutDir or PutMultiple
- @param key: (str) key or Uri
+ @param uri: (str) key or Uri
@param data: (str) for L{consts.RequestType.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
@@ -1571,12 +1563,12 @@
msgClass = message.ClientPutComplexDir
else:
raise ValueError('Unsupported request type')
- msg = msgClass(URI=key)
+ msg = msgClass(URI=uri)
# add params
- if key.KeyType == consts.KeyType.CHK:
- if key.filename is not None:
- msg['TargetFilename'] = key.filename
+ if uri.KeyType == consts.KeyType.CHK:
+ if uri.filename is not None:
+ msg['TargetFilename'] = uri.filename
for param, value in msgParams.items():
if value is not None:
msg[param] = value
@@ -1664,9 +1656,9 @@
self.sendMessage(msg)
return msg['Identifier']
- #TESTED
+
def putData(self,
- key,
+ uri,
data,
contentType=None,
@@ -1680,7 +1672,7 @@
):
"""Uploads data
- @param key: (L{key.KeyBase}) key under wich to upload the data
+ @param uri: (L{key.KeyBase}) key under wich to upload the data
@param data: (bytes) data to upload
@param contentType: (str) content type. If not specified, the node will guess the content type
@@ -1695,7 +1687,7 @@
@event: (L{events.Events.RequestFailed}) triggered when the request failes
@event: (L{events.Events.RequestFetchable}) triggered as soon as the request is fetchable
@event: (L{events.Events.RequestCompressionStarted}) triggered when the request is about to be compressed
- @event: (L{events.Events.RequestCompressionComopleted}) triggered as soon as compressing of the request is completed
+ @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
the data can be retreieved. The key can be accessed as 'URI' member of the request as soon
@@ -1706,7 +1698,7 @@
"""
return self.clientPut(
consts.RequestType.PutData,
- key,
+ uri,
userData,
persistentUserData,
data=data,
@@ -1726,114 +1718,15 @@
Verbosity=consts.Verbosity.ReportProgress | consts.Verbosity.ReportCompression,
)
- #TESTED
- def putRedirect(self,
- key,
- targetKey,
- maxRetries=None,
- persistence=consts.Persistence.Connection,
- priorityClass=consts.Priority.Medium,
- userData=None,
- persistentUserData='',
- ):
- """Uploads a redirect to another key
- @param key: (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 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,
- key,
- userData,
- persistentUserData,
- Persistence=persistence,
- PriorityClass=priorityClass,
- TargetURI=targetKey,
- UploadFrom=consts.UploadFrom.Redirect,
- )
- #########################################################
- #########################################################
- #########################################################
- #########################################################
- #########################################################
-
- #CHK
- def chkPutData(self,
- data,
-
- contentType=None,
- dontCompress=None,
- maxRetries=None,
- persistence=consts.Persistence.Connection,
- priorityClass=consts.Priority.Medium,
- targetFilename=None,
-
- userData=None,
- persistentUserData='',
- ):
- """Uploads data
- @param data: (bytes) data to upload
-
- @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 targetFilename: (str) filename to append to the key (may not contain slashes)
-
- @param userData: any non persistent data to associate to the request
- @param persistentUserData: any string to associate to the request as persistent data
-
- @event: (L{events.Events.RequestCompleted}) triggered when the request is complete
- @event: (L{events.Events.RequestFailed}) triggered when the request failes
- @event: (L{events.Events.RequestFetchable}) triggered as soon as the request is fetchable
- @event: (L{events.Events.RequestCompressionStarted}) triggered when the request is about to be compressed
- @event: (L{events.Events.RequestCompressionComopleted}) 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
- 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.
-
- @todo: EarlyEncode and GetCHKOnly message params not implemented
- """
- return self.clientPut(
- consts.RequestType.PutData,
- consts.KeyType.CHK,
-
- data=data,
- persistentUserData=persistentUserData,
- userData=userData,
-
- # fcp params
- ContentType=contentType,
- DataLength=len(data),
- #EarlyEncode='false',
- #GetCHKOnly='false',
- Global=False,
- Identifier=None,
- MaxRetries=maxRetries,
- DontCompress=dontCompress,
- Persistence=persistence,
- PriorityClass=priorityClass,
- TargetFilename=targetFilename,
- UploadFrom=consts.UploadFrom.Direct,
- Verbosity=consts.Verbosity.ReportProgress | consts.Verbosity.ReportCompression,
- )
-
-
- def chkPutDir(self,
+ def putDir(self,
+ uri,
directory,
allowUnreadableFiles=False,
-
+ defaultName=None,
contentType=None,
+
dontCompress=None,
- defaultName=None,
maxRetries=None,
persistence=consts.Persistence.Connection,
priorityClass=consts.Priority.Medium,
@@ -1845,11 +1738,14 @@
):
"""Uploads the contents of a directory
+ @param uri: (L{key.KeyBase}) key under wich to upload the directory
@param directory: (str) directory to upload
@param allowUnreadableFiles: if True, unreadable files in the directory are ignored, if False the request fails
- if it encounters an unreadavle file.
+ if it encounters an unreadavle file
+ @param defaultName: name of the directory item that should be displayed when accessing the directory
+ without any filename appended to the uri
- @note: for other params see L{chkPutData}
+ @note: for other params see L{putData}
@note: once uploaded, items of the directory can be accessed under Key/MyItemName/MyItemSubname
@todo: EarlyEncode and GetCHKOnly message params not implemented
@@ -1857,18 +1753,15 @@
"""
return self.clientPut(
consts.RequestType.PutDir,
- consts.KeyType.CHK,
-
- data=None,
- persistentUserData=persistentUserData,
- userData=userData,
-
+ uri,
+ userData,
+ persistentUserData,
+
# fcp params
- Filename=directory,
- AllowUnreadableFiles=allowUnreadableFiles,
ContentType=contentType,
DefaultName=defaultName,
#EarlyEncode='false',
+ Filename=directory,
#GetCHKOnly='false',
Global=False,
Identifier=None,
@@ -1876,44 +1769,42 @@
DontCompress=dontCompress,
Persistence=persistence,
PriorityClass=priorityClass,
- TargetFilename=targetFilename,
UploadFrom=consts.UploadFrom.Disk,
Verbosity=consts.Verbosity.ReportProgress | consts.Verbosity.ReportCompression,
)
-
- def chkPutFile(self,
+
+ def putFile(self,
+ uri,
filename,
contentType=None,
dontCompress=None,
maxRetries=None,
persistence=consts.Persistence.Connection,
priorityClass=consts.Priority.Medium,
- targetFilename=None,
-
+
userData=None,
persistentUserData='',
):
"""Uploads a file
- @param filename: (bytes) data to upload
+ @param uri: (L{key.KeyBase}) key under wich to upload the file
+ @param filename: (str) file to upload
- @note: for other params see L{chkPutData}
+ @note: for other params see L{putData}
@todo: EarlyEncode and GetCHKOnly message params not implemented
"""
return self.clientPut(
consts.RequestType.PutFile,
- consts.KeyType.CHK,
-
- data=None,
- persistentUserData=persistentUserData,
- userData=userData,
-
+ uri,
+ userData,
+ persistentUserData,
+
# fcp params
- Filename=filename,
ContentType=contentType,
- #EarlyEncode='false',
+ #EarlyEncode='false',
+ Filename=filename,
#GetCHKOnly='false',
Global=False,
Identifier=None,
@@ -1921,18 +1812,14 @@
DontCompress=dontCompress,
Persistence=persistence,
PriorityClass=priorityClass,
- TargetFilename=targetFilename,
UploadFrom=consts.UploadFrom.Disk,
Verbosity=consts.Verbosity.ReportProgress | consts.Verbosity.ReportCompression,
)
-
-
- def chkPutMultiple(self,
+ def putMultiple(self,
+ uri,
items,
- allowUnreadableFiles=False,
- contentType=None,
defaultName=None,
dontCompress=None,
maxRetries=None,
@@ -1946,9 +1833,10 @@
):
"""Uploads multiple items at once to be retrievable under one key
+ @param uri: (L{key.KeyBase}) key under wich to upload the file
@param items: (list) list of items to upload
- @note: for other params see L{chkPutData}
+ @note: for other params see L{chkPutDir}
@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}
@@ -1966,16 +1854,12 @@
"""
return self.clientPut(
consts.RequestType.PutMultiple,
- consts.KeyType.CHK,
-
- data=None,
- persistentUserData=persistentUserData,
- userData=userData,
+ uri,
+ userData,
+ persistentUserData,
items=items,
-
+
# fcp params
- AllowUnreadableFiles=allowUnreadableFiles,
- ContentType=contentType,
DefaultName=defaultName,
#EarlyEncode='false',
#GetCHKOnly='false',
@@ -1985,132 +1869,42 @@
DontCompress=dontCompress,
Persistence=persistence,
PriorityClass=priorityClass,
- TargetFilename=targetFilename,
UploadFrom=consts.UploadFrom.Disk,
Verbosity=consts.Verbosity.ReportProgress | consts.Verbosity.ReportCompression,
)
- ########################################################
- ##
- ## SSK ClientPut related methods
- ##
- ########################################################
- def sskPutData(self,
- data,
- privateKey,
-
- contentType=None,
- dontCompress=None,
- maxRetries=None,
- persistence=consts.Persistence.Connection,
- priorityClass=consts.Priority.Medium,
- targetFilename=None,
-
- userData=None,
- persistentUserData='',
- ):
- """Uploads data that can be updated by the owner
- @param data: (bytes) data to upload
- @param privateKey: see: private key as generated by L{generateKeypair} + '/' + name
-
- @note: for other params see L{chkPutData}
- @note: use this method to upload updatable data. First you need to create a public / private
- keypair. The private key is used for uploading, the public key for retrieving the data.
- You should add a name to the keypairs like: "privateKey/MyData" and "publicKey/MyData".
- This may aswell be used to implement a basic edition scheme: "privateKey/MyEdition-0",
- "privateKey/MyEdition-1"
- """
- return self.clientPut(
- consts.RequestType.PutData,
- privateKey,
-
- data=data,
- persistentUserData=persistentUserData,
- userData=userData,
-
- # fcp params
- ContentType=contentType,
- DataLength=len(data),
-
- #EarlyEncode='false',
- #GetCHKOnly='false',
- Global=False,
- Identifier=None,
- MaxRetries=maxRetries,
- DontCompress=dontCompress,
- Persistence=persistence,
- PriorityClass=priorityClass,
- UploadFrom=consts.UploadFrom.Direct,
- Verbosity=consts.Verbosity.ReportProgress | consts.Verbosity.ReportCompression,
- )
-
- def sskPutDir(self):
- pass
- def sskPutFile(self):
- pass
-
- def sskPutMultiple(self):
- pass
-
- ########################################################
- ##
- ## USK ClientPut related methods
- ##
- ########################################################
- def uskPutData(self,
- data,
- privateKey,
-
- contentType=None,
- dontCompress=None,
+ def putRedirect(self,
+ uri,
+ targetKey,
maxRetries=None,
persistence=consts.Persistence.Connection,
priorityClass=consts.Priority.Medium,
- targetFilename=None,
-
userData=None,
- persistentUserData=''
+ persistentUserData='',
):
- """Uploads data
-
+ """Uploads a redirect to another key
+ @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 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.PutData,
- privateKey,
- #insertURI + 'foo/0/',
- userData=userData,
- persistentUserData=persistentUserData,
- data=data,
-
- # fcp params
- ContentType=contentType,
- DataLength=len(data),
- #EarlyEncode='false',
- #GetCHKOnly='false',
- Global=False,
- Identifier=None,
- MaxRetries=maxRetries,
- DontCompress=dontCompress,
- Persistence=persistence,
- TargetFilename=targetFilename,
- UploadFrom=consts.UploadFrom.Direct,
- Verbosity=consts.Verbosity.ReportProgress | consts.Verbosity.ReportCompression,
- )
-
- def uskPutDir(self):
- pass
+ consts.RequestType.PutRedirect,
+ uri,
+ userData,
+ persistentUserData,
+ Persistence=persistence,
+ PriorityClass=priorityClass,
+ TargetURI=targetKey,
+ UploadFrom=consts.UploadFrom.Redirect,
+ )
- def uskPutFile(self):
- pass
-
-
- def uskPutMultiple(self):
- pass
-
########################################################
##
## request related methods
@@ -2198,66 +1992,6 @@
del self._requests[requestIdentifier]
- def resendRequest(self, request):
- """Resends a request
- @param request: (L{message.Message})
- @return: (str) request identifier
-
- @note: you can use this method to resend get / put requests.All attempts to resend other requests
- will fail
- @note: actually a new request is created and registered. Todo so, the request passed is copied. If it is a persistent
- request, it will be removed. The new request will have FcInitTime reset and FcUserData amd FcPersistentUserData
- taken over from the old request
-
- @note: for SSK and USK puts, the private key is taken from request['PrivateKey']. Adjust private (and public
- key) if necessary
-
- @todo: reset init time or not? Currently it is not reset.
- """
- requestType = request.get('RequestType', consts.RequestType.Null)
- if not requestType & (consts.RequestType.MaskGet | consts.RequestType.MaskPut):
- raise ValueError('Can not resend request: %s' % request.name)
-
- # we don't know what UserData may be, so back it up before copying
- oldIdentifier = request['Identifier']
- oldUserData, request['UserData'] = request['UserData'], None
- newRequest = copy.deepcopy(request)
-
- # reset key if necessary
- if requestType & consts.RequestType.MaskPut:
- requestKey = key.KeyBase.fcpToPython(request['URI'])
- if requestKey is None:
- raise ValueError('Ups, URI of the request seems not to be valid')
-
- if requestKey.KeyType == consts.KeyType.CHK:
- newRequest['URI'] = consts.KeyType.CHK
- elif requestKey.KeyType == consts.KeyType.SSK:
- newRequest['URI'] = request['PrivateKey']
- if requestKey.filename:
- newRequest['URI'] += '/' + requestKey.filename
- elif requestKey.KeyType == consts.KeyType.USK:
- newRequest['URI'] = request['PrivateKey']
- if requestKey.filename:
- newRequest['URI'] += '/' + requestKey.filename
-
-
- filenameCollision = newRequest.get('FilenameCollision', None)
- self._registerRequest(
- newRequest,
- requestType,
- filenameCollision= None if filenameCollision is None else filenameCollision & consts.FilenameCollision.MaskHandle,
- #initTime=time.time(),
- persistentUserData=newRequest['PersistentUserData'],
- userData=oldUserData,
- )
-
- if oldIdentifier in self._requests:
- request['UserData'] = oldUserData
- self.removeRequest(request['Identifier'])
-
- self.sendMessage(newRequest)
- return newRequest['Identifier']
-
########################################################
##
## Peer related methods
@@ -2402,7 +2136,7 @@
@return: (L{message.FCPPluginMessage})
@note: the client does not keep track of messages send to a plugin, because the plugin
- may or may not return. If the plugin sends a reply, a L{events.PluginMessage} is triggered.
+ may or may not return. If the plugin sends a reply, a L{events.Events.PluginMessage} is triggered.
If something goes wrong, L{events.Events.ProtocolError} or an is L{events.Events.IdentifierCollision}
is triggered. Use the identifier passed to identify responses.
@@ -2434,7 +2168,7 @@
@event: L{events.Events.KeypairGenerated} triggered as soon as the request is complete
"""
if keypairType not in (consts.KeyType.SSK, consts.KeyType.USK):
- raise ValueError('keypairType must be %s or %s' % (consts.KeyType.SSK, consts.KeyType.USK))
+ raise ValueError('keypairType must be SSK or USK')
requestType = consts.RequestType.GenerateSSKKeypair if keypairType == consts.KeyType.SSK else consts.RequestType.GenerateUSKKeypair
msg = message.GenerateSSK()
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|