SF.net SVN: fclient: [308] trunk/sandbox/fcp2/client.py
Status: Pre-Alpha
Brought to you by:
jurner
|
From: <ju...@us...> - 2008-03-04 17:39:07
|
Revision: 308
http://fclient.svn.sourceforge.net/fclient/?rev=308&view=rev
Author: jurner
Date: 2008-03-04 09:39:14 -0800 (Tue, 04 Mar 2008)
Log Message:
-----------
use new key module ++ many a things I can't remember now
Modified Paths:
--------------
trunk/sandbox/fcp2/client.py
Modified: trunk/sandbox/fcp2/client.py
===================================================================
--- trunk/sandbox/fcp2/client.py 2008-03-04 17:38:18 UTC (rev 307)
+++ trunk/sandbox/fcp2/client.py 2008-03-04 17:39:14 UTC (rev 308)
@@ -202,7 +202,7 @@
from fcp2 import message
from fcp2 import fcparams
from fcp2 import types
-from fcp2 import uri
+from fcp2 import key
from fcp2.fcp_lib import namespace
from fcp2.fcp_lib import tools
@@ -249,7 +249,7 @@
message = message
fcparams = fcparams
types = types
- Uri = uri
+ key = key
def __init__(self,
@@ -1167,8 +1167,8 @@
return False
#TODO:no idea if the node may pass uris with prefixes like 'freenet:'... strip it anyways
- insertURI = uri.Uri(msg['InsertURI']).uri
- requestURI = uri.Uri(msg['RequestURI']).uri
+ insertURI = key.stripKey(msg['InsertURI'])
+ requestURI = key.stripKey(msg['RequestURI'])
if initialRequest['FcRequestType'] == consts.RequestType.GenerateUSKKeypair:
insertURI = insertURI.replace(consts.KeyType.SSK, consts.KeyType.USK, 1)
@@ -1367,7 +1367,6 @@
@return: (str) identifier of the request
"""
- key = uri.Uri(key).uri
msg = message.Message(consts.Message.ClientGet, URI=key)
for paramName, value in messageParams.items():
if value is not None:
@@ -1591,7 +1590,7 @@
"""
msg = message.Message(
consts.Message.SubscribeUSK,
- URI=uri.Uri(key).uri,
+ URI=key,
DontPoll=dontPoll,
)
self._registerRequest(msg, consts.RequestType.SubscribeUSK)
@@ -1646,6 +1645,7 @@
else:
raise ValueError('Unsupported request type')
+ #TODO: autoconvert keys to python classes???
msg = message.Message(msgName, URI=key)
contentType = msgParams.get('ContentType', None)
if contentType is not None:
@@ -1741,6 +1741,47 @@
return msg['Identifier']
+ def putData(self,
+ key,
+ data,
+
+ contentType=None,
+ dontCompress=None,
+ maxRetries=None,
+ persistence=consts.Persistence.Connection,
+ priorityClass=consts.Priority.Medium,
+ targetFilename=None,
+
+ userData=None,
+ persistentUserData='',
+
+ ):
+ return self.clientPut(
+ consts.RequestType.PutData,
+ key,
+
+ 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 putRedirect(self,
name,
targetURI,
@@ -1844,6 +1885,7 @@
def chkPutDir(self,
directory,
allowUnreadableFiles=False,
+
contentType=None,
dontCompress=None,
defaultName=None,
@@ -1859,32 +1901,14 @@
"""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
+ @param allowUnreadableFiles: if True, unreadable files in the directory are ignored, if False the request fails
+ if it encounters an unreadavle file.
+ @note: for other params see L{chkPutData}
+ @note: once 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
+ @todo: 2MiB compressed zize allowed?
"""
return self.clientPut(
consts.RequestType.PutDir,
@@ -1929,26 +1953,8 @@
"""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)
+ @note: for other params see L{chkPutData}
- @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
"""
return self.clientPut(
@@ -1996,26 +2002,7 @@
@param items: (list) list of items 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.
-
+ @note: for other params see L{chkPutData}
@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}
@@ -2064,7 +2051,7 @@
def sskPutData(self,
data,
privateKey,
-
+
contentType=None,
dontCompress=None,
maxRetries=None,
@@ -2075,6 +2062,18 @@
userData=None,
persistentUserData='',
):
+ """Uploads data that can be updated by the owner
+
+ @param data: (bytes) data to upload
+ @params 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,
@@ -2086,6 +2085,7 @@
# fcp params
ContentType=contentType,
DataLength=len(data),
+
#EarlyEncode='false',
#GetCHKOnly='false',
Global=False,
@@ -2114,8 +2114,8 @@
##
########################################################
def uskPutData(self,
- insertURI,
data,
+ privateKey,
contentType=None,
dontCompress=None,
@@ -2134,7 +2134,7 @@
return self.clientPut(
consts.RequestType.PutData,
- insertURI,
+ privateKey,
#insertURI + 'foo/0/',
userData=userData,
persistentUserData=persistentUserData,
@@ -2284,19 +2284,20 @@
# reset key if necessary
if requestType & consts.RequestType.MaskPut:
- requestUri = uri.Uri(request['URI'])
- if requestUri.keyType == consts.KeyType.CHK:
+ 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 requestUri.keyType == consts.KeyType.SSK:
+ elif requestKey.KeyType == consts.KeyType.SSK:
newRequest['URI'] = request['FcPrivateKey']
- filename = requestUri.fileName()
- if filename:
- newRequest['URI'] += '/' + filename
- elif requestUri.keyType == consts.KeyType.USK:
+ if requestKey.filename:
+ newRequest['URI'] += '/' + requestKey.filename
+ elif requestKey.KeyType == consts.KeyType.USK:
newRequest['URI'] = request['FcPrivateKey']
- filename = requestUri.fileName()
- if filename:
- newRequest['URI'] += '/' + filename
+ if requestKey.filename:
+ newRequest['URI'] += '/' + requestKey.filename
self._registerRequest(
newRequest,
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|