SF.net SVN: fclient:[698] trunk/fclient/src/fclient/lib/fcp2
Status: Pre-Alpha
Brought to you by:
jurner
|
From: <jU...@us...> - 2008-07-20 19:57:34
|
Revision: 698
http://fclient.svn.sourceforge.net/fclient/?rev=698&view=rev
Author: jUrner
Date: 2008-07-20 19:57:42 +0000 (Sun, 20 Jul 2008)
Log Message:
-----------
removed RequestType param - no longer needed
Modified Paths:
--------------
trunk/fclient/src/fclient/lib/fcp2/__init__.py
trunk/fclient/src/fclient/lib/fcp2/client.py
trunk/fclient/src/fclient/lib/fcp2/consts.py
trunk/fclient/src/fclient/lib/fcp2/message.py
trunk/fclient/src/fclient/lib/fcp2/test/test_client.py
Modified: trunk/fclient/src/fclient/lib/fcp2/__init__.py
===================================================================
--- trunk/fclient/src/fclient/lib/fcp2/__init__.py 2008-07-20 17:55:11 UTC (rev 697)
+++ trunk/fclient/src/fclient/lib/fcp2/__init__.py 2008-07-20 19:57:42 UTC (rev 698)
@@ -17,12 +17,11 @@
from .client import Client
from .config import (Config, ConfigDataType, ConfigItem, ConfigKeySep, ConfigValueClass)
from .consts import (ConstByteAmountPostfix, ConstConnectReason, ConstDebugVerbosity, ConstDisconnectReason,
- ConstFetchError, ConstInsertError, ConstKeyType, ConstLogMessages,
- ConstLogger, ConstMessage, ConstPeerNodeStatus, ConstPeerNoteType, ConstPersistence,
- ConstPriority, ConstProtocolError, ConstRequestModified, ConstRequestStatus,
- ConstRequestType, ConstReturnType, ConstTimeDeltaPostfix, ConstUploadFrom, ConstVerbosity,
- Error, ErrorIOBroken, ErrorIOClosed, ErrorIOConnectFailed, ErrorIOTimeout, ErrorMessageParse,
- FcpFalse, FcpTrue)
+ ConstFetchError, ConstInsertError, ConstKeyType, ConstLogMessages, ConstLogger, ConstMessage,
+ ConstPeerNodeStatus, ConstPeerNoteType, ConstPersistence, ConstPriority, ConstProtocolError,
+ ConstRequestModified, ConstRequestStatus, ConstPutMultiple, ConstReturnType,
+ ConstTimeDeltaPostfix, ConstUploadFrom, ConstVerbosity, Error, ErrorIOBroken, ErrorIOClosed,
+ ErrorIOConnectFailed, ErrorIOTimeout, ErrorMessageParse, FcpFalse, FcpTrue)
from .key import (Key, KeyCHK, KeyKSK, KeySSK, KeyTypesAll, KeyUSK, TypeKey, base64UrlsaveDecode, keyNormkey)
from .message import (MessagesAll, MsgAddPeer, MsgAllData, MsgClientDisconnected, MsgClientGet, MsgClientHello,
MsgClientPut, MsgClientPutComplexDir, MsgClientPutDiskDir, MsgClientSocketDied,
Modified: trunk/fclient/src/fclient/lib/fcp2/client.py
===================================================================
--- trunk/fclient/src/fclient/lib/fcp2/client.py 2008-07-20 17:55:11 UTC (rev 697)
+++ trunk/fclient/src/fclient/lib/fcp2/client.py 2008-07-20 19:57:42 UTC (rev 698)
@@ -352,7 +352,6 @@
def registerRequest(self,
msg,
- requestType,
userData=None,
identifier=None,
initTime=None,
@@ -362,7 +361,6 @@
):
"""Registers a request
@param msg: message to register
- @param requestType: (L{consts.ConstRequestType}) type of request to register
@param handleFilenameCollision: (bool) if True, the file is automatically renamed if "filename" collides
with a file object already present on disk
@param identifier: (str) identifier of the request or None to create a new one
@@ -381,9 +379,8 @@
#TODO: keep an eye on additional params, they may collide with Fcp parameters
msg['Identifier'] = self.newIdentifier(identifiers=self._requests) if identifier is None else identifier
- msg['RequestType'] = requestType
msg['InitTime'] = time.time() if initTime is None else initTime
- if requestType & consts.ConstRequestType.MaskGet:
+ if msg == message.MsgClientGet:
msg['HandleFilenameCollision'] = handleFilenameCollision
msg['HandlePermanentRedirect'] = handlePermanentRedirect
msg['UserData'] = userData
@@ -391,17 +388,17 @@
msg['ClientToken'] = ''
msg.updatePersistentParams()
- elif requestType & consts.ConstRequestType.MaskPut:
+ elif msg == message.MsgClientPut or msg == message.MsgClientPutDiskDir or msg == message.MsgClientPutComplexDir:
msg['UserData'] = userData
msg['PersistentUserData'] = persistentUserData
msg['ClientToken'] = ''
msg.updatePersistentParams()
- elif requestType & consts.ConstRequestType.MaskGenerateKeypair:
+ elif msg == message.MsgGenerateSSK:
pass
- elif requestType & consts.ConstRequestType.SubscribeUSK:
+ elif msg == message.MsgSubscribeUSK:
msg['UserData'] = userData
- elif requestType & consts.ConstRequestType.PluginInfo:
+ elif msg == message.MsgGetPluginInfo:
pass
else:
raise ValueError('Can not register request: ' + msg.name)
@@ -827,7 +824,7 @@
# 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.ConstRequestType.GetData:
+ if initialRequest['ReturnType'] == consts.ConstReturnType.Direct and not initialRequest['IsGetKeyInfo']:
if initialRequest['Persistence'] != consts.ConstPersistence.Connection:
self.sendMessage(
message.MsgGetRequestStatus(
@@ -866,7 +863,7 @@
return True
# check if it is one of our requests for key information
- if code == consts.ConstFetchError.TooBig and initialRequest['RequestType'] & consts.ConstRequestType.GetKeyInfo:
+ if code == consts.ConstFetchError.TooBig and initialRequest['IsGetKeyInfo']:
initialRequest['MetadataContentType'] = msg.get('ExpectedMetadata.ContentType', '')
initialRequest['DataLength'] = msg.get('ExpectedDataLength', -1)
initialRequest['RequestStatus'] |= consts.ConstRequestStatus.Success
@@ -1097,8 +1094,7 @@
insertURI = msg['InsertURI']
requestURI = msg['RequestURI']
-
- if initialRequest['RequestType'] & consts.ConstRequestType.GenerateUSKKeypair:
+ if initialRequest['KeyPairType'] == consts.ConstKeyType.USK:
insertURI = key.KeyUSK(insertURI.keyData, docName=insertURI.docName)
insertURI = key.KeyUSK(insertURI.keyData, docName=insertURI.docName)
requestURI = key.KeyUSK(requestURI.keyData, docName=requestURI.docName)
@@ -1266,46 +1262,6 @@
## ClientGet related methods
##
########################################################
- def clientGet(self,
- uri,
- requestType,
- userData,
- persistentUserData,
- handleFilenameCollision=False,
- handlePermanentRedirect=False,
- **messageParams
- ):
- """Requests a key from the node
- @param uri: (L{key._KeyBase}) key to request
- @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 handleFilenameCollision: (bool) if True, the file is automatically renamed if "filename" collides
- with a file object already present on disk
- @param handlePermanentRedirect: (bool) if True, permanent redirect are handled automatically. for example USK@.../-1
- will look for the current edition. if handlePermanentRedirect is True, the request is automatically resend to retrieve the current edition
- @param messageParams: keyword arguments to pass along with the ClientGet message (uppercase first letter!!).
- If the value of a keyword is None, it is ignored.
-
- @return: (str) request identifier
- """
- msg = message.MsgClientGet(URI=uri)
- for paramName, value in messageParams.items():
- if value is not None:
- msg[paramName] = value
-
- self.registerRequest(
- msg,
- requestType,
- handleFilenameCollision=handleFilenameCollision,
- handlePermanentRedirect=handlePermanentRedirect,
- persistentUserData=persistentUserData,
- userData=userData,
- )
- self.sendMessage(msg)
- return msg['Identifier']
-
-
def getData(self,
uri,
@@ -1351,28 +1307,31 @@
@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.ConstRequestType.GetData,
- userData,
- persistentUserData,
- handlePermanentRedirect=handlePermanentRedirect,
-
- # Fcp params
- AllowedMimeTypes = allowedMimeTypes,
+ msg = message.MsgClientGet(
+ URI=uri,
BinaryBlob=binaryBlob,
Global=False,
DSOnly=dsOnly,
Identifier=None,
IgnoreDS=ignoreDS,
- MaxRetries = maxRetries,
- MaxSize = maxSize,
Persistence=persistence,
PriorityClass=priorityClass,
ReturnType=consts.ConstReturnType.Direct,
Verbosity=consts.ConstVerbosity.ReportProgress,
)
-
+ if allowedMimeTypes is not None: msg['AllowedMimeTypes'] = allowedMimeTypes
+ if maxRetries is not None: msg['MaxRetries'] = maxRetries
+ if maxSize is not None: msg['MaxSize'] = maxSize
+
+ self.registerRequest(
+ msg,
+ handlePermanentRedirect=handlePermanentRedirect,
+ persistentUserData=persistentUserData,
+ userData=userData,
+ )
+ self.sendMessage(msg)
+ return msg['Identifier']
+
def getFile(self,
uri,
@@ -1424,31 +1383,34 @@
@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.ConstRequestType.GetFile,
- userData,
- persistentUserData,
- handleFilenameCollision=handleFilenameCollision,
- handlePermanentRedirect=handlePermanentRedirect,
-
- # Fcp params
- AllowedMimeTypes = allowedMimeTypes,
- BinaryBlob=binaryBlob,
+ msg = message.MsgClientGet(
+ URI=uri,
Filename=filename,
+ BinaryBlob=binaryBlob,
Global=False,
DSOnly=dsOnly,
Identifier=None,
IgnoreDS=ignoreDS,
- MaxRetries = maxRetries,
- MaxSize = maxSize,
- Persistence=persistence,
+ Persistence=persistence,
PriorityClass=priorityClass,
- ReturnType=consts.ConstReturnType.Disk,
+ ReturnType=consts.ConstReturnType.Direct,
Verbosity=consts.ConstVerbosity.ReportProgress,
- )
+ )
+ if allowedMimeTypes is not None: msg['AllowedMimeTypes'] = allowedMimeTypes
+ if maxRetries is not None: msg['MaxRetries'] = maxRetries
+ if maxSize is not None: msg['MaxSize'] = maxSize
+ self.registerRequest(
+ msg,
+ handleFilenameCollision=handleFilenameCollision,
+ handlePermanentRedirect=handlePermanentRedirect,
+ persistentUserData=persistentUserData,
+ userData=userData,
+ )
+ self.sendMessage(msg)
+ return msg['Identifier']
+
def getKeyInfo(self,
uri,
@@ -1488,27 +1450,33 @@
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.ConstRequestType.GetKeyInfo,
- userData,
- persistentUserData,
- handlePermanentRedirect=handlePermanentRedirect,
-
- # Fcp params
+ msg = message.MsgClientGet(
+ URI=uri,
Global=False,
DSOnly=dsOnly,
Identifier=None,
IgnoreDS=ignoreDS,
- MaxRetries = maxRetries,
MaxSize=self.MaxSizeKeyInfo,
Persistence=persistence,
PriorityClass=priorityClass,
- ReturnType=consts.ConstReturnType.Nothing,
+ ReturnType=consts.ConstReturnType.Direct,
Verbosity=consts.ConstVerbosity.ReportProgress,
+
+ IsGetKeyInfo=True,
)
-
-
+ if maxRetries is not None: msg['MaxRetries'] = maxRetries
+
+
+ self.registerRequest(
+ msg,
+ handlePermanentRedirect=handlePermanentRedirect,
+ persistentUserData=persistentUserData,
+ userData=userData,
+ )
+ self.sendMessage(msg)
+ return msg['Identifier']
+
+
def subscribeUSK(self, uri, dontPoll=True):
"""Asks the node to notify the client when an USK is updated
@param uri: (L{key.KeyUSK}) key to subscribe to
@@ -1535,158 +1503,6 @@
## CHK ClientPut related methods
##
########################################################
- def clientPut(self,
- requestType,
- uri,
- userData=None,
- persistentUserData=None,
- data=None,
- items=None,
- **msgParams
- ):
- """Uploads to the node
- @param requestType: (L{consts.ConstRequestType}). Can be PutData, PutDir or PutMultiple
- @param uri: (str) key or Uri
- @param data: (str) for L{consts.ConstRequestType.PutData} data to upload or None
- @param persistentUserData: (str) persistent data to be assosiated to the requestor None
- @param userData: (any) any data to be associated to the request at runtime or None
- @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.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'
-
- All items will be accessible under one single key as 'Uri/Name'. The default item (the item when
- only 'Uri' is requested from freenet) is always the first item in the list.
- """
-
- #FIX: enables passing params as python keywords
- contentType = msgParams.get('ContentType', None)
- if contentType is not None:
- del msgParams['ContentType']
- msgParams['Metadata.ContentType'] = contentType
-
- # find out wich message to use
- 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)
-
- #
- if uri.KeyType == consts.ConstKeyType.CHK:
- if uri.tail is not None:
- raise ValueError('no tail allowed')
- if uri.filename is not None:
- msg['TargetFilename'] = uri.docName
- elif uri.KeyType == consts.ConstKeyType.SSK:
- if uri.tail is not None:
- raise ValueError('no tail allowed')
- elif uri.KeyType == consts.ConstKeyType.USK:
- if uri.tail is not None:
- raise ValueError('no tail allowed')
-
- # add params
- for param, value in msgParams.items():
- if value is not None:
- msg[param] = value
-
- if data is not None:
- if not requestType & consts.ConstRequestType.PutData:
- raise ValueError('Data can only be passed along with putData uploads')
- msg.data = data
-
- if items is not None:
- if not requestType & consts.ConstRequestType.PutMultiple:
- raise ValueError('Items can only be passed along with PutMultiple uploads')
-
- uploadTypeMapping = {
- consts.ConstRequestType.PutData: consts.ConstUploadFrom.Direct,
- consts.ConstRequestType.PutFile: consts.ConstUploadFrom.Disk,
- consts.ConstRequestType.PutRedirect: consts.ConstUploadFrom.Redirect,
- }
- # requestType --> [(allowedParam: boolParamIsRequired), ...]
- paramMapping = {
- consts.ConstRequestType.PutData: [
- ('Name', True),
- ('Data', True),
- ('ContentType', False),
- ],
- consts.ConstRequestType.PutFile: [
- ('Name', True),
- ('Filename', True),
- ('Metadata.ContentType', False),
- ],
- consts.ConstRequestType.PutRedirect: [
- ('Name', True),
- ('TargetURI', True),
- ],
- }
-
- data = ''
- for n, item in enumerate(items):
- requestType = item.get('RequestType', None)
- if requestType is None:
- raise ValueError('No request type specified for item: %s' % n)
- uploadFrom = uploadTypeMapping.get(requestType, None)
- if uploadFrom is None:
- raise ValueError('Unsupported request type for item %s: %s' % (n, requestType))
-
- contentType = item.get('ContentType', None)
- if contentType is not None:
- del msgParams['ContentType']
- item['Metadata.ContentType'] = contentType
-
- allowedParams = dict(paramMapping[requestType])
- msg.params['Files.%s.UploadFrom' % n] = uploadFrom
- for param, value in item.items():
- if param == 'RequestType':
- continue
-
- if param in allowedParams:
- del allowedParams[param]
- else:
- raise ValueError('Unsupported param for item %s: %s' % (n, param))
-
- if param == 'Data':
- data += value
- msg.params['Files.%s.DataLength' % n] = len(value)
- continue
- msg.params['Files.%s.%s' % (n, param)] = value
-
- # errorcheck params
- if allowedParams:
- for paramName, isRequired in allowedParams.items():
- if isRequired:
- raise ValueError('Param "%s" is required for item %s' % (paramName, n))
-
- msg['DefaultName'] = items[0].get('Name', '')
- if data:
- msg.data = data
-
- # finally
- self.registerRequest(
- msg,
- requestType,
- persistentUserData=persistentUserData,
- userData=userData,
- )
- self.sendMessage(msg)
- return msg['Identifier']
-
-
def putData(self,
uri,
data,
@@ -1726,29 +1542,46 @@
@todo: EarlyEncode and GetCHKOnly message params not implemented
"""
- return self.clientPut(
- consts.ConstRequestType.PutData,
- uri,
- userData,
- persistentUserData,
- data=data,
-
- # fcp params
- ContentType=contentType,
+ msg = message.MsgClientPut(
+ URI=uri,
DataLength=len(data),
#EarlyEncode='false',
#GetCHKOnly='false',
Global=False,
Identifier=None,
- MaxRetries=maxRetries,
- DontCompress=dontCompress,
Persistence=persistence,
PriorityClass=priorityClass,
UploadFrom=consts.ConstUploadFrom.Direct,
Verbosity=consts.ConstVerbosity.ReportProgress | consts.ConstVerbosity.ReportCompression,
)
-
-
+
+ #
+ if uri.KeyType == consts.ConstKeyType.CHK:
+ if uri.tail is not None:
+ raise ValueError('no tail allowed')
+ if uri.filename is not None:
+ msg['TargetFilename'] = uri.docName
+ elif uri.KeyType == consts.ConstKeyType.SSK:
+ if uri.tail is not None:
+ raise ValueError('no tail allowed')
+ elif uri.KeyType == consts.ConstKeyType.USK:
+ if uri.tail is not None:
+ raise ValueError('no tail allowed')
+
+ if contentType is not None: msg['Metadata.ContentType'] = allowedMimeTypes
+ if dontCompress is not None: msg['DontCompress'] = dontCompresss
+ if maxRetries is not None: msg['MaxRetries'] = maxRetries
+
+ msg.data = data
+ self.registerRequest(
+ msg,
+ persistentUserData=persistentUserData,
+ userData=userData,
+ )
+ self.sendMessage(msg)
+ return msg['Identifier']
+
+
def putDir(self,
uri,
directory,
@@ -1760,8 +1593,7 @@
maxRetries=None,
persistence=consts.ConstPersistence.Connection,
priorityClass=consts.ConstPriority.Medium,
- targetFilename=None,
-
+
userData=None,
persistentUserData='',
@@ -1781,29 +1613,47 @@
@todo: EarlyEncode and GetCHKOnly message params not implemented
@todo: 2MiB compressed zize allowed?
"""
- return self.clientPut(
- consts.ConstRequestType.PutDir,
- uri,
- userData,
- persistentUserData,
-
- # fcp params
- ContentType=contentType,
- DefaultName=defaultName,
- #EarlyEncode='false',
+ msg = message.MsgClientPutDiskDir(
+ URI=uri,
Filename=directory,
+ #EarlyEncode='false',
#GetCHKOnly='false',
Global=False,
Identifier=None,
- MaxRetries=maxRetries,
DontCompress=dontCompress,
Persistence=persistence,
PriorityClass=priorityClass,
UploadFrom=consts.ConstUploadFrom.Disk,
Verbosity=consts.ConstVerbosity.ReportProgress | consts.ConstVerbosity.ReportCompression,
)
-
+ #
+ if uri.KeyType == consts.ConstKeyType.CHK:
+ if uri.tail is not None:
+ raise ValueError('no tail allowed')
+ if uri.filename is not None:
+ msg['TargetFilename'] = uri.docName
+ elif uri.KeyType == consts.ConstKeyType.SSK:
+ if uri.tail is not None:
+ raise ValueError('no tail allowed')
+ elif uri.KeyType == consts.ConstKeyType.USK:
+ if uri.tail is not None:
+ raise ValueError('no tail allowed')
+
+ if contentType is not None: msg['Metadata.ContentType'] = allowedMimeTypes
+ if defaultName is not None: msg['DefaultName'] = defaultName
+ if dontCompress is not None: msg['DontCompress'] = dontCompresss
+ if maxRetries is not None: msg['MaxRetries'] = maxRetries
+
+ self.registerRequest(
+ msg,
+ persistentUserData=persistentUserData,
+ userData=userData,
+ )
+ self.sendMessage(msg)
+ return msg['Identifier']
+
+
def putFile(self,
uri,
filename,
@@ -1825,27 +1675,45 @@
@todo: EarlyEncode and GetCHKOnly message params not implemented
"""
- return self.clientPut(
- consts.ConstRequestType.PutFile,
- uri,
- userData,
- persistentUserData,
-
- # fcp params
- ContentType=contentType,
- #EarlyEncode='false',
+ msg = message.MsgClientPut(
+ URI=uri,
Filename=filename,
+ #EarlyEncode='false',
#GetCHKOnly='false',
Global=False,
Identifier=None,
- MaxRetries=maxRetries,
- DontCompress=dontCompress,
Persistence=persistence,
PriorityClass=priorityClass,
UploadFrom=consts.ConstUploadFrom.Disk,
Verbosity=consts.ConstVerbosity.ReportProgress | consts.ConstVerbosity.ReportCompression,
)
-
+
+ #
+ if uri.KeyType == consts.ConstKeyType.CHK:
+ if uri.tail is not None:
+ raise ValueError('no tail allowed')
+ if uri.filename is not None:
+ msg['TargetFilename'] = uri.docName
+ elif uri.KeyType == consts.ConstKeyType.SSK:
+ if uri.tail is not None:
+ raise ValueError('no tail allowed')
+ elif uri.KeyType == consts.ConstKeyType.USK:
+ if uri.tail is not None:
+ raise ValueError('no tail allowed')
+
+ if contentType is not None: msg['Metadata.ContentType'] = allowedMimeTypes
+ if dontCompress is not None: msg['DontCompress'] = dontCompresss
+ if maxRetries is not None: msg['MaxRetries'] = maxRetries
+
+ self.registerRequest(
+ msg,
+ persistentUserData=persistentUserData,
+ userData=userData,
+ )
+ self.sendMessage(msg)
+ return msg['Identifier']
+
+
def putMultiple(self,
uri,
items,
@@ -1855,8 +1723,7 @@
maxRetries=None,
persistence=consts.ConstPersistence.Connection,
priorityClass=consts.ConstPriority.Medium,
- targetFilename=None,
-
+
userData=None,
persistentUserData='',
@@ -1869,10 +1736,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.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
+ - RequestType: L{consts.ConstPutMultiple.Data}, L{consts.ConstPutMultiple.File} or L{consts.ConstPutMultiple.Redirect}
+ - Data: if requestType is L{consts.ConstPutMultiple.Data}, data to upload
+ - Filename: if requestType is L{consts.ConstPutMultiple.File}, filepath of the file to upload
+ - TargetURI: if requestType is L{consts.ConstPutMultiple.Redirect}, uri to redirect to
- Name: name under wich the item will be accesible via freenet
- Metadata.ContentType: (optional) may be passed as 'ContentType'
@@ -1882,28 +1749,107 @@
@todo: EarlyEncode and GetCHKOnly message params not implemented
"""
- return self.clientPut(
- consts.ConstRequestType.PutMultiple,
- uri,
- userData,
- persistentUserData,
- items=items,
-
- # fcp params
- DefaultName=defaultName,
- #EarlyEncode='false',
+ msg = message.MsgClientPutComplexDir(
+ URI=uri,
+ #EarlyEncode='false',
#GetCHKOnly='false',
Global=False,
Identifier=None,
- MaxRetries=maxRetries,
- DontCompress=dontCompress,
Persistence=persistence,
PriorityClass=priorityClass,
- UploadFrom=consts.ConstUploadFrom.Disk,
Verbosity=consts.ConstVerbosity.ReportProgress | consts.ConstVerbosity.ReportCompression,
)
-
+ #
+ if uri.KeyType == consts.ConstKeyType.CHK:
+ if uri.tail is not None:
+ raise ValueError('no tail allowed')
+ if uri.filename is not None:
+ msg['TargetFilename'] = uri.docName
+ elif uri.KeyType == consts.ConstKeyType.SSK:
+ if uri.tail is not None:
+ raise ValueError('no tail allowed')
+ elif uri.KeyType == consts.ConstKeyType.USK:
+ if uri.tail is not None:
+ raise ValueError('no tail allowed')
+
+ if defaultName is not None: msg['DefaultName'] = defaultName
+ if dontCompress is not None: msg['DontCompress'] = dontCompresss
+ if maxRetries is not None: msg['MaxRetries'] = maxRetries
+
+ uploadTypeMapping = {
+ consts.ConstPutMultiple.Data: consts.ConstUploadFrom.Direct,
+ consts.ConstPutMultiple.File: consts.ConstUploadFrom.Disk,
+ consts.ConstPutMultiple.Redirect: consts.ConstUploadFrom.Redirect,
+ }
+ # requestType --> [(allowedParam: boolParamIsRequired), ...]
+ paramMapping = {
+ consts.ConstPutMultiple.Data: [
+ ('Name', True),
+ ('Data', True),
+ ('ContentType', False),
+ ],
+ consts.ConstPutMultiple.File: [
+ ('Name', True),
+ ('Filename', True),
+ ('Metadata.ContentType', False),
+ ],
+ consts.ConstPutMultiple.Redirect: [
+ ('Name', True),
+ ('TargetURI', True),
+ ],
+ }
+
+ data = ''
+ for n, item in enumerate(items):
+ requestType = item.get('RequestType', None)
+ if requestType is None:
+ raise ValueError('No request type specified for item: %s' % n)
+ uploadFrom = uploadTypeMapping.get(requestType, None)
+ if uploadFrom is None:
+ raise ValueError('Unsupported request type for item %s: %s' % (n, requestType))
+
+ contentType = item.get('ContentType', None)
+ if contentType is not None:
+ del msgParams['ContentType']
+ item['Metadata.ContentType'] = contentType
+
+ allowedParams = dict(paramMapping[requestType])
+ msg.params['Files.%s.UploadFrom' % n] = uploadFrom
+ for param, value in item.items():
+ if param == 'RequestType':
+ continue
+
+ if param in allowedParams:
+ del allowedParams[param]
+ else:
+ raise ValueError('Unsupported param for item %s: %s' % (n, param))
+
+ if param == 'Data':
+ data += value
+ msg.params['Files.%s.DataLength' % n] = len(value)
+ continue
+ msg.params['Files.%s.%s' % (n, param)] = value
+
+ # errorcheck params
+ if allowedParams:
+ for paramName, isRequired in allowedParams.items():
+ if isRequired:
+ raise ValueError('Param "%s" is required for item %s' % (paramName, n))
+
+ msg['DefaultName'] = items[0].get('Name', '')
+ if data:
+ msg.data = data
+
+ self.registerRequest(
+ msg,
+ persistentUserData=persistentUserData,
+ userData=userData,
+ )
+ self.sendMessage(msg)
+ return msg['Identifier']
+
+
def putRedirect(self,
uri,
targetKey,
@@ -1923,17 +1869,41 @@
@param userData: (any) any data to be associated to the request at runtime
@return: (str) request identifier
"""
- return self.clientPut(
- consts.ConstRequestType.PutRedirect,
- uri,
- userData,
- persistentUserData,
- Persistence=persistence,
- PriorityClass=priorityClass,
- TargetURI=targetKey,
- UploadFrom=consts.ConstUploadFrom.Redirect,
- )
-
+ #
+ if uri.KeyType == consts.ConstKeyType.CHK:
+ if uri.tail is not None:
+ raise ValueError('no tail allowed')
+ if uri.filename is not None:
+ msg['TargetFilename'] = uri.docName
+ elif uri.KeyType == consts.ConstKeyType.SSK:
+ if uri.tail is not None:
+ raise ValueError('no tail allowed')
+ elif uri.KeyType == consts.ConstKeyType.USK:
+ if uri.tail is not None:
+ raise ValueError('no tail allowed')
+
+ msg = message.MsgClientPut(
+ URI=uri,
+ TargetURI=targetKey,
+ #EarlyEncode='false',
+ #GetCHKOnly='false',
+ Global=False,
+ Identifier=None,
+ Persistence=persistence,
+ PriorityClass=priorityClass,
+ UploadFrom=consts.ConstUploadFrom.Redirect,
+ Verbosity=consts.ConstVerbosity.ReportProgress | consts.ConstVerbosity.ReportCompression,
+ )
+ if maxRetries is not None: msg['MaxRetries'] = maxRetries
+
+ self.registerRequest(
+ msg,
+ persistentUserData=persistentUserData,
+ userData=userData,
+ )
+ self.sendMessage(msg)
+ return msg['Identifier']
+
########################################################
##
## request related methods
@@ -1970,7 +1940,10 @@
Fcp does not provide means to do so.
"""
initialRequest = self._requests[requestIdentifier]
- if not initialRequest['RequestType'] & (consts.ConstRequestType.MaskGet | consts.ConstRequestType.MaskPut):
+ if not initialRequest == message.MsgClientGet or \
+ initialRequest == message.MsgClientPut or \
+ initialRequest == message.MsgClientPutDiskDir or \
+ initialRequest == message.MsgClientPutComplexDir:
raise ValueError('Can not modify request: %s' % initialRequest.name)
#FIX: [0002083]
@@ -2013,7 +1986,10 @@
"""
initialRequest = self._requests[requestIdentifier]
initialRequest['RequestStatus'] |= consts.ConstRequestStatus.Removed | consts.ConstRequestStatus.Completed
- if initialRequest['RequestType'] & (consts.ConstRequestType.MaskGet | consts.ConstRequestType.MaskPut):
+ if initialRequest == message.MsgClientGet or \
+ initialRequest == message.MsgClientPut or \
+ initialRequest == message.MsgClientPutDiskDir or \
+ initialRequest == message.MsgClientPutComplexDir:
self.sendMessage(
message.MsgRemoveRequest(
Global=False,
@@ -2153,7 +2129,7 @@
PluginName=pluginName,
Detailed=detailed,
)
- self.registerRequest(msg, consts.ConstRequestType.PluginInfo)
+ self.registerRequest(msg)
self.sendMessage(msg)
return msg['Identifier']
@@ -2190,20 +2166,18 @@
## others
##
##########################################################
- def generateKeypair(self, keypairType=consts.ConstKeyType.SSK):
+ def generateKeypair(self, keyPairType=consts.ConstKeyType.SSK):
"""Generates a public / private keypair
- @param keypairType: type of keypair to generate (either L{consts.ConstKeyType.SSK} or L{consts.ConstKeyType.SSK})
+ @param keyPairType: type of keypair to generate (either L{consts.ConstKeyType.SSK} or L{consts.ConstKeyType.SSK})
@return: identifier of the request
@event: L{events.Events.KeypairGenerated} triggered as soon as the request is complete
"""
- if keypairType not in (consts.ConstKeyType.SSK, consts.ConstKeyType.USK):
+ if keyPairType not in (consts.ConstKeyType.SSK, consts.ConstKeyType.USK):
raise ValueError('keypairType must be SSK or USK')
-
- requestType = consts.ConstRequestType.GenerateSSKKeypair if keypairType == consts.ConstKeyType.SSK else consts.ConstRequestType.GenerateUSKKeypair
- msg = message.MsgGenerateSSK()
- self.registerRequest(msg, requestType)
+ msg = message.MsgGenerateSSK(KeyPairType=keyPairType)
+ self.registerRequest(msg)
self.sendMessage(msg)
return msg['Identifier']
Modified: trunk/fclient/src/fclient/lib/fcp2/consts.py
===================================================================
--- trunk/fclient/src/fclient/lib/fcp2/consts.py 2008-07-20 17:55:11 UTC (rev 697)
+++ trunk/fclient/src/fclient/lib/fcp2/consts.py 2008-07-20 19:57:42 UTC (rev 698)
@@ -408,6 +408,12 @@
DarknetPeerOnly = 31
NoSuchPlugin = 32
+class ConstPutMultiple:
+ Data = 0
+ File = 1
+ Redirect = 2
+
+
class ConstRequestModified(_BaseBitFlags):
"""Flags indicating what aspect of a request has been modified
@cvar Filename: the filename has been modified
Modified: trunk/fclient/src/fclient/lib/fcp2/message.py
===================================================================
--- trunk/fclient/src/fclient/lib/fcp2/message.py 2008-07-20 17:55:11 UTC (rev 697)
+++ trunk/fclient/src/fclient/lib/fcp2/message.py 2008-07-20 19:57:42 UTC (rev 698)
@@ -89,8 +89,11 @@
@param data: data associated to the message
@param params: {field-name: value, ...} of parameters of the message
"""
- params.update(self._additional_params_.copy())
-
+ additionalParams = self._additional_params_.copy()
+ for name, value in additionalParams.items():
+ if name not in params:
+ params[name] = value
+
self.data = data
self.params = params
@@ -198,13 +201,13 @@
_AdditionalGetParams = {
# persistent params
- _PrivateParam('RequestType'): consts.ConstRequestType.Null, # identifies sub message types
_PrivateParam('InitTime'): 0, # when was the request started?
_PrivateParam('PersistentUserData'): '', # any user defined persistent data
_PrivateParam('HandleFilenameCollision'): False,
_PrivateParam('FilenameCollisionHandled'): False,
_PrivateParam('HandlePermanentRedirect'): False,
_PrivateParam('PermanentRedirectHandled'): False,
+ _PrivateParam('IsGetKeyInfo'): False,
# non persistent params
_PrivateParam('RequestStatus'): consts.ConstRequestStatus.Null,
@@ -233,7 +236,6 @@
_AdditionalPutParams = {
# persistent params
- _PrivateParam('RequestType'): consts.ConstRequestType.Null, # identifies sub message types
_PrivateParam('InitTime'): 0, # when was the request started?
_PrivateParam('PersistentUserData'): '', # any user defined persistent data
@@ -261,9 +263,9 @@
}
_GenerateSSKParams = {
- _PrivateParam('RequestType'): consts.ConstRequestType.Null, # identifies sub message types
_PrivateParam('RequestStatus'): consts.ConstRequestStatus.Null,
_PrivateParam('InitTime'): 0, # when was the request started?
+ _PrivateParam('KeyPairType'): consts.ConstKeyType.SSK,
}
_SubscribeUSKParams = {
@@ -296,6 +298,7 @@
('FilenameCollisionHandled', pmstruct.BOOL),
('HandlePermanentRedirect', pmstruct.BOOL),
('PermanentRedirectHandled', pmstruct.BOOL),
+ ('IsGetKeyInfo', pmstruct.BOOL),
)
class PersistentParamsPut(pmstruct.PMStruct):
@@ -433,7 +436,6 @@
def updatePersistentParams(self):
params = PersistentParamsGet(
Version=1,
- RequestType=self['RequestType'],
InitTime=self['InitTime'],
PersistentUserData=self['PersistentUserData'],
HandleFilenameCollision=self['HandleFilenameCollision'],
@@ -483,7 +485,6 @@
def updatePersistentParams(self):
params = PersistentParamsPut(
Version=1,
- RequestType=self['RequestType'],
InitTime=self['InitTime'],
PersistentUserData=self['PersistentUserData'],
)
Modified: trunk/fclient/src/fclient/lib/fcp2/test/test_client.py
===================================================================
--- trunk/fclient/src/fclient/lib/fcp2/test/test_client.py 2008-07-20 17:55:11 UTC (rev 697)
+++ trunk/fclient/src/fclient/lib/fcp2/test/test_client.py 2008-07-20 19:57:42 UTC (rev 698)
@@ -883,8 +883,7 @@
requestsAll = self.client.getRequests()
self.failUnless(myIdentifier in requestsAll)
myRequest = self.client.getRequest(myIdentifier)
- self.assertEqual(myRequest['RequestType'], fcp2.ConstRequestType.GetData)
-
+
def test_300_message_send(self):
self.connectClient()
@@ -1141,8 +1140,7 @@
requestsAll = self.client.getRequests()
self.failUnless(myIdentifier in requestsAll)
myRequest = self.client.getRequest(myIdentifier)
- self.assertEqual(myRequest['RequestType'], fcp2.ConstRequestType.GetFile)
-
+
def test_200_key_object_is_accepted(self):
self.connectClient()
@@ -1242,7 +1240,7 @@
requestsAll = self.client.getRequests()
self.failUnless(myIdentifier in requestsAll)
myRequest = self.client.getRequest(myIdentifier)
- self.assertEqual(myRequest['RequestType'], fcp2.ConstRequestType.GetKeyInfo)
+
def test_200_key_object_is_accepted(self):
self.connectClient()
@@ -1473,13 +1471,13 @@
# key.tail is not allowed in all put actions
myKey = fcp2.KeyCHK(keyData=DummyKeyData, tail='foo')
- self.assertRaises(ValueError, self.client.clientPut, fcp2.ConstRequestType.PutData, myKey, data='foo')
+ self.assertRaises(ValueError, self.client.putData, myKey, data='foo')
myKey = fcp2.KeySSK(keyData=DummyKeyData, tail='foo')
- self.assertRaises(ValueError, self.client.clientPut, fcp2.ConstRequestType.PutData, myKey, data='foo')
+ self.assertRaises(ValueError, self.client.putData, myKey, data='foo')
myKey = fcp2.KeyUSK(keyData=DummyKeyData, tail='foo')
- self.assertRaises(ValueError, self.client.clientPut, fcp2.ConstRequestType.PutData, myKey, data='foo')
+ self.assertRaises(ValueError, self.client.putData, myKey, data='foo')
#***********************************************************************************
#
@@ -1707,22 +1705,22 @@
items = [
{
- 'RequestType': fcp2.ConstRequestType.PutData,
+ 'RequestType': fcp2.ConstPutMultiple.Data,
'Data': '12345',
'Name': 'myItem0',
},
{
- 'RequestType': fcp2.ConstRequestType.PutFile,
+ 'RequestType': fcp2.ConstPutMultiple.File,
'Filename': 'myFile.txt',
'Name': 'myItem1',
},
{
- 'RequestType': fcp2.ConstRequestType.PutRedirect,
+ 'RequestType': fcp2.ConstPutMultiple.Redirect,
'TargetURI': 'CHK@123456789',
'Name': 'myItem2',
},
{
- 'RequestType': fcp2.ConstRequestType.PutData,
+ 'RequestType': fcp2.ConstPutMultiple.Data,
'Data': '67890',
'Name': 'myItem3',
},
@@ -1786,16 +1784,7 @@
def test_putMultiple_ItemErrors(self):
self.connectClient()
- # upload directory is not allowed
- items = [
- {
- 'RequestType': fcp2.ConstRequestType.PutDir,
- 'Data': '12345',
- 'Name': 'myItem0',
- },
- ]
myKey = fcp2.KeyKSK('foo')
- self.assertRaises(ValueError, self.client.putMultiple, myKey, items)
#TODO: how to test required params?
# ...just some samples below
@@ -1813,7 +1802,7 @@
# param missing (we enforce all required parameters)
items = [
{
- 'RequestType': fcp2.ConstRequestType.PutData,
+ 'RequestType': fcp2.ConstPutMultiple.Data,
#'Data': '12345',
#'Name': 'myItem0',
},
@@ -2960,19 +2949,20 @@
self.connectClient()
myIdentifier = self.client.generateKeypair(fcp2.ConstKeyType.USK)
+
myRequest = self.client.getRequest(myIdentifier)
requestsAll = self.client.getRequests()
self.assertHasNextMessage(fcp2.MsgGenerateSSK)
priv = fcp2.Key('SSK@' + DummyKeyData + '/')
pub = fcp2.Key('SSK@' + DummyKeyData + '/')
+
self.sendResponseMessage(
'SSKKeypair',
Identifier=myIdentifier,
RequestURI=pub,
InsertURI=priv,
)
-
priv = fcp2.KeyUSK(priv.keyData, docName=priv.docName)
pub = fcp2.KeyUSK(pub.keyData, docName=pub.docName)
msg = self.assertHasNextEvent(
@@ -3007,7 +2997,6 @@
requestsAll = self.client.getRequests()
self.failUnless(myIdentifier in requestsAll)
myRequest = self.client.getRequest(myIdentifier)
- self.assertEqual(myRequest['RequestType'], fcp2.ConstRequestType.SubscribeUSK)
self.assertHasNextMessage(
fcp2.MsgSubscribeUSK,
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|