SF.net SVN: fclient: [428] trunk/sandbox/fcp2/client.py
Status: Pre-Alpha
Brought to you by:
jurner
|
From: <jU...@us...> - 2008-06-29 16:20:54
|
Revision: 428
http://fclient.svn.sourceforge.net/fclient/?rev=428&view=rev
Author: jUrner
Date: 2008-06-29 09:21:01 -0700 (Sun, 29 Jun 2008)
Log Message:
-----------
reworked putData and putRedirect
Modified Paths:
--------------
trunk/sandbox/fcp2/client.py
Modified: trunk/sandbox/fcp2/client.py
===================================================================
--- trunk/sandbox/fcp2/client.py 2008-06-29 15:19:30 UTC (rev 427)
+++ trunk/sandbox/fcp2/client.py 2008-06-29 16:21:01 UTC (rev 428)
@@ -1526,9 +1526,9 @@
def clientPut(self,
requestType,
key,
+ userData,
+ persistentUserData,
data=None,
- persistentUserData='',
- userData=None,
items=None,
**msgParams
):
@@ -1540,7 +1540,7 @@
@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 pass a dict for each item containig the following members:
@@ -1555,31 +1555,38 @@
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 = message.ClientPut.name
- elif requestType == consts.RequestType.PutDir:
- msgName = message.ClientPutDiskDir.name
- elif requestType == consts.RequestType.PutMultiple:
- msgName = message.ClientPutComplexDir.name
- else:
- raise ValueError('Unsupported request type')
- msg = message.MessagesAll[msgName](URI=key)
+ #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.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
+ else:
+ raise ValueError('Unsupported request type')
+ msg = msgClass(URI=key)
+
+ # add params
+ if key.KeyType == consts.KeyType.CHK:
+ if key.filename is not None:
+ msg['TargetFilename'] = key.filename
for param, value in msgParams.items():
if value is not None:
msg[param] = value
if data is not None:
if requestType != consts.RequestType.PutData:
- raise ValueError('Data can only be passed along with PutData uploads')
+ raise ValueError('Data can only be passed along with putData uploads')
msg.data = data
if items is not None:
-
if requestType != consts.RequestType.PutMultiple:
raise ValueError('Items can only be passed along with PutMultiple uploads')
@@ -1647,7 +1654,7 @@
if data:
msg.data = data
- #
+ # finally
self._registerRequest(
msg,
requestType,
@@ -1657,7 +1664,7 @@
self.sendMessage(msg)
return msg['Identifier']
-
+ #TESTED
def putData(self,
key,
data,
@@ -1667,20 +1674,43 @@
maxRetries=None,
persistence=consts.Persistence.Connection,
priorityClass=consts.Priority.Medium,
- targetFilename=None,
-
+
userData=None,
persistentUserData='',
):
+ """Uploads data
+ @param key: (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
+ @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 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,
key,
-
+ userData,
+ persistentUserData,
data=data,
- persistentUserData=persistentUserData,
- userData=userData,
-
+
# fcp params
ContentType=contentType,
DataLength=len(data),
@@ -1692,16 +1722,14 @@
DontCompress=dontCompress,
Persistence=persistence,
PriorityClass=priorityClass,
- TargetFilename=targetFilename,
UploadFrom=consts.UploadFrom.Direct,
Verbosity=consts.Verbosity.ReportProgress | consts.Verbosity.ReportCompression,
)
-
-
+ #TESTED
def putRedirect(self,
- name,
- targetURI,
+ key,
+ targetKey,
maxRetries=None,
persistence=consts.Persistence.Connection,
priorityClass=consts.Priority.Medium,
@@ -1709,8 +1737,8 @@
persistentUserData='',
):
"""Uploads a redirect to another key
- @param name: name of the redirect
- @param targetURI: (str) uri to redirect to
+ @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
@@ -1718,22 +1746,23 @@
@param userData: (any) any data to be associated to the request at runtime
@return: (str) request identifier
"""
- msg = 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.sendMessage(msg)
- return msg['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,
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|