Thread: SF.net SVN: fclient:[691] trunk/fclient/src/fclient/lib/fcp2
Status: Pre-Alpha
Brought to you by:
jurner
|
From: <jU...@us...> - 2008-07-20 10:38:16
|
Revision: 691
http://fclient.svn.sourceforge.net/fclient/?rev=691&view=rev
Author: jUrner
Date: 2008-07-20 10:38:14 +0000 (Sun, 20 Jul 2008)
Log Message:
-----------
filenameCollision is now handleFilenameCollision (bool)
Modified Paths:
--------------
trunk/fclient/src/fclient/lib/fcp2/client.py
trunk/fclient/src/fclient/lib/fcp2/test/test_client.py
Modified: trunk/fclient/src/fclient/lib/fcp2/client.py
===================================================================
--- trunk/fclient/src/fclient/lib/fcp2/client.py 2008-07-20 10:35:34 UTC (rev 690)
+++ trunk/fclient/src/fclient/lib/fcp2/client.py 2008-07-20 10:38:14 UTC (rev 691)
@@ -357,13 +357,13 @@
identifier=None,
initTime=None,
persistentUserData='',
- filenameCollision=consts.ConstFilenameCollision.HandleNever,
+ handleFilenameCollision=False,
):
"""Registers a request
@param msg: message to register
@param requestType: (L{consts.ConstRequestType}) type of request to register
- @param filenameCollision: (L{consts.ConstFilenameCollision}) how to handle filename collisions.
- Default is L{consts.ConstFilenameCollision.HandleNever}
+ @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
@param initTime: (int) init time of the request or None to set it to now
@param persistentUserData: (str) anyuser defined persistent data
@@ -381,7 +381,7 @@
msg['RequestType'] = requestType
msg['InitTime'] = time.time() if initTime is None else initTime
if requestType & consts.ConstRequestType.MaskGet:
- msg['FilenameCollision'] = filenameCollision
+ msg['HandleFilenameCollision'] = handleFilenameCollision
msg['UserData'] = userData
msg['PersistentUserData'] = persistentUserData
msg['ClientToken'] = ''
@@ -669,25 +669,22 @@
# handle filename collisions
elif code == consts.ConstProtocolError.DiskTargetExists:
- handleCollision = initialRequest.get('FilenameCollision', consts.ConstFilenameCollision.HandleNever)
- collisionHandled = bool(handleCollision & consts.ConstFilenameCollision.CollisionHandled)
-
- # rename filename
- if handleCollision & consts.ConstFilenameCollision.HandleRename:
- filename = initialRequest['Filename']
- initialRequest['FilenameCollision'] |= consts.ConstFilenameCollision.CollisionHandled
- newFilename = namespace.unique_filename(filename, extensions=1, ispostfixed=collisionHandled)
- initialRequest['Filename'] = newFilename
- initialRequest['Modified'] = {consts.ConstRequestModified.Filename: filename}
- self.sendMessage(initialRequest)
- self.events.RequestModified(initialRequest)
- return True
-
- # don't handle
- else:
- initialRequest['FilenameCollision'] &= ~consts.ConstFilenameCollision.CollisionHandled
-
-
+ handleCollision = initialRequest.get('HandleFilenameCollision', None)
+ if handleCollision is not None: # looks like one of our requests
+ collisionHandled = initialRequest.get('FilenameCollisionHandled', None)
+ if collisionHandled is not None: # one more hint that it is one of our requests
+ if handleCollision:
+ # rename file and resend request
+ initialRequest['FilenameCollisionHandled'] = True
+ filename = initialRequest['Filename']
+ newFilename = namespace.unique_filename(filename, extensions=1, ispostfixed=collisionHandled)
+ initialRequest['Filename'] = newFilename
+ initialRequest['Modified'] = {consts.ConstRequestModified.Filename: filename}
+ initialRequest.updatePersistentParams()
+ self.sendMessage(initialRequest)
+ self.events.RequestModified(initialRequest)
+ return True
+
# handle plugin related request failures
elif code == consts.ConstProtocolError.NoSuchPlugin or code == consts.ConstProtocolError.AccessDenied:
if initialRequest == message.MsgGetPluginInfo:
@@ -1263,7 +1260,7 @@
requestType,
userData,
persistentUserData,
- filenameCollision,
+ handleFilenameCollision=False,
**messageParams
):
"""Requests a key from the node
@@ -1271,7 +1268,8 @@
@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 filenameCollision: what to do if the disk target alreaady exists. One of the FilenameCollision.* consts
+ @param handleFilenameCollision: (bool) if True, the file is automatically renamed if "filename" collides
+ with a file object already present on disk
@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.
@@ -1285,7 +1283,7 @@
self._registerRequest(
msg,
requestType,
- filenameCollision=filenameCollision,
+ handleFilenameCollision=handleFilenameCollision,
persistentUserData=persistentUserData,
userData=userData,
)
@@ -1340,8 +1338,7 @@
consts.ConstRequestType.GetData,
userData,
persistentUserData,
- consts.ConstFilenameCollision.HandleNever,
-
+
# Fcp params
AllowedMimeTypes = allowedMimeTypes,
BinaryBlob=binaryBlob,
@@ -1373,7 +1370,7 @@
userData=None,
persistentUserData='',
- filenameCollision=consts.ConstFilenameCollision.HandleNever,
+ handleFilenameCollision=False,
):
"""Requests a file from the node
@@ -1388,7 +1385,8 @@
@param maxSize: (int) maximum size of the file in bytes or None to set no limited
@param persistence: (L{consts.ConstPersistence}) persistence of the request
@param priorityClass: (L{consts.ConstPriority}) priority of the request
- @param filenameCollision: what to do if the disk target alreaady exists. One of the FilenameCollision.* consts
+ @param handleFilenameCollision: (bool) if True, the file is automatically renamed if "filename" collides
+ with a file object already present on disk
@param userData: any non persistent data to associate to the request
@param persistentUserData: any string to associate to the request as persistent data
@@ -1408,7 +1406,7 @@
consts.ConstRequestType.GetFile,
userData,
persistentUserData,
- filenameCollision,
+ handleFilenameCollision=handleFilenameCollision,
# Fcp params
AllowedMimeTypes = allowedMimeTypes,
@@ -1468,8 +1466,7 @@
consts.ConstRequestType.GetKeyInfo,
userData,
persistentUserData,
- consts.ConstFilenameCollision.HandleNever,
-
+
# Fcp params
Global=False,
DSOnly=dsOnly,
Modified: trunk/fclient/src/fclient/lib/fcp2/test/test_client.py
===================================================================
--- trunk/fclient/src/fclient/lib/fcp2/test/test_client.py 2008-07-20 10:35:34 UTC (rev 690)
+++ trunk/fclient/src/fclient/lib/fcp2/test/test_client.py 2008-07-20 10:38:14 UTC (rev 691)
@@ -2507,7 +2507,7 @@
self.failIf(requestsAll)
- def test_filenameCollision_HandleRename(self):
+ def test_filenameCollision_doHandle(self):
self.connectClient()
# request a file
@@ -2519,7 +2519,7 @@
myIdentifier = self.client.getFile(
myKey,
fpath,
- filenameCollision=fcp2.ConstFilenameCollision.HandleRename,
+ handleFilenameCollision=True,
)
myRequest = self.client.getRequest(myIdentifier)
requestsAll = self.client.getRequests()
@@ -2549,12 +2549,8 @@
self.assertNotEqual(msg['Filename'], fpath)
# check flags
- filenameCollision = msg['FilenameCollision']
- self.assertEqual(
- filenameCollision & fcp2.ConstFilenameCollision.MaskHandle,
- fcp2.ConstFilenameCollision.HandleRename
- )
- self.failUnless(filenameCollision & fcp2.ConstFilenameCollision.CollisionHandled)
+ self.failUnless(myRequest['HandleFilenameCollision'])
+ self.failUnless(myRequest['FilenameCollisionHandled'])
self.assertHasNextEvent(None)
self.assertHasNextMessage(None)
@@ -2563,7 +2559,7 @@
self.failIf(requestsAll)
- def test_filenameCollision_HandleNever(self):
+ def test_filenameCollision_doNotHandle(self):
self.connectClient()
# request a file
@@ -2575,7 +2571,7 @@
myIdentifier = self.client.getFile(
myKey,
fpath,
- filenameCollision=fcp2.ConstFilenameCollision.HandleNever,
+ handleFilenameCollision=False,
)
myRequest = self.client.getRequest(myIdentifier)
requestsAll = self.client.getRequests()
@@ -2597,6 +2593,10 @@
Global='false',
)
+ # check flags
+ self.failIf(myRequest['HandleFilenameCollision'])
+ self.failIf(myRequest['FilenameCollisionHandled'])
+
# client schould send no messages and trigger a RequestFailed event
self.assertHasNextEvent(self.client.events.RequestFailed)
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jU...@us...> - 2008-07-20 10:39:36
|
Revision: 692
http://fclient.svn.sourceforge.net/fclient/?rev=692&view=rev
Author: jUrner
Date: 2008-07-20 10:39:36 +0000 (Sun, 20 Jul 2008)
Log Message:
-----------
filenameCollision consts no longer needed
Modified Paths:
--------------
trunk/fclient/src/fclient/lib/fcp2/__init__.py
trunk/fclient/src/fclient/lib/fcp2/consts.py
Modified: trunk/fclient/src/fclient/lib/fcp2/__init__.py
===================================================================
--- trunk/fclient/src/fclient/lib/fcp2/__init__.py 2008-07-20 10:38:14 UTC (rev 691)
+++ trunk/fclient/src/fclient/lib/fcp2/__init__.py 2008-07-20 10:39:36 UTC (rev 692)
@@ -17,7 +17,7 @@
from .client import Client
from .config import (Config, ConfigDataType, ConfigItem, ConfigKeySep, ConfigValueClass)
from .consts import (ConstByteAmountPostfix, ConstConnectReason, ConstDebugVerbosity, ConstDisconnectReason,
- ConstFetchError, ConstFilenameCollision, ConstInsertError, ConstKeyType, ConstLogMessages,
+ ConstFetchError, ConstInsertError, ConstKeyType, ConstLogMessages,
ConstLogger, ConstMessage, ConstPeerNodeStatus, ConstPeerNoteType, ConstPersistence,
ConstPriority, ConstProtocolError, ConstPutDirType, ConstRequestModified, ConstRequestStatus,
ConstRequestType, ConstReturnType, ConstTimeDeltaPostfix, ConstUploadFrom, ConstVerbosity,
Modified: trunk/fclient/src/fclient/lib/fcp2/consts.py
===================================================================
--- trunk/fclient/src/fclient/lib/fcp2/consts.py 2008-07-20 10:38:14 UTC (rev 691)
+++ trunk/fclient/src/fclient/lib/fcp2/consts.py 2008-07-20 10:39:36 UTC (rev 692)
@@ -175,19 +175,6 @@
PermanentRedirect = 27 # 'USK@.../-1/' for example will always fail and return a key pointing to the current edition
NotAllDataFound = 28
-class ConstFilenameCollision(_BaseBitFlags):
- """Filename collision flags
- @cvar HandleNever: don't handle filename collisions
- @cvar HandleRename: rename file on collisions
- @cvar MaskHandle: bitmask indicating if collisions are hadled or not
- @cvar CollisonHandled: if this bit is set, a collision has actually been handled
- """
- HandleNever = 0x0
- HandleRename = 0x1
-
- MaskHandle = HandleRename
-
- CollisionHandled = 0x10000000 # a filename collision has already been handled
class ConstInsertError(Exception):
"""All insert errors supported by the client"""
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jU...@us...> - 2008-07-20 11:47:13
|
Revision: 694
http://fclient.svn.sourceforge.net/fclient/?rev=694&view=rev
Author: jUrner
Date: 2008-07-20 11:46:26 +0000 (Sun, 20 Jul 2008)
Log Message:
-----------
permanent redirect are now handled automatically (if desired)
(should work in theory)
Modified Paths:
--------------
trunk/fclient/src/fclient/lib/fcp2/client.py
trunk/fclient/src/fclient/lib/fcp2/consts.py
trunk/fclient/src/fclient/lib/fcp2/test/test_client.py
Modified: trunk/fclient/src/fclient/lib/fcp2/client.py
===================================================================
--- trunk/fclient/src/fclient/lib/fcp2/client.py 2008-07-20 10:50:47 UTC (rev 693)
+++ trunk/fclient/src/fclient/lib/fcp2/client.py 2008-07-20 11:46:26 UTC (rev 694)
@@ -358,6 +358,7 @@
initTime=None,
persistentUserData='',
handleFilenameCollision=False,
+ handlePermanentRedirect=False,
):
"""Registers a request
@param msg: message to register
@@ -368,7 +369,8 @@
@param initTime: (int) init time of the request or None to set it to now
@param persistentUserData: (str) anyuser defined persistent data
@param userData: (any) any user defined non persistent data
-
+ @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
@return: (str) identifer of therequest
@note: the identifier returned is unique to the client but may not be unique to the node
"""
@@ -382,6 +384,7 @@
msg['InitTime'] = time.time() if initTime is None else initTime
if requestType & consts.ConstRequestType.MaskGet:
msg['HandleFilenameCollision'] = handleFilenameCollision
+ msg['HandlePermanentRedirect'] = handlePermanentRedirect
msg['UserData'] = userData
msg['PersistentUserData'] = persistentUserData
msg['ClientToken'] = ''
@@ -855,16 +858,27 @@
self.events.RequestRemoved(initialRequest)
return True
+ if code == consts.ConstFetchError.PermanentRedirect:
+ if initialRequest['HandlePermanentRedirect']:
+ initialRequest['PermanentRedirectHandled'] = True
+ initialRequest['Modified'] = {consts.ConstRequestModified.PermanentRedirect: initialRequest['URI']}
+ initialRequest['URI'] = msg['RedirectURI']
+ initialRequest.updatePersistentParams()
+ self.events.RequestModified(initialRequest)
+ self.sendMessage(initialRequest)
+ return True
+
# check if it is one of our requests for key information
if code == consts.ConstFetchError.TooBig and initialRequest['RequestType'] & consts.ConstRequestType.GetKeyInfo:
initialRequest['MetadataContentType'] = msg.get('ExpectedMetadata.ContentType', '')
initialRequest['DataLength'] = msg.get('ExpectedDataLength', -1)
initialRequest['RequestStatus'] |= consts.ConstRequestStatus.Success
self._finalizeRequest(msg, initialRequest, self.events.RequestCompleted)
- else:
- initialRequest['ErrorMessage'] = msg
- initialRequest['RequestStatus'] |= consts.ConstRequestStatus.Error
- self._finalizeRequest(msg, initialRequest, self.events.RequestFailed)
+ return True
+
+ initialRequest['ErrorMessage'] = msg
+ initialRequest['RequestStatus'] |= consts.ConstRequestStatus.Error
+ self._finalizeRequest(msg, initialRequest, self.events.RequestFailed)
return True
@@ -1261,6 +1275,7 @@
userData,
persistentUserData,
handleFilenameCollision=False,
+ handlePermanentRedirect=False,
**messageParams
):
"""Requests a key from the node
@@ -1270,6 +1285,8 @@
@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.
@@ -1284,6 +1301,7 @@
msg,
requestType,
handleFilenameCollision=handleFilenameCollision,
+ handlePermanentRedirect=handlePermanentRedirect,
persistentUserData=persistentUserData,
userData=userData,
)
@@ -1305,6 +1323,7 @@
userData=None,
persistentUserData='',
+ handlePermanentRedirect=False,
):
"""Requests datae from the node
@@ -1320,6 +1339,8 @@
@param priorityClass: (L{consts.ConstPriority}) 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
+ @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
@return: (str) request identifier
@@ -1338,6 +1359,7 @@
consts.ConstRequestType.GetData,
userData,
persistentUserData,
+ handlePermanentRedirect=handlePermanentRedirect,
# Fcp params
AllowedMimeTypes = allowedMimeTypes,
@@ -1371,6 +1393,7 @@
userData=None,
persistentUserData='',
handleFilenameCollision=False,
+ handlePermanentRedirect=False,
):
"""Requests a file from the node
@@ -1385,11 +1408,14 @@
@param maxSize: (int) maximum size of the file in bytes or None to set no limited
@param persistence: (L{consts.ConstPersistence}) persistence of the request
@param priorityClass: (L{consts.ConstPriority}) 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
@param handleFilenameCollision: (bool) if True, the file is automatically renamed if "filename" collides
with a file object already present on disk
- @param userData: any non persistent data to associate to the request
- @param persistentUserData: any string to associate to the request as persistent data
+ @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
+
@return: (str) request identifier
@event: (L{events.Events.RequestCompleted}) triggered when the request is complete
@@ -1407,6 +1433,7 @@
userData,
persistentUserData,
handleFilenameCollision=handleFilenameCollision,
+ handlePermanentRedirect=handlePermanentRedirect,
# Fcp params
AllowedMimeTypes = allowedMimeTypes,
@@ -1436,6 +1463,7 @@
userData=None,
persistentUserData='',
+ handlePermanentRedirect=False,
):
"""Requests info about a key
@@ -1448,6 +1476,8 @@
@param priorityClass: (L{consts.ConstPriority}) 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
+ @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
@return: (str) request identifier
@@ -1466,6 +1496,7 @@
consts.ConstRequestType.GetKeyInfo,
userData,
persistentUserData,
+ handlePermanentRedirect=handlePermanentRedirect,
# Fcp params
Global=False,
Modified: trunk/fclient/src/fclient/lib/fcp2/consts.py
===================================================================
--- trunk/fclient/src/fclient/lib/fcp2/consts.py 2008-07-20 10:50:47 UTC (rev 693)
+++ trunk/fclient/src/fclient/lib/fcp2/consts.py 2008-07-20 11:46:26 UTC (rev 694)
@@ -418,15 +418,17 @@
@cvar Identifier: the identifier has been moodified
@cvar PersistentUserData: persistent user data has been modified
@cvar PriorityClass: the priority class has been modified
+ @cvar PermanentRedirect: url of a request has been modified because of a redirect
@note: the FcModified member of the params dict of a request may contain
one or more of the bitflags
"""
Null = 0x0
- Filename = 0x8
+ Filename = 0x2
Identifier = 0x4
- PersistentUserData = 0x1
- PriorityClass = 0x2
+ PersistentUserData = 0x8
+ PriorityClass = 0x10
+ PermanentRedirect = 0x20
class ConstRequestStatus(_BaseBitFlags):
"""Request status flags
Modified: trunk/fclient/src/fclient/lib/fcp2/test/test_client.py
===================================================================
--- trunk/fclient/src/fclient/lib/fcp2/test/test_client.py 2008-07-20 10:50:47 UTC (rev 693)
+++ trunk/fclient/src/fclient/lib/fcp2/test/test_client.py 2008-07-20 11:46:26 UTC (rev 694)
@@ -2607,7 +2607,88 @@
self.assertHasNextMessage(None)
self.failIf(requestsAll)
+#***********************************************************************************
+#
+#***********************************************************************************
+class TestHandlePermanentRedirect(BaseTestClient):
+
+ def test_doHandleRedirect(self):
+ self.connectClient()
+
+# request a file
+ myKey = fcp2.Key('USK@blah,blah,blah/foo/-1')
+ myIdentifier = self.client.getData(
+ myKey,
+ handlePermanentRedirect=True,
+ )
+ myRequest = self.client.getRequest(myIdentifier)
+ requestsAll = self.client.getRequests()
+ # client schould send a ClientGet
+ self.assertHasNextMessage(fcp2.MsgClientGet)
+
+ # respond with a Getfailed
+ self.sendResponseMessage(
+ 'GetFailed',
+ Identifier=myIdentifier,
+ Code=27, # PermanentRedirect
+ RedirectURI=fcp2.Key('USK@blah,blah,blah/foo/99'),
+ )
+
+ # check if RequestModified event has been triggered
+ msg = self.assertHasNextEvent(
+ self.client.events.RequestModified,
+ fcp2.MsgClientGet,
+ )
+
+ modified = msg['Modified'][fcp2.ConstRequestModified.PermanentRedirect]
+ self.assertEqual(modified, myKey)
+
+ # check flags
+ self.failUnless(myRequest['HandlePermanentRedirect'])
+ self.failUnless(myRequest['PermanentRedirectHandled'])
+
+ # client should resend request
+ self.assertHasNextMessage(fcp2.MsgClientGet)
+ self.assertHasNextEvent(None)
+ self.assertHasNextMessage(None)
+
+
+ def test_doNotHandleRedirect(self):
+ self.connectClient()
+
+# request a file
+ myKey = fcp2.Key('USK@blah,blah,blah/foo/-1')
+ myIdentifier = self.client.getData(
+ myKey,
+ handlePermanentRedirect=False,
+ )
+ myRequest = self.client.getRequest(myIdentifier)
+ requestsAll = self.client.getRequests()
+
+ # client schould send a ClientGet
+ self.assertHasNextMessage(fcp2.MsgClientGet)
+
+ # respond with a Getfailed
+ self.sendResponseMessage(
+ 'GetFailed',
+ Identifier=myIdentifier,
+ Code=27, # PermanentRedirect
+ RedirectURI=fcp2.Key('USK@blah,blah,blah/foo/99'),
+ )
+
+ # check if RequestModified event has been triggered
+ msg = self.assertHasNextEvent(
+ self.client.events.RequestFailed,
+ fcp2.MsgClientGet,
+ )
+
+ # check flags
+ self.failIf(myRequest['HandlePermanentRedirect'])
+ self.failIf(myRequest['PermanentRedirectHandled'])
+ self.assertHasNextEvent(None)
+ self.assertHasNextMessage(None)
+
#***********************************************************************************
#
#***********************************************************************************
@@ -2996,6 +3077,7 @@
Test_DDA,
TestCollisions,
+ TestHandlePermanentRedirect,
Test_getPluginInfo,
Test_sendPluginMessage,
Test_generateKeypair,
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jU...@us...> - 2008-07-20 17:55:03
|
Revision: 697
http://fclient.svn.sourceforge.net/fclient/?rev=697&view=rev
Author: jUrner
Date: 2008-07-20 17:55:11 +0000 (Sun, 20 Jul 2008)
Log Message:
-----------
removed unused ConstPutDirType
Modified Paths:
--------------
trunk/fclient/src/fclient/lib/fcp2/__init__.py
trunk/fclient/src/fclient/lib/fcp2/consts.py
Modified: trunk/fclient/src/fclient/lib/fcp2/__init__.py
===================================================================
--- trunk/fclient/src/fclient/lib/fcp2/__init__.py 2008-07-20 11:53:59 UTC (rev 696)
+++ trunk/fclient/src/fclient/lib/fcp2/__init__.py 2008-07-20 17:55:11 UTC (rev 697)
@@ -19,7 +19,7 @@
from .consts import (ConstByteAmountPostfix, ConstConnectReason, ConstDebugVerbosity, ConstDisconnectReason,
ConstFetchError, ConstInsertError, ConstKeyType, ConstLogMessages,
ConstLogger, ConstMessage, ConstPeerNodeStatus, ConstPeerNoteType, ConstPersistence,
- ConstPriority, ConstProtocolError, ConstPutDirType, ConstRequestModified, ConstRequestStatus,
+ ConstPriority, ConstProtocolError, ConstRequestModified, ConstRequestStatus,
ConstRequestType, ConstReturnType, ConstTimeDeltaPostfix, ConstUploadFrom, ConstVerbosity,
Error, ErrorIOBroken, ErrorIOClosed, ErrorIOConnectFailed, ErrorIOTimeout, ErrorMessageParse,
FcpFalse, FcpTrue)
Modified: trunk/fclient/src/fclient/lib/fcp2/consts.py
===================================================================
--- trunk/fclient/src/fclient/lib/fcp2/consts.py 2008-07-20 11:53:59 UTC (rev 696)
+++ trunk/fclient/src/fclient/lib/fcp2/consts.py 2008-07-20 17:55:11 UTC (rev 697)
@@ -408,10 +408,6 @@
DarknetPeerOnly = 31
NoSuchPlugin = 32
-class ConstPutDirType:
- Complex = 'complex'
- Disk = 'disk'
-
class ConstRequestModified(_BaseBitFlags):
"""Flags indicating what aspect of a request has been modified
@cvar Filename: the filename has been modified
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
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[requestIdenti...
[truncated message content] |
|
From: <jU...@us...> - 2008-07-25 07:08:07
|
Revision: 722
http://fclient.svn.sourceforge.net/fclient/?rev=722&view=rev
Author: jUrner
Date: 2008-07-25 07:08:16 +0000 (Fri, 25 Jul 2008)
Log Message:
-----------
RequestRestored has gone. use RequestStarted
Modified Paths:
--------------
trunk/fclient/src/fclient/lib/fcp2/client.py
trunk/fclient/src/fclient/lib/fcp2/test/test_client.py
Modified: trunk/fclient/src/fclient/lib/fcp2/client.py
===================================================================
--- trunk/fclient/src/fclient/lib/fcp2/client.py 2008-07-25 07:07:59 UTC (rev 721)
+++ trunk/fclient/src/fclient/lib/fcp2/client.py 2008-07-25 07:08:16 UTC (rev 722)
@@ -905,11 +905,9 @@
if 'Started' in initialRequest.params:
del initialRequest.params['Started']
initialRequest['RequestStatus'] |= consts.ConstRequestStatus.Restored
- self.events.RequestRestored(initialRequest)
- return True
-
- #TODO: ignore handshake?
- return False
+
+ self.events.RequestStarted(initialRequest)
+ return True
elif msg == message.MsgPersistentRequestModified:
@@ -1395,7 +1393,7 @@
IgnoreDS=ignoreDS,
Persistence=persistence,
PriorityClass=priorityClass,
- ReturnType=consts.ConstReturnType.Direct,
+ ReturnType=consts.ConstReturnType.Disk,
Verbosity=consts.ConstVerbosity.ReportProgress,
)
if allowedMimeTypes is not None: msg['AllowedMimeTypes'] = allowedMimeTypes
Modified: trunk/fclient/src/fclient/lib/fcp2/test/test_client.py
===================================================================
--- trunk/fclient/src/fclient/lib/fcp2/test/test_client.py 2008-07-25 07:07:59 UTC (rev 721)
+++ trunk/fclient/src/fclient/lib/fcp2/test/test_client.py 2008-07-25 07:08:16 UTC (rev 722)
@@ -1120,7 +1120,7 @@
self.failUnless(myIdentifier in requestsAll)
myRequest = self.client.getRequest(myIdentifier)
msg = self.assertHasNextEvent(
- self.client.events.RequestRestored,
+ self.client.events.RequestStarted,
fcp2.MsgClientGet,
('Identifier', myIdentifier),
('RequestStatus', fcp2.ConstRequestStatus.Restored), # no RequestStatus.Pending flag should be set here
@@ -1222,7 +1222,7 @@
self.failUnless(myIdentifier in requestsAll)
- self.assertHasNextEvent(None)
+ self.assertHasNextEvent(self.client.events.RequestStarted)
self.assertHasNextMessage(None)
self.failUnless(self.ioOpen())
@@ -1915,7 +1915,7 @@
Started='false',
**myRequest.params
)
- #self.assertNextMessage(fcp2.MsgClientGet)
+ self.assertHasNextEvent(self.client.events.RequestStarted)
# test modify persistent user data
@@ -1963,6 +1963,7 @@
Started='false',
**myRequest.params
)
+ self.assertHasNextEvent(self.client.events.RequestStarted)
# test modify persistent user data
self.client.modifyRequest(myIdentifier, persistentUserData='bar', priorityClass=fcp2.ConstPriority.High)
@@ -2122,7 +2123,7 @@
# check if the client restored the request
msg = self.assertHasNextEvent(
- self.client.events.RequestRestored,
+ self.client.events.RequestStarted,
fcp2.MsgClientGet,
('Identifier', myIdentifier),
('RequestStatus', fcp2.ConstRequestStatus.Restored), # no RequestStatus.Pending flag should be set here
@@ -2217,7 +2218,7 @@
)
self.assertEqual(len(requestsAll), 1)
- self.assertHasNextEvent(None)
+ self.assertHasNextEvent(self.client.events.RequestStarted)
self.assertHasNextMessage(None)
@@ -2371,7 +2372,7 @@
)
self.assertEqual(len(requestsAll), 1)
- self.assertHasNextEvent(None)
+ self.assertHasNextEvent(self.client.events.RequestStarted)
self.assertHasNextMessage(None)
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|