SF.net SVN: fclient: [85] trunk/sandbox/fcp/fcp2_0_client.py
Status: Pre-Alpha
Brought to you by:
jurner
|
From: <ju...@us...> - 2008-01-29 11:28:05
|
Revision: 85
http://fclient.svn.sourceforge.net/fclient/?rev=85&view=rev
Author: jurner
Date: 2008-01-29 03:28:06 -0800 (Tue, 29 Jan 2008)
Log Message:
-----------
Started implementing python <--> fcp value type mapping
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-01-29 11:27:31 UTC (rev 84)
+++ trunk/sandbox/fcp/fcp2_0_client.py 2008-01-29 11:28:06 UTC (rev 85)
@@ -46,7 +46,6 @@
import atexit
-import base64
import cPickle
import logging
import os
@@ -157,8 +156,6 @@
ConnectReason,
DebugVerbosity,
DisconnectReason,
- FcpTrue,
- FcpFalse,
FetchError,
FilenameCollision,
InsertError,
@@ -229,7 +226,7 @@
):
"""
@param conectionName: name of the connection or None to use an arbitrary connection name
- @param debugVerbosity: verbosity level for debugging. Default is L{Verbosity.Warning}
+ @param debugVerbosity: verbosity level for debugging. Default is L{DebugVerbosity.Warning}
@ivar events: events the client supports
"""
@@ -267,8 +264,8 @@
# persistent params that will go into identifier
'FcSubType': msgSubType, # identifies sub message types
- 'FcInitTime': self.fcpTime(initTime), # when was the request started?
- 'FcFilenameCollision': filenameCollision, # handle fielanem collisions?
+ 'FcInitTime': initTime, # when was the request started?
+ 'FcFilenameCollision': filenameCollision, # handle fielanem collisions?
'FcPersistentUserData': persistentUserData, # any user defined persistent data
# non persistent params
@@ -349,9 +346,6 @@
if fcParams is None:
return None
- # have to re-adjust initTime to python time
- fcParams[self.FcParams.IInitTime] = self.pythonTime(fcParams[self.FcParams.IInitTime])
-
# add additional params to msg
msg = self._addFcParamsToRequest(
msg,
@@ -370,45 +364,8 @@
return msg
-
-
###############################################################
##
- ## Fcp <--> Python mappings
- ##
- ###############################################################
- def fcpBool(self, pythonBool):
- """Converts a python bool to a fcp bool
- @param pythonBool: (bool)
- @return: (str) 'true' or 'false'
- """
- return self.FcpTrue if pythonBool else self.FcpFalse
-
- def fcpTime(self, pythonTime):
- """Converts a python time value to a fcp time value
- @param fcpTime: (int, str) time to convert
- @raise ValueError: if the python time could not be converted
- @return: (int) fcp time
- """
- return pythonTime * 1000
-
- def pythonBool(self, fcpBool):
- """Converts a fcp bool to a python bool
- @param pythonBool: 'true' or 'false'
- @return: (bool) True or False
- """
- return fcpBool == self.FcpTrue
-
- def pythonTime(self, fcpTime):
- """Converts a fcp time value to a python time value
- @param fcpTime: (int, str) time to convert
- @raise ValueError: if the fcp time could not be converted
- @return: (int) python time
- """
- return int(fcpTime) / 1000
-
- ###############################################################
- ##
## connection related methods
##
###############################################################
@@ -520,7 +477,7 @@
def setDebugVerbosity(self, debugVerbosity):
"""Sets the verbosity level of the client
- @note: see L{Verbosity}
+ @note: see L{DebugVerbosity}
"""
self._log.setLevel(debugVerbosity)
@@ -604,14 +561,14 @@
elif code == self.ProtocolError.DDADenied:
ddaRequestMsg = self.Message(self.Message.MessageTestDDARequest)
if initialRequest.name == self.Message.MessageClientGet:
- ddaRequestMsg['WantWriteDirectory'] = self.FcpTrue
+ ddaRequestMsg['WantWriteDirectory'] = True
directory = os.path.dirname(initialRequest['Filename'])
else:
#TODO: determine directory for other cases
raise RuntimeError(NotImplemented)
- ddaRequestMsg['WantReadDirectory'] = self.FcpTrue
+ ddaRequestMsg['WantReadDirectory'] = True
directory = None
ddaRequestMsg['Directory'] = directory
@@ -621,7 +578,7 @@
'Directory': directory,
'Replied': False,
'TmpFile': None,
- 'WantWrite': self.pythonBool(ddaRequestMsg.get('WantWriteDirectory', self.FcpFalse)),
+ 'WantWrite': ddaRequestMsg.get('WantWriteDirectory', False),
'ErrorMsg': msg,
}
self._ddaTests.append(initialRequest)
@@ -729,15 +686,15 @@
# check if test was sucessful
testFailed = False
if wantWrite:
- testFailed = not self.pythonBool(msg.params.get('WriteDirectoryAllowed', self.FcpFalse) )
+ testFailed = not msg.params.get('WriteDirectoryAllowed', False)
else:
- testFailed = not self.pythonBool(msg.params.get('ReadDirectoryAllowed', self.FcpFalse) )
+ testFailed = not msg.params.get('ReadDirectoryAllowed', False)
if testFailed:
#TODO: check if errorMsg gives reasonable feedback
- del self._request[initialRequest['Identifier']]
+ del self._requests[initialRequest['Identifier']]
initialRequest['FcStatus'] = self.Message.StatusError | self.Message.StatusRemoved
initialRequest['FcErrorMessage'] = initialRequest['FcTestDDA']['ErrorMsg']
self.events.ProtocolError(initialRequest)
@@ -801,8 +758,8 @@
if code == self.FetchError.TooBig and initialRequest['FcSubType'] == self.Message.SubTypeGetKeyInfo:
initialRequest['FcStatus'] = self.Message.StatusComplete
initialRequest['FcMetadataContentType'] = msg.get('ExpectedMetadata.ContentType', '')
- initialRequest['FcDataLength'] = msg.get('ExpectedDataLength', '')
- initialRequest['FcProgressCompleted'] = self.FcpTrue
+ initialRequest['FcDataLength'] = msg.get('ExpectedDataLength', -1)
+ initialRequest['FcProgressCompleted'] = True
#TODO: check if Fcp removed the request
self.events.RequestCompleted(initialRequest)
@@ -955,10 +912,6 @@
return True
elif msg.name == self.Message.MessagePeerNote:
- note = msg.get('NoteText', '')
- if note:
- note = base64.decodestring(note)
- msg['NoteText'] = note
self.events.PeerNote(msg)
return True
@@ -1068,13 +1021,13 @@
#########################################################
#TODO: WithDefault never returns defaults
def getConfig(self,
- withCurrent=consts.FcpTrue,
- withDefaults=consts.FcpTrue,
- withExpertFlag=consts.FcpTrue,
- withForceWriteFlag=consts.FcpTrue,
- withSortOrder=consts.FcpTrue,
- withShortDescription=consts.FcpTrue,
- withLongDescription=consts.FcpTrue,
+ withCurrent=True,
+ withDefaults=True,
+ withExpertFlag=True,
+ withForceWriteFlag=True,
+ withSortOrder=True,
+ withShortDescription=True,
+ withLongDescription=True,
):
"""
@event: ConfigData(event, msg)
@@ -1155,9 +1108,9 @@
uri,
allowedMimeTypes=None,
- binaryBlob=consts.FcpFalse,
- dsOnly=consts.FcpFalse,
- ignoreDS=consts.FcpFalse,
+ binaryBlob=False,
+ dsOnly=False,
+ ignoreDS=False,
maxRetries=None,
maxSize=None,
persistence=consts.Persistence.Connection,
@@ -1171,9 +1124,9 @@
@param uri: uri of the file to request (may contain prefixes like 'freenet:' or 'http://')
@param allowedMimeTypes: (str) list of allowed mime types
- @param binaryBlob: if FcpTrue, the file is retrieved as binary blob file
- @param dsOnly: if FcpTrue, retrieves the file from the local data store only
- @param ignoreDs: If FcpTrue, ignores the local data store
+ @param binaryBlob: if True, the file is retrieved as binary blob file
+ @param dsOnly: if True, retrieves the file from the local data store only
+ @param ignoreDs: If True, ignores the local data store
@param maxRetries: (int) maximum number of retries or -1 to retry forver or None to leave it to the node to decide
@param maxSize: (int) maximum size of the file in bytes or None to set no limited
@param persistence: persistence of the request as one of the L{consts.Persistence} constants
@@ -1195,7 +1148,7 @@
# Fcp params
AllowedMimeTypes = allowedMimeTypes,
BinaryBlob=binaryBlob,
- Global=self.FcpFalse,
+ Global=False,
DSOnly=dsOnly,
Identifier=None,
IgnoreDS=ignoreDS,
@@ -1214,9 +1167,9 @@
filename,
allowedMimeTypes=None,
- binaryBlob=consts.FcpFalse,
- dsOnly=consts.FcpFalse,
- ignoreDS=consts.FcpFalse,
+ binaryBlob=False,
+ dsOnly=False,
+ ignoreDS=False,
maxRetries=None,
maxSize=None,
persistence=consts.Persistence.Connection,
@@ -1232,9 +1185,9 @@
@param filename: (full path) filename to store the file to
@param allowedMimeTypes: (str) list of allowed mime types
- @param binaryBlob: if FcpTrue, the file is retrieved as binary blob file
- @param dsOnly: if FcpTrue, retrieves the file from the local data store only
- @param ignoreDs: If FcpTrue, ignores the local data store
+ @param binaryBlob: if True, the file is retrieved as binary blob file
+ @param dsOnly: if True, retrieves the file from the local data store only
+ @param ignoreDs: If True, ignores the local data store
@param maxRetries: (int) maximum number of retries or -1 to retry forver or None to leave it to the node to decide
@param maxSize: (int) maximum size of the file in bytes or None to set no limited
@param persistence: persistence of the request as one of the L{consts.Persistence} constants
@@ -1258,7 +1211,7 @@
AllowedMimeTypes = allowedMimeTypes,
BinaryBlob=binaryBlob,
Filename=filename,
- Global=self.FcpFalse,
+ Global=False,
DSOnly=dsOnly,
Identifier=None,
IgnoreDS=ignoreDS,
@@ -1275,8 +1228,8 @@
def getKeyInfo(self,
uri,
- dsOnly=consts.FcpFalse,
- ignoreDS=consts.FcpFalse,
+ dsOnly=False,
+ ignoreDS=False,
maxRetries=None,
persistence=consts.Persistence.Connection,
priorityClass=consts.Priority.Medium,
@@ -1288,8 +1241,8 @@
@param uri: uri of the file to request (may contain prefixes like 'freenet:' or 'http://')
- @param dsOnly: if FcpTrue, retrieves the file from the local data store only
- @param ignoreDs: If FcpTrue, ignores the local data store
+ @param dsOnly: if True, retrieves the file from the local data store only
+ @param ignoreDs: If True, ignores the local data store
@param maxRetries: (int) maximum number of retries or -1 to retry forver or None to leave it to the node to decide
@param persistence: persistence of the request as one of the L{consts.Persistence} constants
@param priorityClass: priority of the request as one of the L{consts.Priority} consts
@@ -1307,7 +1260,7 @@
consts.FilenameCollision.HandleNever,
# Fcp params
- Global=self.FcpFalse,
+ Global=False,
DSOnly=dsOnly,
Identifier=None,
IgnoreDS=ignoreDS,
@@ -1382,14 +1335,14 @@
DataLength=len(data),
#EarlyEncode='false',
#GetCHKOnly='false',
- Global=self.FcpFalse,
+ Global=False,
Identifier=None,
MaxRetries=maxRetries,
DontCompress=dontCompress,
Persistence=persistence,
TergetFilename=targetFilename,
UploadFrom=self.UploadFrom.Direct,
- Verbosity=self.Verbosity.ReportProgressAndCompression,
+ Verbosity=self.Verbosity.ReportProgress | self.Verbosity.ReportCompression,
)
def putFile(self):
@@ -1447,7 +1400,7 @@
msg = self.Message(
self.Message.MessageModifyPersistentRequest,
Identifier=initialRequest['Identifier'],
- Global=self.FcpFalse,
+ Global=False,
)
if persistentUserData is not None:
initialRequest['FcPersistentUserData'] = persistentUserData
@@ -1467,7 +1420,7 @@
initialRequest['FcStatus'] = self.Message.StatusRemoved
self.sendMessage(
self.Message.MessageRemovePersistentRequest,
- Global=self.FcpFalse,
+ Global=False,
Identifier=requestIdentifier,
)
@@ -1578,6 +1531,7 @@
for nodeHello in c.connect(): pass
if nodeHello is not None:
+
#for i in xrange(5):
# c.next()
@@ -1589,7 +1543,7 @@
identifier = c.getData(
'CHK@q4~2soHTd9SOINIoXmg~dn7LNUAOYzN1tHNHT3j4c9E,gcVRtoglEhgqN-DJolXPqJ4yX1f~1gBGh89HNWlFMWQ,AAIC--8/snow_002%20%2810%29.jpg',
- #binaryBlob=c.FcpTrue,
+ #binaryBlob=True,
)
for i in xrange(50):
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|