SF.net SVN: fclient: [244] trunk/sandbox/fcp/fcp2_0_client.py
Status: Pre-Alpha
Brought to you by:
jurner
|
From: <ju...@us...> - 2008-02-24 11:48:13
|
Revision: 244
http://fclient.svn.sourceforge.net/fclient/?rev=244&view=rev
Author: jurner
Date: 2008-02-24 03:48:04 -0800 (Sun, 24 Feb 2008)
Log Message:
-----------
continued working on uploads
Modified Paths:
--------------
trunk/sandbox/fcp/fcp2_0_client.py
Modified: trunk/sandbox/fcp/fcp2_0_client.py
===================================================================
--- trunk/sandbox/fcp/fcp2_0_client.py 2008-02-23 08:18:18 UTC (rev 243)
+++ trunk/sandbox/fcp/fcp2_0_client.py 2008-02-24 11:48:04 UTC (rev 244)
@@ -1661,67 +1661,12 @@
self.sendMessageEx(msg)
return msg['Identifier']
-
- def putRedirect(self,
- name,
- targetURI,
-
- maxRetries=None,
- persistence=consts.Persistence.Connection,
- priorityClass=consts.Priority.Medium,
-
- userData=None,
- persistentUserData='',
- ):
- """Uploads a redirect
- @param name: name of the redirect
- @param targetURI: (str) uri to redirect to
- @return: (str) request identifier
- """
- msg = self.Message(
- consts.Message.ClientPut,
- URI=consts.KeyType.KSK + name,
- Persistence=persistence,
- PriorityClass=priorityClass,
- TargetURI=targetURI,
- UploadFrom=consts.UploadFrom.Redirect,
- )
- self._registerRequest(
- msg,
- consts.RequestType.PutRedirect,
- persistentUserData=persistentUserData,
- userData=userData,
- )
- self.sendMessageEx(msg)
- return msg['Identifier']
-
########################################################
##
## CHK ClientPut related methods
##
########################################################
- def putUpload(self, upload, userData=None, persistentUserData=''):
-
- requestType, msg = upload.getMessage(self.Message)
- if requestType is None:
- raise ValueError('Nothing to upload')
-
- self._registerRequest(
- msg,
- requestType,
- persistentUserData=persistentUserData,
- userData=userData,
- )
-
- if upload.keyType in (consts.KeyType.SSK, consts.KeyType.USK):
- msg['FcPrivateKey'] = upload.privateKey
- #NOTE: the caller may use the 'FcPrivateKey' member to store the private key
-
-
- self.sendMessageEx(msg)
- return msg['Identifier']
-
def clientPut(self,
requestType,
uri,
@@ -1729,29 +1674,94 @@
persistentUserData='',
userData=None,
items=None,
- **messageParams
+ **msgParams
):
+ """Uploads to the node
+ @param requestType: (L{consts.RequestType}). Can be PutData, PutDir or PutMultiple
+ @param 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
+ @param items: for L{consts.RequestType.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 (see: PutComplexDir) pass a dict for each item
+ containig the following members:
+
+ - FcRequestType: 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
+ - 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.
+ """
if requestType in (consts.RequestType.PutData, consts.RequestType.PutFile):
msgName = consts.Message.ClientPut
elif requestType == consts.RequestType.PutDir:
msgName = consts.Message.ClientPutDiskDir
+ elif requestType == consts.RequestType.PutMultiple:
+ msgName = consts.Message.ClientPutComplexDir
else:
- msgName = consts.Message.ClientPutComplexDir
-
+ raise ValueError('Unsupported request type')
+
msg = self.Message(msgName, URI=uri)
- for paramName, value in messageParams.items():
+ contentType = msgParams.get('ContentType', None)
+ if contentType is not None:
+ del msgParams['ContentType']
+ msgParams['Metadata.ContentType'] = contentType
+ for param, value in msgParams.items():
if value is not None:
- if paramName == 'ContentType':
- param = 'Metadata.ContentType'
- msg[paramName] = value
+ msg[param] = value
+
if data is not None:
+ if requestType != consts.RequestType.PutData:
+ raise ValueError('Data can only be passed along with PutData uploads')
msg.data = data
- if items:
- pass
-
-
+ if items is not None:
+ mapping = {
+ consts.RequestType.PutData: consts.UploadFrom.Direct,
+ consts.RequestType.PutFile: consts.UploadFrom.Disk,
+ consts.RequestType.PutRedirect: consts.UploadFrom.Redirect,
+ }
+
+ if requestType != consts.RequestType.PutMultiple:
+ raise ValueError('Items can only be passed along with PutMultiple uploads')
+
+ data = ''
+ for n, item in enumerate(items):
+ requestType = item.get('FcRequestType', None)
+ if requestType is None:
+ raise ValueError('No request type specified for item: %s' % n)
+ uploadFrom = mapping.get(requestType, None)
+ if uploadFrom is None:
+ raise valueError('Unsupported request type for item %s: %s' % (n, requestType))
+
+ contentType = item.get('ContentType', None)
+ if conetntType is not None:
+ del msgParams['ContentType']
+ item['Metadata.ContentType'] = contentType
+
+ msg.params['Files.%s.UploadFrom' % n] = uploadFrom
+ for param, value in item.items():
+ if param.startswith('Fc'):
+ continue
+ elif param == 'Data':
+ data += data
+ msg.params['Files.%s.DataLength' % n] = len(data)
+ continue
+ msg.params['Files.%s.%s' % (n, param)] = value
+
+ msg['DefaultName'] = items[0].get('Name', '')
+ if data:
+ msg.data = data
+
+ #
self._registerRequest(
msg,
requestType,
@@ -1762,6 +1772,42 @@
return msg['Identifier']
+ def putRedirect(self,
+ name,
+ targetURI,
+ maxRetries=None,
+ persistence=consts.Persistence.Connection,
+ priorityClass=consts.Priority.Medium,
+ userData=None,
+ persistentUserData='',
+ ):
+ """Uploads a redirect to another key
+ @param name: name of the redirect
+ @param targetURI: (str) uri 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 priority: (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
+ """
+ msg = self.Message(
+ consts.Message.ClientPut,
+ URI=consts.KeyType.KSK + name,
+ Persistence=persistence,
+ PriorityClass=priorityClass,
+ TargetURI=targetURI,
+ UploadFrom=consts.UploadFrom.Redirect,
+ )
+ self._registerRequest(
+ msg,
+ consts.RequestType.PutRedirect,
+ persistentUserData=persistentUserData,
+ userData=userData,
+ )
+ self.sendMessageEx(msg)
+ return msg['Identifier']
+
#CHK
def chkPutData(self,
data,
@@ -1970,8 +2016,8 @@
##
########################################################
def uskPutData(self,
+ insertURI,
data,
- insertURI,
contentType=None,
dontCompress=None,
@@ -1982,9 +2028,12 @@
userData=None,
persistentUserData=''
-
-
):
+ """Uploads data
+
+ """
+
+
return self.clientPut(
consts.RequestType.PutData,
insertURI,
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|