SF.net SVN: fclient: [298] trunk/sandbox/fcp2/client.py
Status: Pre-Alpha
Brought to you by:
jurner
|
From: <ju...@us...> - 2008-02-27 16:55:34
|
Revision: 298
http://fclient.svn.sourceforge.net/fclient/?rev=298&view=rev
Author: jurner
Date: 2008-02-27 08:55:41 -0800 (Wed, 27 Feb 2008)
Log Message:
-----------
Some fixes for uploadMultiple and more docs
Modified Paths:
--------------
trunk/sandbox/fcp2/client.py
Modified: trunk/sandbox/fcp2/client.py
===================================================================
--- trunk/sandbox/fcp2/client.py 2008-02-27 14:14:59 UTC (rev 297)
+++ trunk/sandbox/fcp2/client.py 2008-02-27 16:55:41 UTC (rev 298)
@@ -1486,10 +1486,12 @@
@return: (str) request identifier
- @event: RequestCompleted(event, message) triggered when the request is complete
- @event: RequestFailed(event, message) triggered when the request failes
- @event: RequestStarted(event, message) triggered when as the request is started
- @event: RequestModified(event, message) trigggered if the request identifier changes,
+ @event: (L{events.Event.RequestCompleted}) triggered when the request is complete
+ @event: (L{events.Event.RequestFailed}) triggered when the request failes
+ @event: (L{events.Event.RequestFetchable}) triggered as soon as the request is fetchable
+ @event: (L{events.Event.RequestCompressing}) triggered when the request is about to be compressed
+ @event: (L{events.Event.RequestCompressed}) triggered as soon as compressing of the request is completed
+
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
@@ -1623,8 +1625,7 @@
@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:
+ @note: to upload multiple items at once 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
@@ -1660,39 +1661,71 @@
msg.data = data
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')
+ uploadTypeMapping = {
+ consts.RequestType.PutData: consts.UploadFrom.Direct,
+ consts.RequestType.PutFile: consts.UploadFrom.Disk,
+ consts.RequestType.PutRedirect: consts.UploadFrom.Redirect,
+ }
+ # requestType --> [(allowedParam: boolParamIsRequired), ...]
+ paramMapping = {
+ consts.RequestType.PutData: [
+ ('Name', True),
+ ('Data', True),
+ ('ContentType', False),
+ ],
+ consts.RequestType.PutFile: [
+ ('Name', True),
+ ('Filename', True),
+ ('Metadata.ContentType', False),
+ ],
+ consts.RequestType.PutRedirect: [
+ ('Name', True),
+ ('TargetURI', True),
+ ],
+ }
+
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)
+ uploadFrom = uploadTypeMapping.get(requestType, None)
if uploadFrom is None:
- raise valueError('Unsupported request type for item %s: %s' % (n, requestType))
+ raise ValueError('Unsupported request type for item %s: %s' % (n, requestType))
contentType = item.get('ContentType', None)
- if conetntType is not 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.startswith('Fc'):
continue
- elif param == 'Data':
- data += data
- msg.params['Files.%s.DataLength' % n] = len(data)
+
+ 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
@@ -1750,7 +1783,6 @@
contentType=None,
dontCompress=None,
- filename=None,
maxRetries=None,
persistence=consts.Persistence.Connection,
priorityClass=consts.Priority.Medium,
@@ -1759,9 +1791,31 @@
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
+ @paramtargetFilename: (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.Event.RequestCompleted}) triggered when the request is complete
+ @event: (L{events.Event.RequestFailed}) triggered when the request failes
+ @event: (L{events.Event.RequestFetchable}) triggered as soon as the request is fetchable
+ @event: (L{events.Event.RequestCompressing}) triggered when the request is about to be compressed
+ @event: (L{events.Event.RequestCompressed}) 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.Event.RequestFetchable} or the L{events.Event.RequestCompleted} event
+ is triggered.
+
+ @todo: EarlyEncode and GetCHKOnly message params not implemented
"""
- @param data: ()
- """
return self.clientPut(
consts.RequestType.PutData,
consts.KeyType.CHK,
@@ -1791,8 +1845,8 @@
directory,
allowUnreadableFiles=False,
contentType=None,
+ dontCompress=None,
defaultName=None,
- dontCompress=None,
maxRetries=None,
persistence=consts.Persistence.Connection,
priorityClass=consts.Priority.Medium,
@@ -1802,9 +1856,36 @@
persistentUserData='',
):
+ """Uploads the contents of a directory
+
+ @param directory: (str) directory to upload
+
+ @param contentType: (str) content type. If not specified, the node will guess the content type
+ @param defaultName: (str) the default item to display when the key is requested
+ @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
+ @paramtargetFilename: (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.Event.RequestCompleted}) triggered when the request is complete
+ @event: (L{events.Event.RequestFailed}) triggered when the request failes
+ @event: (L{events.Event.RequestFetchable}) triggered as soon as the request is fetchable
+ @event: (L{events.Event.RequestCompressing}) triggered when the request is about to be compressed
+ @event: (L{events.Event.RequestCompressed}) 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.Event.RequestFetchable} or the L{events.Event.RequestCompleted} event
+ is triggered.
+
+ @note: when uploaded items of the directory can be accessed under Key/MyItemName/MyItemSubname
+
+ @todo: EarlyEncode and GetCHKOnly message params not implemented
+ @todo: 2MiB allowed? Have to test this
"""
- @param targetFilename: (str) filename to append to the CHK key or None (may not contain slashes)
- """
return self.clientPut(
consts.RequestType.PutDir,
consts.KeyType.CHK,
@@ -1845,10 +1926,31 @@
persistentUserData='',
):
+ """Uploads a file
+ @param filename: (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
+ @paramtargetFilename: (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.Event.RequestCompleted}) triggered when the request is complete
+ @event: (L{events.Event.RequestFailed}) triggered when the request failes
+ @event: (L{events.Event.RequestFetchable}) triggered as soon as the request is fetchable
+ @event: (L{events.Event.RequestCompressing}) triggered when the request is about to be compressed
+ @event: (L{events.Event.RequestCompressed}) 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.Event.RequestFetchable} or the L{events.Event.RequestCompleted} event
+ is triggered.
+
+ @todo: EarlyEncode and GetCHKOnly message params not implemented
"""
- @param targetFilename: (str) filename to append to the CHK key or None (may not contain slashes)
- """
-
return self.clientPut(
consts.RequestType.PutFile,
consts.KeyType.CHK,
@@ -1890,14 +1992,44 @@
persistentUserData='',
):
- """Uploads multiple items at once
+ """Uploads multiple items at once to be retrievable under one key
- @param items:
+ @param items: (list) list of items to upload
- @param targetFilename: (str) filename to append to the CHK key or None (may not contain slashes)
+ @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
+ @paramtargetFilename: (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.Event.RequestCompleted}) triggered when the request is complete
+ @event: (L{events.Event.RequestFailed}) triggered when the request failes
+ @event: (L{events.Event.RequestFetchable}) triggered as soon as the request is fetchable
+ @event: (L{events.Event.RequestCompressing}) triggered when the request is about to be compressed
+ @event: (L{events.Event.RequestCompressed}) 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.Event.RequestFetchable} or the L{events.Event.RequestCompleted} event
+ is triggered.
+
+ @note: to upload multiple items at once 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.
+
+
+ @todo: EarlyEncode and GetCHKOnly message params not implemented
"""
return self.clientPut(
consts.RequestType.PutMultiple,
@@ -1909,7 +2041,6 @@
items=items,
# fcp params
- Filename=directory,
AllowUnreadableFiles=allowUnreadableFiles,
ContentType=contentType,
DefaultName=defaultName,
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|