fclient-commit Mailing List for fclient (Page 30)
Status: Pre-Alpha
Brought to you by:
jurner
You can subscribe to this list here.
| 2007 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
(23) |
Nov
(54) |
Dec
|
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 2008 |
Jan
(17) |
Feb
(209) |
Mar
(63) |
Apr
(31) |
May
(7) |
Jun
(39) |
Jul
(390) |
Aug
(122) |
Sep
(6) |
Oct
|
Nov
|
Dec
|
|
From: <ju...@us...> - 2008-02-21 13:10:12
|
Revision: 237
http://fclient.svn.sourceforge.net/fclient/?rev=237&view=rev
Author: jurner
Date: 2008-02-21 05:10:08 -0800 (Thu, 21 Feb 2008)
Log Message:
-----------
fix: someone set ExtRevision to '@custom@'. Heh! See if we can get away with our int / float conversions
Modified Paths:
--------------
trunk/sandbox/fcp/fcp2_0_types.py
Modified: trunk/sandbox/fcp/fcp2_0_types.py
===================================================================
--- trunk/sandbox/fcp/fcp2_0_types.py 2008-02-21 13:08:36 UTC (rev 236)
+++ trunk/sandbox/fcp/fcp2_0_types.py 2008-02-21 13:10:08 UTC (rev 237)
@@ -727,7 +727,7 @@
'Build': FcpTypeInt,
'CompressionCodecs': FcpTypeInt,
'ExtBuild': FcpTypeInt,
- 'ExtRevision': FcpTypeInt,
+ #'ExtRevision': FcpTypeInt,
'FcpVersion': FcpTypeFloat,
'Testnet': FcpTypeBool,
},
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ju...@us...> - 2008-02-21 13:08:35
|
Revision: 236
http://fclient.svn.sourceforge.net/fclient/?rev=236&view=rev
Author: jurner
Date: 2008-02-21 05:08:36 -0800 (Thu, 21 Feb 2008)
Log Message:
-----------
fix: run did not run untill all requests where completed if a request was removed or modified
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-02-20 17:48:09 UTC (rev 235)
+++ trunk/sandbox/fcp/fcp2_0_client.py 2008-02-21 13:08:36 UTC (rev 236)
@@ -375,7 +375,6 @@
if event is not None:
event(request)
- request['FcRequestStatus'] |= consts.RequestStatus.Completed
if removeRequest:
del self._requests[request['Identifier']]
@@ -765,12 +764,12 @@
elif code == consts.ProtocolError.NoSuchPlugin:
if initialRequest.name == consts.Message.GetPluginInfo:
initialRequest['FcErrorMessage'] = msg
- initialRequest['FcRequestStatus'] |= consts.RequestStatus.Error
+ initialRequest['FcRequestStatus'] |= consts.RequestStatus.Error | consts.RequestStatus.Completed
self._finalizeRequest(msg, initialRequest, self.events.PluginInfoFailed)
return True
elif initialRequest.name == consts.Message.FCPPluginMessage:
initialRequest['FcErrorMessage'] = msg
- initialRequest['FcRequestStatus'] |= consts.RequestStatus.Error
+ initialRequest['FcRequestStatus'] |= consts.RequestStatus.Error | consts.RequestStatus.Completed
self._finalizeRequest(msg, initialRequest, self.events.PluginMessageFailed)
return True
@@ -792,7 +791,7 @@
# NOTE: Fcp already removed the request
initialRequest['FcErrorMessage'] = msg
- initialRequest['FcRequestStatus'] = consts.RequestStatus.Error
+ initialRequest['FcRequestStatus'] |= consts.RequestStatus.Error | consts.RequestStatus.Completed
self._finalizeRequest(msg, initialRequest, self.events.RequestFailed)
return True
@@ -872,7 +871,7 @@
if testFailed:
#TODO: check if errorMsg gives reasonable feedback
- initialRequest['FcRequestStatus'] = consts.RequestStatus.Error
+ initialRequest['FcRequestStatus'] = consts.RequestStatus.Error | consts.RequestStatus.Completed
initialRequest['FcErrorMessage'] = initialRequest['FcTestDDA']['ErrorMsg']
self._finalizeRequest(msg, initialRequest, self.events.RequestFailed)
return True
@@ -906,7 +905,7 @@
if initialRequest is None:
return False
- initialRequest['FcRequestStatus'] |= consts.RequestStatus.Success
+ initialRequest['FcRequestStatus'] |= consts.RequestStatus.Success | consts.RequestStatus.Completed
initialRequest.data = msg.data
self._finalizeRequest(msg, initialRequest, self.events.RequestCompleted)
return True
@@ -923,7 +922,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, too.
+ # All Data.
if initialRequest['FcRequestType'] == consts.RequestType.GetData:
if initialRequest['Persistence'] != consts.Persistence.Connection:
self.sendMessage(
@@ -933,9 +932,9 @@
OnlyData=True
)
else:
+ initialRequest['FcRequestStatus'] |= consts.RequestStatus.Completed
self._finalizeRequest(msg, initialRequest, self.events.RequestCompleted)
-
-
+
return True
@@ -951,11 +950,11 @@
if code == consts.FetchError.TooBig and initialRequest['FcRequestType'] == consts.RequestType.GetKeyInfo:
initialRequest['FcMetadataContentType'] = msg.get('ExpectedMetadata.ContentType', '')
initialRequest['FcDataLength'] = msg.get('ExpectedDataLength', -1)
- initialRequest['FcRequestStatus'] |= consts.RequestStatus.Success
+ initialRequest['FcRequestStatus'] |= consts.RequestStatus.Success | consts.RequestStatus.Completed
self._finalizeRequest(msg, initialRequest, self.events.RequestCompleted)
else:
initialRequest['FcErrorMessage'] = msg
- initialRequest['FcRequestStatus'] |= consts.RequestStatus.Error
+ initialRequest['FcRequestStatus'] |= consts.RequestStatus.Error | consts.RequestStatus.Completed
self._finalizeRequest(msg, initialRequest, self.events.RequestFailed)
return True
@@ -1035,7 +1034,7 @@
if initialRequest is None:
return False
- initialRequest['FcRequestStatus'] |= consts.RequestStatus.Removed
+ initialRequest['FcRequestStatus'] |= consts.RequestStatus.Removed | consts.RequestStatus.Completed
self._finalizeRequest(msg, initialRequest, self.events.RequestRemoved)
return True
@@ -1107,7 +1106,7 @@
if code == consts.InsertError.Canceled:
return False
- initialRequest['FcRequestStatus'] |= consts.RequestStatus.Error
+ initialRequest['FcRequestStatus'] |= consts.RequestStatus.Error | consts.RequestStatus.Completed
initialRequest['FcErrorMessage'] = msg
self._finalizeRequest(msg, initialRequest, self.events.RequestFailed)
return True
@@ -1128,7 +1127,7 @@
# TODO: StartupTime and CompletionTime are passed, but
# as long as no corrosponding params are passed in DataFound
# we ignore them
- initialRequest['FcRequestStatus'] |= consts.RequestStatus.Success
+ initialRequest['FcRequestStatus'] |= consts.RequestStatus.Success | consts.RequestStatus.Completed
initialRequest['URI'] = msg['URI']
self._finalizeRequest(msg, initialRequest, self.events.RequestCompleted)
return True
@@ -1195,14 +1194,14 @@
if initialRequest is None:
return False
- initialRequest['FcRequestStatus'] |= consts.RequestStatus.Success
+ initialRequest['FcRequestStatus'] |= consts.RequestStatus.Success | consts.RequestStatus.Completed
self._finalizeRequest(msg, initialRequest, self.events.PluginInfo)
return True
elif msg.name == consts.Message.FCPPluginReply:
if initialRequest is None:
return False
- initialRequest['FcRequestStatus'] |= consts.RequestStatus.Success
+ initialRequest['FcRequestStatus'] |= consts.RequestStatus.Success | consts.RequestStatus.Completed
initialRequest['FcPluginReply'] = msg
self._finalizeRequest(msg, initialRequest, self.events.PluginMessage)
return True
@@ -1236,7 +1235,7 @@
initialRequest['FcPrivateKey'] = insertURI
initialRequest['FcPublicKey'] = requestURI
- initialRequest['FcRequestStatus'] |= consts.RequestStatus.Success
+ initialRequest['FcRequestStatus'] |= consts.RequestStatus.Success | consts.RequestStatus.Completed
self._finalizeRequest(msg, initialRequest, self.events.KeypairGenerated)
return True
@@ -1304,7 +1303,7 @@
# check if we have running requests. Assert False
haveRunningRequests = False
for request in self._requests.values():
- if not request.params['FcRequestStatus'] & consts.RequestStatus.Completed:
+ if not request['FcRequestStatus'] & consts.RequestStatus.Completed:
haveRunningRequests = True
break
@@ -2074,6 +2073,7 @@
return
+ initialRequest['FcRequestStatus'] &= ~consts.RequestStatus.Completed
msg = self.Message(
consts.Message.ModifyPersistentRequest,
Identifier=initialRequest['Identifier'],
@@ -2093,15 +2093,16 @@
@param requestIdentifier: (str) identifier of the request to remove
"""
initialRequest = self._requests[requestIdentifier]
- initialRequest['FcRequestStatus'] |= consts.RequestStatus.Removed
+ initialRequest['FcRequestStatus'] |= consts.RequestStatus.Removed | consts.RequestStatus.Completed
if initialRequest['FcRequestType'] & (consts.RequestType.MaskGet | consts.RequestType.MaskPut):
# remove Persistence.Connection emidiately
- #todo so we make up a PersistentRequestRemoved message
+ # ..make up a PersistentRequestRemoved message for this case
if initialRequest['Persistence'] == consts.Persistence.Connection:
msg = self.Message(consts.Message.PersistentRequestRemoved, Identifier=requestIdentifier, Global=False)
self._finalizeRequest(msg, initialRequest, self.events.RequestRemoved)
else:
+ initialRequest['FcRequestStatus'] &= ~consts.RequestStatus.Completed
self.sendMessage(
consts.Message.RemovePersistentRequest,
Global=False,
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ju...@us...> - 2008-02-20 17:48:44
|
Revision: 235
http://fclient.svn.sourceforge.net/fclient/?rev=235&view=rev
Author: jurner
Date: 2008-02-20 09:48:09 -0800 (Wed, 20 Feb 2008)
Log Message:
-----------
fix: run() method now waits a while to see if persistent requests are waiting
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-02-18 22:00:55 UTC (rev 234)
+++ trunk/sandbox/fcp/fcp2_0_client.py 2008-02-20 17:48:09 UTC (rev 235)
@@ -281,6 +281,7 @@
# basic sizes of keys are: 1k for SSks and 32k for CHKs
# without MaxSize DataFound will have DataLength set to 0 (?!)
MaxSizeKeyInfo = 32768
+ MinimumRunTime = 1 # minimum time (seconds) the client will run when run() is called (FIX: 0001931)
SocketTimeout = 0.1
ExpectedFcpVersion = 2.0
ExpectedNodeBuild = 1107
@@ -923,7 +924,6 @@
# 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, too.
- # Note: All other requests are completed here.
if initialRequest['FcRequestType'] == consts.RequestType.GetData:
if initialRequest['Persistence'] != consts.Persistence.Connection:
self.sendMessage(
@@ -1284,11 +1284,23 @@
@note: a KeyboardInterrupt will stop the client
"""
+ #FIX: 0001931
+ # poll a few times to see if there are persistent requests waiting
+ t0 = time.time()
+ while time.time() - t0 <= self.MinimumRunTime:
+ try:
+ msg = self.next()
+ except KeyboardInterrupt:
+ self._logRuntime.info(consts.LogMessages.KeyboardInterrupt)
+ return
+ if msg.name == consts.Message.ClientSocketDied:
+ return
+
#n = 0
while True:
#n += 1
#if n > 50: break
-
+
# check if we have running requests. Assert False
haveRunningRequests = False
for request in self._requests.values():
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ju...@us...> - 2008-02-18 22:01:05
|
Revision: 234
http://fclient.svn.sourceforge.net/fclient/?rev=234&view=rev
Author: jurner
Date: 2008-02-18 14:00:55 -0800 (Mon, 18 Feb 2008)
Log Message:
-----------
a few fixes
Modified Paths:
--------------
trunk/sandbox/fcp/fcp2_0_uri.py
Modified: trunk/sandbox/fcp/fcp2_0_uri.py
===================================================================
--- trunk/sandbox/fcp/fcp2_0_uri.py 2008-02-18 22:00:15 UTC (rev 233)
+++ trunk/sandbox/fcp/fcp2_0_uri.py 2008-02-18 22:00:55 UTC (rev 234)
@@ -14,7 +14,7 @@
@return: decoded string
@raise TypeError: if the string can not be decoded
- @note: this function handles non-standard encoding as used by freenet (see: freenet/support/base64.java)
+ @note: this function handles non-standard encoding as used by freenet (see: freenet/src/support/base64.java)
"""
# freenet uses - for + and ~ for /
altchars = '-~'
@@ -31,12 +31,14 @@
# KeyType@32 bytes hash, 32 bytes encryption key, 5 bytes extra
#
# all byte components are base64 encoded. Freenet uses base64 without padding
-# and uses the following altchars for urlsave encode: - for + and ~ for /
+# along with the following altchars for urlsave encode: - for + and ~ for /
# see: freenet/support/base64.java
#
# so a key as the user gets it to see is:
# KeyType@43 bytes, 43 bytes, 7 bytes ..of [A-Za-z0-9\-~]
#
+# see: [freenet/src/support/base64.java]
+#
#***************************************************************************************
KeyPat = re.compile(
r'''
@@ -97,7 +99,7 @@
"""Splits the uri
@return: tuple(freenet-key, file-name)
"""
- if self.keyType() != self.KeyType.Invalid:
+ if self.keyType != self.KeyType.Invalid:
head, sep, tail = self.uri.partition('/')
return head, tail
return self.uri, ''
@@ -110,7 +112,8 @@
head, tail = self.split()
if tail:
return tail
- return self.uri
+ return ''
+
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ju...@us...> - 2008-02-18 22:00:17
|
Revision: 233
http://fclient.svn.sourceforge.net/fclient/?rev=233&view=rev
Author: jurner
Date: 2008-02-18 14:00:15 -0800 (Mon, 18 Feb 2008)
Log Message:
-----------
beautifications
Modified Paths:
--------------
trunk/sandbox/fcp/fcp2_0_message.py
Modified: trunk/sandbox/fcp/fcp2_0_message.py
===================================================================
--- trunk/sandbox/fcp/fcp2_0_message.py 2008-02-18 21:59:40 UTC (rev 232)
+++ trunk/sandbox/fcp/fcp2_0_message.py 2008-02-18 22:00:15 UTC (rev 233)
@@ -171,6 +171,8 @@
# value = paramType.pythonToFcp(value)
out.append('>> %s=%s' % (param, value))
+
+ #TODO: append data?
out.append('>>EndMessage')
return '\n'.join(out)
@@ -200,6 +202,7 @@
out.append('%s=%s' % (param, value))
out.append('EndMessage')
- out.append(self.data if self.data is not None else '')
+ out.append('' if self.data is None else self.data)
return '\n'.join(out)
-
+
+
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ju...@us...> - 2008-02-18 21:59:36
|
Revision: 232
http://fclient.svn.sourceforge.net/fclient/?rev=232&view=rev
Author: jurner
Date: 2008-02-18 13:59:40 -0800 (Mon, 18 Feb 2008)
Log Message:
-----------
a few fixes
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-02-18 13:44:25 UTC (rev 231)
+++ trunk/sandbox/fcp/fcp2_0_client.py 2008-02-18 21:59:40 UTC (rev 232)
@@ -544,7 +544,7 @@
# try to Connect socket
if self._socket is not None:
- self.close()
+ self._close(None)
self._socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self._socket.settimeout(self.SocketTimeout)
try:
@@ -573,7 +573,6 @@
elif msg.name == consts.Message.NodeHello:
self._nodeHelloMessage = msg
- self._logMessage.debug(consts.LogMessages.MessageReceived + msg.pprint())
# check if version is ok
if self.versionCheckNodeHello(msg):
self.events.ClientConnected(msg)
@@ -672,10 +671,6 @@
CancelPersistentRequests = 0 # for testing... if True, cancels all PersistentRequests
- if msg.name == consts.Message.ClientSocketTimeout:
- return True
- self._logMessage.debug(consts.LogMessages.MessageReceived + msg.pprint())
-
# check if we have an initial request corrosponding to msg
requestIdentifier = msg.get('Identifier', None)
initialRequest = None if requestIdentifier is None else self._requests.get(requestIdentifier, None)
@@ -1278,6 +1273,7 @@
if dispatch:
self.events.Idle(msg)
else:
+ self._logMessage.debug(consts.LogMessages.MessageReceived + msg.pprint())
if dispatch:
self.handleMessage(msg)
return msg
@@ -1867,8 +1863,7 @@
data=None,
persistentUserData=persistentUserData,
userData=userData,
-
-
+
# fcp params
Filename=filename,
ContentType=contentType,
@@ -1982,9 +1977,9 @@
consts.RequestType.PutData,
insertURI,
#insertURI + 'foo/0/',
- userData,
- persistentUserData,
- data,
+ userData=userData,
+ persistentUserData=persistentUserData,
+ data=data,
# fcp params
ContentType=contentType,
@@ -2205,7 +2200,6 @@
)
-
def modifyPeer(self, identitty, allowLocalAddresses=None, isDisabled=None, isListenOnly=None):
"""Modifies a peer node
@param identitty: identity of the peer node to modify
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ju...@us...> - 2008-02-18 13:44:20
|
Revision: 231
http://fclient.svn.sourceforge.net/fclient/?rev=231&view=rev
Author: jurner
Date: 2008-02-18 05:44:25 -0800 (Mon, 18 Feb 2008)
Log Message:
-----------
added a todo
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-02-18 13:37:05 UTC (rev 230)
+++ trunk/sandbox/fcp/fcp2_0_client.py 2008-02-18 13:44:25 UTC (rev 231)
@@ -150,6 +150,7 @@
# Fcp types vs. Python types
#
# x. Fcp seems to use kibibytes. Autoconvert to kilobytes?
+# x. time intervals
#
#------------------------------------------------------------------------------------------------------------------------------------------------
# logging
@@ -158,10 +159,15 @@
# "save" logger could be useful (like for user feedback).
#
#------------------------------------------------------------------------------------------------------------------------------------------------
+# runtime
+#
+# x. if the socket dies the client disconnects automatically, clearing all requests.
+# No idea how to handle this. Would require at least an EndListPersistentRequest
+# from the node to check wich requests arrived at the node ..and an auto resend
+# requests the node does not know about.
+#
+#------------------------------------------------------------------------------------------------------------------------------------------------
-
-
-
import atexit
import copy
import cPickle
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ju...@us...> - 2008-02-18 13:37:10
|
Revision: 230
http://fclient.svn.sourceforge.net/fclient/?rev=230&view=rev
Author: jurner
Date: 2008-02-18 05:37:05 -0800 (Mon, 18 Feb 2008)
Log Message:
-----------
fix: setDebugVerosity() for all loggers
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-02-18 13:30:13 UTC (rev 229)
+++ trunk/sandbox/fcp/fcp2_0_client.py 2008-02-18 13:37:05 UTC (rev 230)
@@ -621,7 +621,9 @@
"""Sets the verbosity level of the client
@note: see L{consts.DebugVerbosity}
"""
+ self._logEvent.setLevel(debugVerbosity)
self._logMessage.setLevel(debugVerbosity)
+ self._logRuntime.setLevel(debugVerbosity)
def startFreenet(self, cmdline):
@@ -2315,398 +2317,3 @@
return msg['Identifier']
-#*****************************************************************************
-#
-#*****************************************************************************
-if __name__ == '__main__':
-
- Dir = os.path.dirname(os.path.abspath(__file__))
-
- c = FcpClient(
- connectionName='test',
- debugVerbosity=consts.DebugVerbosity.Debug
- )
-
- fpath = os.path.join(Dir, 'test.log')
- handler = logging.FileHandler(fpath, 'w')
- #formatter = logging.Formatter('%(name)s:%(levelname)s:%(funcName)s:%(message)s')
- #handler.setFormatter(formatter)
- logging.getLogger('Fcp.Client').addHandler(handler)
-
-
- nodeHello = c.connect()
- if nodeHello is not None:
-
-
-
- #for i in xrange(10):
- # c.next()
-
-
- def testGetData():
- def cb(event, request):
- pass
- #print request.data
- #c.modifyRequest(request['Identifier'], persistentUserData='foo')
-
- c.events.RequestCompleted += cb
- c.events.RequestFailed += cb
-
- identifier = c.getData(
- 'CHK@q4~2soHTd9SOINIoXmg~dn7LNUAOYzN1tHNHT3j4c9E,gcVRtoglEhgqN-DJolXPqJ4yX1f~1gBGh89HNWlFMWQ,AAIC--8/snow_002%20%2810%29.jpg',
- persistence=consts.Persistence.Connection,
- #binaryBlob=True,
- )
-
- c.run()
- #for i in xrange(50):
- # c.next()
-
- #c.removeRequest(identifier)
- #for i in xrange(5):
- # c.next()
-
- #testGetData()
-
- def testGetFile():
-
- def cb(event, request):
- c.sendMessage(
- #c.consts.Message.RemovePersistentRequest,
- c.consts.Message.ModifyPersistentRequest,
- Identifier=request['Identifier'],
- PriorityClass=0,
- Global=False,
- )
- pass
-
- filename = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'test.jpg')
- print filename
- identifier = c.getFile(
- 'CHK@q4~2soHTd9SOINIoXmg~dn7LNUAOYzN1tHNHT3j4c9E,gcVRtoglEhgqN-DJolXPqJ4yX1f~1gBGh89HNWlFMWQ,AAIC--8/snow_002%20%2810%29.jpg',
- filename,
- filenameCollision=consts.FilenameCollision.HandleRename,
- #persistence=consts.Persistence.Reboot,
- )
-
- c.events.RequestProgress += cb
-
- #c.run()
- for i in xrange(50):
- c.next()
-
- #c.removeRequest(identifier)
- #for i in xrange(5):
- # c.next()
-
- #testGetFile()
-
-
-
- def testGetKeyInfo():
-
-
-
- identifier = c.getKeyInfo(
- 'CHK@q4~2soHTd9SOINIoXmg~dn7LNUAOYzN1tHNHT3j4c9E,gcVRtoglEhgqN-DJolXPqJ4yX1f~1gBGh89HNWlFMWQ,AAIC--8/snow_002%20%2810%29.jpg',
- #persistence=c.consts.Persistence.Reboot,
- )
-
-
- def cb(event, msg):
- if event == c.events.RequestCompleted:
- pass
- #c.sendMessage(c.consts.Message.GetRequestStatus, Identifier=identifier)
- c.events.RequestCompleted += cb
-
- #for i in xrange(55):
- # c.next()
- #c.removeRequest(identifier)
- #for i in xrange(5):
- # c.next()
- c.run()
-
- #testGetKeyInfo()
-
-
- def testPutRedirect():
-
-
-
-
- def cb(event, msg):
- if event == c.events.RequestCompleted:
-
- identifier = c.putRedirect(
- 'HaHaHa',
- msg['URI']
- )
-
- pass
- #c.sendMessage(c.consts.Message.GetRequestStatus, Identifier=identifier)
- #print msg['FcErrorMessage']
-
-
- c.events.RequestCompleted += cb
- c.events.RequestFailed += cb
-
- #c.chkPutData('HaHaHaHa')
-
- #identifier = c.putRedirect(
- # 'foo',
- # 'USK@zQyF2O1o8B4y40w7Twz8y2I9haW3d2DTlxjTHPu7zc8,h2mhQNNE9aQvF~2yKAmKV1uorr7141-QOroBf5hrlbw,AQACAAE/AnotherIndex/0/',
- #'foo/bar'
- #persistence=c.consts.Persistence.Reboot,
- # )
-
- #c.sendMessage(
- # consts.Message.ClientPut,
- # Identifier='blah',
- # URI='KSK@foo',
- # TargetURI='USK@zQyF2O1o8B4y40w7Twz8y2I9haW3d2DTlxjTHPu7zc8,h2mhQNNE9aQvF~2yKAmKV1uorr7141-QOroBf5hrlbw,AQACAAE/AnotherIndex/0/',
- # UploadFrom='redirect',
- # )
-
- c.chkPutData('arggggggggg!')
-
- #for i in xrange(55):
- # c.next()
- #c.removeRequest(identifier)
- #for i in xrange(5):
- # c.next()
- c.run()
-
- #testPutRedirect()
-
-
-
-
-
- def testChkPutData():
- myIdentifier = c.chkPutData(
- 'test123hahaha',
- #persistence=c.Persistence.Reboot,
- )
-
- c.run()
- #for i in xrange(500):
- # c.next()
- #c.removeRequest(myIdentifier)
- #for i in xrange(5):
- # c.next()
-
- #testChkPutData()
-
-
-
- def testChkPutFile():
- fpath = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'test.jpg')
-
- identifier = c.chkPutFile(
- fpath,
- )
- c.run()
- #for i in xrange(500):
- # c.next()
- #c.removeRequest(identifier)
- #for i in xrange(5):
- # c.next()
-
- #testChkPutFile()
-
-
- def testUskPutData():
- def cb(event, request):
- insertURI = request['FcPrivateKey']
- myIdentifier = c.uskPutData(
- 'foo',
- insertURI + 'foo/0/',
- #persistence=consts.Persistence.Reboot,
- )
- #c.removeRequest(myIdentifier)
-
- c.events.KeypairGenerated += cb
- c.generateKeypair(keypairType=consts.KeyType.USK)
-
- #identifier = c.uskPutData(
- #'foo1',
- #'USK@dkbB9DSr6R2WWs0MFsB9BJvN2cRjNxSboanDQNMJVNc,uIi9-1JrCLZ~6MLa8UrxQCMLptu~PzL59hAtorUIStw,AQECAAE/foo/0/',
- #)
- c.run()
-
- #for i in xrange(700):
- # c.next()
-
- #testUskPutData()
-
-
- def testUskPutData():
- def cb(event, request):
- insertURI = request['FcPrivateKey']
- insertURI = 'USK@AKva7OolWsdAICB8ZE1hDgFqBJigJpYN2edJd6deiApU,dOitAHZSrt27Tl4wK7F-VHVShJVvzR7eNWKsXBolq8k,AQECAAE/'
-
-
- u = c.Upload(consts.KeyType.USK, privateKey=insertURI)
- u.addData('foo/0/', 'data here')
- c.putUpload(u)
-
-
- c.events.KeypairGenerated += cb
- c.generateKeypair(keypairType=consts.KeyType.USK)
-
- #identifier = c.uskPutData(
- #'foo1',
- #'USK@dkbB9DSr6R2WWs0MFsB9BJvN2cRjNxSboanDQNMJVNc,uIi9-1JrCLZ~6MLa8UrxQCMLptu~PzL59hAtorUIStw,AQECAAE/foo/0/',
- #)
- c.run()
-
- #testUskPutData()
-
-
-
- def testConfigData():
-
- from fcp2_0_config import Config
-
- def cb(event, msg):
-
- #print msg['current.fcp.persistentDownloadsInterval']
- #return
- root=Config(configDataMsg=msg)
-
- print
- print '***************************************'
- print '* walking config tree'
- print '***************************************'
- for node in root.walk():
- if node.name is None: # skip root
- continue
- print node.key()
- for valueClass, (value, valueType) in sorted(node.values.items()):
- print ' %s=%r (%s)' % (valueClass, value, valueType)
-
- print
- print '***************************************'
- print '* generating dict from config tree'
- print '***************************************'
- for key, value in root.toMessageParams().items():
- print '%s: %s (%s)' % (key, value, type(value))
-
- #c.setDebugVerbosity(c.DebugVerbosity.Warning)
-
- c.events.ConfigData += cb
- c.getConfig()
- for i in xrange(10):
- c.next()
-
- #testConfigData()
-
-
- #testConfigData()
-
-
- def testModifyConfig():
-
- from fcp2_0_config import Config
-
- def cb(event, msg):
- print msg['current.logger.interval']
- #print msg['current.fcp.persistentDownloadsInterval']
-
- c.setDebugVerbosity(c.consts.DebugVerbosity.Warning)
-
- c.events.ConfigData += cb
- #c.modifyConfig({'fcp.persistentDownloadsInterval': '3000000h'})
-
- c.modifyConfig({'logger.interval': '1'})
-
- for i in xrange(10):
- c.next()
-
- #testModifyConfig()
-
-
-
- def testNodeData():
-
- def cb(event, msg):
- pass
-
-
- c.events.NodeData += cb
- c.getNode()
- for i in xrange(10):
- c.next()
-
- #testNodeData()
-
-
- def testGenerateKeypair():
-
- def cb(event, msg):
- print '--------------------------------'
- print '>>>>privateKey:', msg['FcPrivateKey']
- print '>>>>publicKey:', msg['FcPublicKey']
- pass
-
- c.events.KeypairGenerated += cb
- c.generateKeypair('SSK@')
- c.generateKeypair('USK@')
-
-
- c.run()
- #for i in xrange(10):
- # c.next()
-
- #testGenerateKeypair()
-
-
- def testListPeers():
-
- def peerCb(event, msg):
- c.listPeerNotes(msg['identity'])
-
- c.events.Peer += peerCb
- c.listPeers()
-
-
-
- for i in xrange(50):
- c.next()
-
-
- #testListPeers()
-
- def testGetNode():
- c.getNode()
- for i in xrange(10):
- c.next()
-
- #testGetNode()
-
- def testGetPluginInfo():
- c.getPluginInfo('plugins.XMLLibrarian')
- for i in xrange(10):
- c.next()
-
- #testGetPluginInfo()
-
-
- def testListPeers():
- c.listPeers()
- for i in xrange(30):
- c.next()
-
- #testListPeers()
-
-
- def testSubscribeUSK():
- myIdentifier = c.subscribeUSK('USK@zQyF2O1o8B4y40w7Twz8y2I9haW3d2DTlxjTHPu7zc8,h2mhQNNE9aQvF~2yKAmKV1uorr7141-QOroBf5hrlbw,AQACAAE/AnotherIndex/0/')
- for i in xrange(10):
- c.next()
-
- for i in xrange(10):
- c.next()
-
-
- #testSubscribeUSK()
\ No newline at end of file
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ju...@us...> - 2008-02-18 13:30:12
|
Revision: 229
http://fclient.svn.sourceforge.net/fclient/?rev=229&view=rev
Author: jurner
Date: 2008-02-18 05:30:13 -0800 (Mon, 18 Feb 2008)
Log Message:
-----------
added aome more loggers
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-02-18 13:28:30 UTC (rev 228)
+++ trunk/sandbox/fcp/fcp2_0_client.py 2008-02-18 13:30:13 UTC (rev 229)
@@ -301,13 +301,16 @@
self._ddaTests = [] # currently running DDA tests (request0, ... requestN)
self._requests = {} # currently running requests (requestIdentifier --> request)
- self._log = logging.getLogger(consts.LoggerNames.Client)
+ self._logEvent = logging.getLogger(consts.LoggerNames.ClientEvents)
+ self._logMessage = logging.getLogger(consts.LoggerNames.ClientMessages)
+ self._logRuntime = logging.getLogger(consts.LoggerNames.ClientRuntime)
+
self._nodeHelloMessage = None
self._socket = None
-
+
self.events = Events()
for event in self.events:
- event += self._logEvent
+ event += self._captureEvent
self.setDebugVerbosity(consts.DebugVerbosity.Warning if debugVerbosity is None else debugVerbosity)
atexit.register(self.close)
@@ -322,7 +325,7 @@
"""Closes the client
@param msg: message to pass to the ClientDisconnected event or None to not inform listeners
"""
- self._log.info(consts.LogMessages.ClientClose)
+ self._logRuntime.info(consts.LogMessages.ClientClose)
# clean left over DDA test tmp files
for initialRequest in self._ddaTests:
@@ -471,9 +474,9 @@
self._requests[identifier] = msg
- def _logEvent(self, event, request):
+ def _captureEvent(self, event, request):
if event != self.events.Idle:
- self._log.debug(consts.LogMessages.EventTriggered + event.name)
+ self._logEvent.debug(consts.LogMessages.EventTriggered + event.name)
###############################################################
##
@@ -523,7 +526,7 @@
@event: ClientConnected(event, message) is triggered as soon as the client is connected
"""
- self._log.info(consts.LogMessages.Connecting)
+ self._logRuntime.info(consts.LogMessages.Connecting)
# try to Connect socket
if self._socket is not None:
@@ -543,7 +546,7 @@
except socket.error, d:
yield None
else:
- self._log.info(consts.LogMessages.Connected)
+ self._logRuntime.info(consts.LogMessages.Connected)
# send ClientHello and wait for NodeHello
#NOTE: thought I could leave ClientHelloing up to the caller
@@ -564,7 +567,7 @@
elif msg.name == consts.Message.NodeHello:
self._nodeHelloMessage = msg
- self._log.debug(consts.LogMessages.MessageReceived + msg.pprint())
+ self._logMessage.debug(consts.LogMessages.MessageReceived + msg.pprint())
# check if version is ok
if self.versionCheckNodeHello(msg):
self.events.ClientConnected(msg)
@@ -579,16 +582,16 @@
raise StopIteration
else:
- self._log.debug(consts.LogMessages.MessageReceived + msg.pprint())
+ self._logMessage.debug(consts.LogMessages.MessageReceived + msg.pprint())
break
break
# continue polling
- self._log.info(consts.LogMessages.ConnectionRetry)
+ self._logRuntime.info(consts.LogMessages.ConnectionRetry)
timeElapsed += timeout
time.sleep(timeout)
- self._log.info(consts.LogMessages.ConnectingFailed)
+ self._logRuntime.info(consts.LogMessages.ConnectingFailed)
disconnectMsg = self.Message(
consts.Message.ClientDisconnected,
DisconnectReason=consts.DisconnectReason.ConnectingFailed,
@@ -604,7 +607,7 @@
"""
return self._connectionName
-
+
def setConnectionName(self, connectionName=None):
"""Sets the connection name to be used by the client
@param connectionName: (str) connection name or None to use an arbitrary connection name
@@ -618,7 +621,7 @@
"""Sets the verbosity level of the client
@note: see L{consts.DebugVerbosity}
"""
- self._log.setLevel(debugVerbosity)
+ self._logMessage.setLevel(debugVerbosity)
def startFreenet(self, cmdline):
@@ -663,7 +666,7 @@
if msg.name == consts.Message.ClientSocketTimeout:
return True
- self._log.debug(consts.LogMessages.MessageReceived + msg.pprint())
+ self._logMessage.debug(consts.LogMessages.MessageReceived + msg.pprint())
# check if we have an initial request corrosponding to msg
requestIdentifier = msg.get('Identifier', None)
@@ -1253,7 +1256,7 @@
"""
msg = self.Message.fromSocket(self._socket)
if msg.name == consts.Message.ClientSocketDied:
- self._log.critical(consts.LogMessages.SocketDied)
+ self._logRuntime.critical(consts.LogMessages.SocketDied)
if dispatch:
disconnectMsg = self.Message(
consts.Message.ClientDisconnected,
@@ -1290,13 +1293,13 @@
break
if not haveRunningRequests:
- self._log.info(consts.LogMessages.AllRequestsCompleted)
+ self._logRuntime.info(consts.LogMessages.AllRequestsCompleted)
break
try:
msg = self.next()
except KeyboardInterrupt:
- self._log.info(consts.LogMessages.KeyboardInterrupt)
+ self._logRuntime.info(consts.LogMessages.KeyboardInterrupt)
break
if msg.name == consts.Message.ClientSocketDied:
@@ -1330,11 +1333,11 @@
@note: you can use this method to send a message to the node, bypassing all
track keeping methods of the client
"""
- self._log.debug(consts.LogMessages.MessageSend + msg.pprint())
+ self._logMessage.debug(consts.LogMessages.MessageSend + msg.pprint())
try:
msg.send(self._socket)
except socket.error, d:
- self._log.critical(consts.LogMessages.SocketDied)
+ self._logRuntime.critical(consts.LogMessages.SocketDied)
disconnectMsg = self.Message(
consts.Message.ClientDisconnected,
DisconnectReason=consts.DisconnectReason.SocketDied,
@@ -1642,6 +1645,41 @@
self.sendMessageEx(msg)
return msg['Identifier']
+
+ def putRedirect(self,
+ name,
+ targetURI,
+
+ maxRetries=None,
+ persistence=consts.Persistence.Connection,
+ priorityClass=consts.Priority.Medium,
+
+ userData=None,
+ persistentUserData='',
+ ):
+ """Uploads a redirect
+ @param name: name of the redirect
+ @param targetURI: (str) uri to redirect to
+ @return: (str) request identifier
+ """
+ msg = self.Message(
+ consts.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.sendMessageEx(msg)
+ return msg['Identifier']
+
+
########################################################
##
## CHK ClientPut related methods
@@ -1678,9 +1716,9 @@
**messageParams
):
- if requestType in (consts.Message.ClientPutData, consts.Message.ClientPutFile):
+ if requestType in (consts.RequestType.PutData, consts.RequestType.PutFile):
msgName = consts.Message.ClientPut
- elif requestType == consts.Message.ClientPutDir:
+ elif requestType == consts.RequestType.PutDir:
msgName = consts.Message.ClientPutDiskDir
else:
msgName = consts.Message.ClientPutComplexDir
@@ -1744,6 +1782,7 @@
MaxRetries=maxRetries,
DontCompress=dontCompress,
Persistence=persistence,
+ PriorityClass=priorityClass,
TargetFilename=targetFilename,
UploadFrom=consts.UploadFrom.Direct,
Verbosity=consts.Verbosity.ReportProgress | consts.Verbosity.ReportCompression,
@@ -1789,7 +1828,8 @@
MaxRetries=maxRetries,
DontCompress=dontCompress,
Persistence=persistence,
- TergetFilename=targetFilename,
+ PriorityClass=priorityClass,
+ TargetFilename=targetFilename,
UploadFrom=consts.UploadFrom.Disk,
Verbosity=consts.Verbosity.ReportProgress | consts.Verbosity.ReportCompression,
)
@@ -1831,14 +1871,14 @@
MaxRetries=maxRetries,
DontCompress=dontCompress,
Persistence=persistence,
- TergetFilename=targetFilename,
+ PriorityClass=priorityClass,
+ TargetFilename=targetFilename,
UploadFrom=consts.UploadFrom.Disk,
Verbosity=consts.Verbosity.ReportProgress | consts.Verbosity.ReportCompression,
)
def chkPutMultiple(self,
- directory,
items,
allowUnreadableFiles=False,
@@ -1854,8 +1894,14 @@
persistentUserData='',
):
- """
+ """Uploads multiple items at once
+
+ @param items:
+
@param TargetFilename: (str) filename to append to the CHK key or None (may not contain slashes)
+
+
+
"""
return self.clientPut(
@@ -1880,7 +1926,8 @@
MaxRetries=maxRetries,
DontCompress=dontCompress,
Persistence=persistence,
- TergetFilename=targetFilename,
+ PriorityClass=priorityClass,
+ TargetFilename=targetFilename,
UploadFrom=consts.UploadFrom.Disk,
Verbosity=consts.Verbosity.ReportProgress | consts.Verbosity.ReportCompression,
)
@@ -1924,9 +1971,9 @@
):
return self.clientPut(
+ consts.RequestType.PutData,
insertURI,
#insertURI + 'foo/0/',
- consts.RequestType.Put,
userData,
persistentUserData,
data,
@@ -2279,10 +2326,12 @@
connectionName='test',
debugVerbosity=consts.DebugVerbosity.Debug
)
- #log = c.getLogger()
+
fpath = os.path.join(Dir, 'test.log')
handler = logging.FileHandler(fpath, 'w')
- logging.getLogger('').addHandler(handler)
+ #formatter = logging.Formatter('%(name)s:%(levelname)s:%(funcName)s:%(message)s')
+ #handler.setFormatter(formatter)
+ logging.getLogger('Fcp.Client').addHandler(handler)
nodeHello = c.connect()
@@ -2380,9 +2429,62 @@
#testGetKeyInfo()
+ def testPutRedirect():
+
+
+
+
+ def cb(event, msg):
+ if event == c.events.RequestCompleted:
+
+ identifier = c.putRedirect(
+ 'HaHaHa',
+ msg['URI']
+ )
+
+ pass
+ #c.sendMessage(c.consts.Message.GetRequestStatus, Identifier=identifier)
+ #print msg['FcErrorMessage']
+
+
+ c.events.RequestCompleted += cb
+ c.events.RequestFailed += cb
+
+ #c.chkPutData('HaHaHaHa')
+
+ #identifier = c.putRedirect(
+ # 'foo',
+ # 'USK@zQyF2O1o8B4y40w7Twz8y2I9haW3d2DTlxjTHPu7zc8,h2mhQNNE9aQvF~2yKAmKV1uorr7141-QOroBf5hrlbw,AQACAAE/AnotherIndex/0/',
+ #'foo/bar'
+ #persistence=c.consts.Persistence.Reboot,
+ # )
+
+ #c.sendMessage(
+ # consts.Message.ClientPut,
+ # Identifier='blah',
+ # URI='KSK@foo',
+ # TargetURI='USK@zQyF2O1o8B4y40w7Twz8y2I9haW3d2DTlxjTHPu7zc8,h2mhQNNE9aQvF~2yKAmKV1uorr7141-QOroBf5hrlbw,AQACAAE/AnotherIndex/0/',
+ # UploadFrom='redirect',
+ # )
+
+ c.chkPutData('arggggggggg!')
+
+ #for i in xrange(55):
+ # c.next()
+ #c.removeRequest(identifier)
+ #for i in xrange(5):
+ # c.next()
+ c.run()
+
+ #testPutRedirect()
+
+
+
+
+
def testChkPutData():
myIdentifier = c.chkPutData(
- 'test123',
+ 'test123hahaha',
#persistence=c.Persistence.Reboot,
)
@@ -2394,11 +2496,9 @@
# c.next()
#testChkPutData()
-
-
def testChkPutFile():
fpath = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'test.jpg')
@@ -2421,9 +2521,9 @@
myIdentifier = c.uskPutData(
'foo',
insertURI + 'foo/0/',
- persistence=consts.Persistence.Reboot,
+ #persistence=consts.Persistence.Reboot,
)
- c.removeRequest(myIdentifier)
+ #c.removeRequest(myIdentifier)
c.events.KeypairGenerated += cb
c.generateKeypair(keypairType=consts.KeyType.USK)
@@ -2432,10 +2532,10 @@
#'foo1',
#'USK@dkbB9DSr6R2WWs0MFsB9BJvN2cRjNxSboanDQNMJVNc,uIi9-1JrCLZ~6MLa8UrxQCMLptu~PzL59hAtorUIStw,AQECAAE/foo/0/',
#)
- #c.run()
+ c.run()
- for i in xrange(700):
- c.next()
+ #for i in xrange(700):
+ # c.next()
#testUskPutData()
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ju...@us...> - 2008-02-18 13:28:39
|
Revision: 228
http://fclient.svn.sourceforge.net/fclient/?rev=228&view=rev
Author: jurner
Date: 2008-02-18 05:28:30 -0800 (Mon, 18 Feb 2008)
Log Message:
-----------
added aome more loggers
Modified Paths:
--------------
trunk/sandbox/fcp/fcp2_0_consts.py
Modified: trunk/sandbox/fcp/fcp2_0_consts.py
===================================================================
--- trunk/sandbox/fcp/fcp2_0_consts.py 2008-02-18 00:32:46 UTC (rev 227)
+++ trunk/sandbox/fcp/fcp2_0_consts.py 2008-02-18 13:28:30 UTC (rev 228)
@@ -216,9 +216,21 @@
class LoggerNames:
- """Logger names used by the client"""
+ """Logger names used by the the package
+
+ @cvar Fcp: root logger for the packsge
+ @cvar Client: root logger for the client
+ @cvar ClientEvents: logs events the client emits
+ @cvar ClientMessages: logs messages the client sends and receives
+ @cvar ClientRuntime: logs runtime information
+
+ @cvar Config: logs config related information
+ """
Fcp = 'Fcp'
Client = Fcp + '.Client'
+ ClientEvents = Client + '.Events'
+ ClientMessages = Client + '.Messages'
+ ClientRuntime = Client + '.Runtime'
Config = Fcp + '.Config'
@@ -232,14 +244,14 @@
ClientClose = 'closing client'
- MessageSend = 'sending message'
- MessageReceived = 'received message'
+ MessageSend = 'send'
+ MessageReceived = 'received'
KeyboardInterrupt = 'keyboard interrupt' # kick out
SocketDied = 'socket died'
AllRequestsCompleted = 'All requests completed'
- EventTriggered = 'Event Triggered: '
+ EventTriggered = 'triggered: '
class Message:
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ju...@us...> - 2008-02-18 00:32:43
|
Revision: 227
http://fclient.svn.sourceforge.net/fclient/?rev=227&view=rev
Author: jurner
Date: 2008-02-17 16:32:46 -0800 (Sun, 17 Feb 2008)
Log Message:
-----------
minor changes
Modified Paths:
--------------
trunk/sandbox/fcp/fcp2_0_consts.py
Modified: trunk/sandbox/fcp/fcp2_0_consts.py
===================================================================
--- trunk/sandbox/fcp/fcp2_0_consts.py 2008-02-18 00:31:32 UTC (rev 226)
+++ trunk/sandbox/fcp/fcp2_0_consts.py 2008-02-18 00:32:46 UTC (rev 227)
@@ -148,7 +148,7 @@
CouldNotReadFile = 26
ReferenceSignature = 27
CanNotPeerWithSelf = 28
- PeerExists = '29'
+ PeerExists = 29
OpennetDisabled = 30
DarknetPeerOnly = 31
NoSuchPlugin = 32
@@ -186,7 +186,7 @@
DuplicateClientName = 0x2
Shutdown = 0x4
SocketDied = 0x8
- VersionMissmatch = 0x10 #TODO: implement???
+ VersionMissmatch = 0x10
class FilenameCollision(BaseBitFlags):
@@ -216,12 +216,11 @@
class LoggerNames:
- """Logger names"""
+ """Logger names used by the client"""
Fcp = 'Fcp'
- Client = 'Fcp.Client'
- Config = 'Fcp.Config'
+ Client = Fcp + '.Client'
+ Config = Fcp + '.Config'
-
class LogMessages:
"""Strings used for log infos"""
@@ -241,7 +240,6 @@
AllRequestsCompleted = 'All requests completed'
EventTriggered = 'Event Triggered: '
-
class Message:
@@ -365,7 +363,6 @@
Disconnecting = 'DISCONNECTING'
Unknown = 'UNKNOWN STATUS'
-
class RequestType(BaseBitFlags):
"""Consts indicating the type of a request"""
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ju...@us...> - 2008-02-18 00:31:36
|
Revision: 225
http://fclient.svn.sourceforge.net/fclient/?rev=225&view=rev
Author: jurner
Date: 2008-02-17 16:31:25 -0800 (Sun, 17 Feb 2008)
Log Message:
-----------
fix: always end messages with 'EndMessage\n'
Modified Paths:
--------------
trunk/sandbox/fcp/fcp2_0_message.py
Modified: trunk/sandbox/fcp/fcp2_0_message.py
===================================================================
--- trunk/sandbox/fcp/fcp2_0_message.py 2008-02-17 09:21:42 UTC (rev 224)
+++ trunk/sandbox/fcp/fcp2_0_message.py 2008-02-18 00:31:25 UTC (rev 225)
@@ -46,7 +46,7 @@
self.data = data
self.name = name
self.params = params
-
+
@classmethod
def bytesFromSocket(clss, socketObj, n):
@@ -198,14 +198,8 @@
value = paramType.pythonToFcp(value)
out.append('%s=%s' % (param, value))
- if self.data:
- out.append('Data')
- out.append(self.data)
- else:
- out.append('EndMessage\n')
+
+ out.append('EndMessage')
+ out.append(self.data if self.data is not None else '')
return '\n'.join(out)
-
-
-
-
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ju...@us...> - 2008-02-18 00:31:36
|
Revision: 226
http://fclient.svn.sourceforge.net/fclient/?rev=226&view=rev
Author: jurner
Date: 2008-02-17 16:31:32 -0800 (Sun, 17 Feb 2008)
Log Message:
-----------
fix: always end messages with 'EndMessage\n'
Modified Paths:
--------------
trunk/sandbox/fcp/test_fcp/test_fcp2_0_message.py
Modified: trunk/sandbox/fcp/test_fcp/test_fcp2_0_message.py
===================================================================
--- trunk/sandbox/fcp/test_fcp/test_fcp2_0_message.py 2008-02-18 00:31:25 UTC (rev 225)
+++ trunk/sandbox/fcp/test_fcp/test_fcp2_0_message.py 2008-02-18 00:31:32 UTC (rev 226)
@@ -103,7 +103,7 @@
data='ABCDE'
)
msg.send(s)
- self.failUnless(s.bytes == 'AllData\nDataLength=5\nData\nABCDE')
+ self.failUnless(s.bytes == 'AllData\nDataLength=5\nEndMessage\nABCDE')
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ju...@us...> - 2008-02-17 09:21:37
|
Revision: 224
http://fclient.svn.sourceforge.net/fclient/?rev=224&view=rev
Author: jurner
Date: 2008-02-17 01:21:42 -0800 (Sun, 17 Feb 2008)
Log Message:
-----------
new sys path hack
Modified Paths:
--------------
trunk/sandbox/fcp/test_fcp/test_fcp2_0_message.py
Modified: trunk/sandbox/fcp/test_fcp/test_fcp2_0_message.py
===================================================================
--- trunk/sandbox/fcp/test_fcp/test_fcp2_0_message.py 2008-02-17 09:21:27 UTC (rev 223)
+++ trunk/sandbox/fcp/test_fcp/test_fcp2_0_message.py 2008-02-17 09:21:42 UTC (rev 224)
@@ -5,20 +5,20 @@
import unittest
#--> rel import hack
-def parentdir(n, fpath):
- fpath = os.path.abspath(fpath)
- for i in xrange(n):
- fpath = os.path.dirname(fpath)
- return fpath
-sys.path.insert(0, parentdir(2, __file__))
+class SysPathHack(object):
+ def __init__(self, n):
+ fpath = os.path.abspath(__file__)
+ for i in xrange(n): fpath = os.path.dirname(fpath)
+ sys.path.insert(0, fpath)
+ def __del__(self): sys.path.pop(0)
+hack = SysPathHack(2)
from fcp2_0_client import FcpClient
Message = FcpClient.Message
import fcp2_0_consts as consts
-sys.path.pop(0)
-del parentdir
+del hack
#<-- rel import hack
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ju...@us...> - 2008-02-17 09:21:22
|
Revision: 223
http://fclient.svn.sourceforge.net/fclient/?rev=223&view=rev
Author: jurner
Date: 2008-02-17 01:21:27 -0800 (Sun, 17 Feb 2008)
Log Message:
-----------
new sys path hack
Modified Paths:
--------------
trunk/sandbox/fcp/test_fcp/test_fcp2_0_client.py
Modified: trunk/sandbox/fcp/test_fcp/test_fcp2_0_client.py
===================================================================
--- trunk/sandbox/fcp/test_fcp/test_fcp2_0_client.py 2008-02-17 09:20:13 UTC (rev 222)
+++ trunk/sandbox/fcp/test_fcp/test_fcp2_0_client.py 2008-02-17 09:21:27 UTC (rev 223)
@@ -9,12 +9,13 @@
import unittest
#--> rel import hack
-def parentdir(n, fpath):
- fpath = os.path.abspath(fpath)
- for i in xrange(n):
- fpath = os.path.dirname(fpath)
- return fpath
-sys.path.insert(0, parentdir(2, __file__))
+class SysPathHack(object):
+ def __init__(self, n):
+ fpath = os.path.abspath(__file__)
+ for i in xrange(n): fpath = os.path.dirname(fpath)
+ sys.path.insert(0, fpath)
+ def __del__(self): sys.path.pop(0)
+hack = SysPathHack(2)
import fcp2_0_client
@@ -22,8 +23,7 @@
import fcp2_0_consts as consts
-sys.path.pop(0)
-del parentdir
+del hack
#<-- rel import hack
from dummy_socket import DummySocket
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ju...@us...> - 2008-02-17 09:20:10
|
Revision: 222
http://fclient.svn.sourceforge.net/fclient/?rev=222&view=rev
Author: jurner
Date: 2008-02-17 01:20:13 -0800 (Sun, 17 Feb 2008)
Log Message:
-----------
better logger names
Modified Paths:
--------------
trunk/sandbox/fcp/fcp2_0_consts.py
Modified: trunk/sandbox/fcp/fcp2_0_consts.py
===================================================================
--- trunk/sandbox/fcp/fcp2_0_consts.py 2008-02-17 09:19:52 UTC (rev 221)
+++ trunk/sandbox/fcp/fcp2_0_consts.py 2008-02-17 09:20:13 UTC (rev 222)
@@ -217,9 +217,9 @@
class LoggerNames:
"""Logger names"""
- Fcp = ''
- Client = 'Client'
- Config = 'Config'
+ Fcp = 'Fcp'
+ Client = 'Fcp.Client'
+ Config = 'Fcp.Config'
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ju...@us...> - 2008-02-17 09:19:47
|
Revision: 221
http://fclient.svn.sourceforge.net/fclient/?rev=221&view=rev
Author: jurner
Date: 2008-02-17 01:19:52 -0800 (Sun, 17 Feb 2008)
Log Message:
-----------
removed getLogger()
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-02-16 11:02:46 UTC (rev 220)
+++ trunk/sandbox/fcp/fcp2_0_client.py 2008-02-17 09:19:52 UTC (rev 221)
@@ -604,9 +604,6 @@
"""
return self._connectionName
- def getLogger(self):
- """Returns the L{logging.Logger} used by the client"""
- return self._log
def setConnectionName(self, connectionName=None):
"""Sets the connection name to be used 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-02-16 11:03:00
|
Revision: 220
http://fclient.svn.sourceforge.net/fclient/?rev=220&view=rev
Author: jurner
Date: 2008-02-16 03:02:46 -0800 (Sat, 16 Feb 2008)
Log Message:
-----------
ups, missing pages
Added Paths:
-----------
trunk/web/more-fcp.html
trunk/web/screenshots-fclient.html
trunk/web/screenshots-fcp.html
Added: trunk/web/more-fcp.html
===================================================================
--- trunk/web/more-fcp.html (rev 0)
+++ trunk/web/more-fcp.html 2008-02-16 11:02:46 UTC (rev 220)
@@ -0,0 +1,84 @@
+<html>
+ <head>
+ <link rel="StyleSheet" href="default.css" type="text/css" media="screen">
+ </head>
+ <body>
+
+ <div class="navHeader">
+ <a class="navRef" href="intro.html" target="mainFrame">fclient</a><span class="navRef">::more-fcp</span>
+ </div>
+
+
+ <div class="topic">
+ <b>fcp:</b> high level wrapper for the freenet client protocol written in python. Automatic
+ conversions from Fcp to python types, access to node and peer configurations.
+
+ <br>
+ Blah more here
+ </div>
+
+ <h5>Sample code:</h5>
+
+
+Connect to the freenet node
+<pre class="py_code">client <span class="py_operator">=</span> FcpClient()
+nodeHello <span class="py_operator">=</span> client.connect()
+<span class="py_keyword">if</span> nodeHello <span class="py_keyword">is</span> <span class="py_bool">None</span>:
+ <span class="py_keyword">pass</span>
+ <span class="py_comment"># something went wrong ..could not connect to the freenet node</span>
+<span class="py_keyword">else</span>:
+ <span class="py_keyword">pass</span>
+ <span class="py_comment"># everything went well ..we are connected now</span>
+</pre>
+
+Request data associated to a freenet key
+<pre class="py_code">myRequestIdentifier <span class="py_operator">=</span> client.getData(<span class="py_string2">'CHK@ABCDE.......'</span>)
+myRequest <span class="py_operator">=</span> client.getRequest(myIdentifier)
+client.run()
+<span class="py_keyword">print</span> myRequest.data
+</pre>
+
+
+Usually you would connect handlers to client events to do processing or handle errors
+<pre class="py_code"><span class="py_keyword">def</span> handleSuccess(event, request):
+ <span class="py_keyword">print</span> <span class="py_string2">'Here is the data:'</span>, request.data
+
+<span class="py_keyword">def</span> handleFailure(event, request):
+ <span class="py_keyword">print</span> <span class="py_string2">'Too bad, something went wrong'</span>
+
+client.events.RequestCompleted <span class="py_operator">+</span><span class="py_operator">=</span> handleSuccess
+client.events.RequestFailed <span class="py_operator">+</span><span class="py_operator">=</span> handleFailure
+
+client.getData(<span class="py_string2">'CHK@ABCDE.......'</span>)
+client.run()
+</pre>
+
+Instead of calling run() you may run the client step by step
+<pre class="py_code">client.getData(<span class="py_string2">'CHK@ABCDE.......'</span>)
+<span class="py_keyword">for</span> i <span class="py_keyword">in</span> xrange(50):
+ client.next()
+</pre>
+
+You may disconnect event handlers aswel
+<pre class="py_code">client.events.RequestCompleted <span class="py_operator">-</span><span class="py_operator">=</span> handleSuccess
+client.events.RequestFailed <span class="py_operator">-</span><span class="py_operator">=</span> handleFailure
+</pre>
+
+Multiple event handlers may be connected / disconnected at once
+<pre class="py_code">client.events <span class="py_operator">+</span><span class="py_operator">=</span> (
+ (client.events.RequestCompleted, handleSuccess),
+ (client.events.RequestFailed, handleFailure)
+ )
+</pre>
+
+
+
+To generate extensive documentation run the package through [<a href="http://epydoc.sourceforge.net/">epydoc</a>].
+To make things a bit simpler script <span class="hilight">gen_docs.py</span> located in the
+<span class="hilight">scripts</span> subdirectory of the package wich will dump docs automatically to the
+packages <span class="hilight">doc</span> folder.
+
+
+ <div class="bottom_padding"></div>
+ </body>
+</html>
\ No newline at end of file
Added: trunk/web/screenshots-fclient.html
===================================================================
--- trunk/web/screenshots-fclient.html (rev 0)
+++ trunk/web/screenshots-fclient.html 2008-02-16 11:02:46 UTC (rev 220)
@@ -0,0 +1,19 @@
+<html>
+ <head>
+ <link rel="StyleSheet" href="default.css" type="text/css" media="screen">
+ </head>
+ <body>
+
+ <div class="navHeader">
+ <a class="navRef" href="intro.html" target="mainFrame">fclient</a><span class="navRef">::screenshots-fclient</span>
+ </div>
+
+
+ <br>
+ <br>
+ Nothing to see here, move along
+
+
+ <div class="bottom_padding"></div>
+ </body>
+</html>
Added: trunk/web/screenshots-fcp.html
===================================================================
--- trunk/web/screenshots-fcp.html (rev 0)
+++ trunk/web/screenshots-fcp.html 2008-02-16 11:02:46 UTC (rev 220)
@@ -0,0 +1,21 @@
+<html>
+ <head>
+ <link rel="StyleSheet" href="default.css" type="text/css" media="screen">
+ </head>
+ <body>
+
+ <div class="navHeader">
+ <a class="navRef" href="intro.html" target="mainFrame">fclient</a><span class="navRef">::screenshots-fcp</span>
+ </div>
+
+
+ <div class="topic">
+ <br>
+ <br>
+ Nothing to see here, move along
+ </div>
+
+
+ <div class="bottom_padding"></div>
+ </body>
+</html>
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ju...@us...> - 2008-02-16 11:00:48
|
Revision: 219
http://fclient.svn.sourceforge.net/fclient/?rev=219&view=rev
Author: jurner
Date: 2008-02-16 03:00:47 -0800 (Sat, 16 Feb 2008)
Log Message:
-----------
added sf web page
Added Paths:
-----------
trunk/web/
trunk/web/default.css
trunk/web/download-fclient.html
trunk/web/download-fcp.html
trunk/web/index.html
trunk/web/intro.html
trunk/web/more-fclient.html
Added: trunk/web/default.css
===================================================================
--- trunk/web/default.css (rev 0)
+++ trunk/web/default.css 2008-02-16 11:00:47 UTC (rev 219)
@@ -0,0 +1,97 @@
+/* bit of a hack to get tables (...) to display at 100% hight
+See: http://apptools.com/examples/tableheight.php
+*/
+html,body, #fillsViewport{
+ margin:0;
+ padding:0;
+ height:100%;
+ border:none
+ }
+
+div.body{
+ border: solid;
+ border-width: 0.1em;
+ border-color: #C7E9D3;
+ height: auto;
+ }
+
+td.frame{
+ border: solid;
+ border-width: 0.1em;
+ border-color: #C7E9D3;
+ }
+div.navHeader{
+ background-color: green;
+ font-size: xx-large;
+ font-weight: bolder;
+ }
+div.topic{
+ margin-top: 10;
+ }
+a{
+ text-decoration: none;
+ }
+.navRef{
+ color: #64CB8C;
+ }
+
+.hilight{
+ font-weight: bold;
+ background-color: #F0F0F0;
+}
+.bottom_padding{
+ padding-bottom: 20em;
+ }
+
+
+/* pymarkup */
+table.py_table{
+}
+/* pre */
+pre.py_code{
+ font:xx-small Georgia,Serif;
+ padding-left: 0.5em;
+ background: #F0F0F0;
+ border: solid 1px;
+}
+pre.py_lineno{
+ font:xx-small Georgia,Serif;
+ color: gray;
+ padding-right: 0.1em;
+ border-right: solid 1px gray;
+ background: #F0F0F0;
+}
+/* source code colors */
+span.py_blockcomment1{
+ color: #008000;
+}
+span.py_blockcomment2{
+ color: #008000;
+}
+span.py_comment{
+ color: #008000;
+}
+span.py_string1{
+ color: #FF00FF;
+}
+span.py_string2{
+ color: #FF00FF;
+}
+span.py_keyword{
+ color: #0000FF;
+ font: bold;
+}
+span.py_operator{
+ color: #008080;
+}
+span.py_bool{
+ color: #008080;
+}
+span.py-number{
+ color: #0080C0;
+}
+span.py_exception{
+ color: #FF0000;
+}
+span.py_plain{
+}
\ No newline at end of file
Added: trunk/web/download-fclient.html
===================================================================
--- trunk/web/download-fclient.html (rev 0)
+++ trunk/web/download-fclient.html 2008-02-16 11:00:47 UTC (rev 219)
@@ -0,0 +1,22 @@
+
+<html>
+ <head>
+ <link rel="StyleSheet" href="default.css" type="text/css" media="screen">
+ </head>
+ <body>
+
+ <div class="navHeader">
+ <a class="navRef" href="intro.html" target="mainFrame">fclient</a><span class="navRef">::download-fclient</span>
+ </div>
+
+
+ <div class="topic">
+ <br>
+ <br>
+ Nothing to see here, move along
+ </div>
+
+
+ <div class="bottom_padding"></div>
+ </body>
+</html>
Added: trunk/web/download-fcp.html
===================================================================
--- trunk/web/download-fcp.html (rev 0)
+++ trunk/web/download-fcp.html 2008-02-16 11:00:47 UTC (rev 219)
@@ -0,0 +1,21 @@
+<html>
+ <head>
+ <link rel="StyleSheet" href="default.css" type="text/css" media="screen">
+ </head>
+ <body>
+
+ <div class="navHeader">
+ <a class="navRef" href="intro.html" target="mainFrame">fclient</a><span class="navRef">::download-fcp</span>
+ </div>
+
+
+ <div class="topic">
+ <br>
+ <br>
+ Nothing to see here, move along
+ </div>
+
+ <div class="bottom_padding"></div>
+ </body>
+</html>
+
Added: trunk/web/index.html
===================================================================
--- trunk/web/index.html (rev 0)
+++ trunk/web/index.html 2008-02-16 11:00:47 UTC (rev 219)
@@ -0,0 +1,56 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
+<html>
+ <head>
+ <title>fclient</title>
+ <link rel="StyleSheet" href="default.css" type="text/css" media="screen">
+ </head>
+ <body>
+
+
+ <table id="fillsViewport" width="100%" border="0" cellspacing="0" cellpadding="0">
+
+ <!-- header -->
+ <tr>
+ <td class="frame" colspan="999">
+ Python versus freenet
+ <td>
+ </tr>
+ <!-- end header -->
+
+ <tr>
+ <td colspan="999" height="100%">
+ <iframe name="mainFrame" src="intro.html" title="" frameborder="0" width="100%" height="100%">
+
+ Your browser does not seem to support iframes. Some links for quick navigation
+ <br>
+ <a href="intro.html">Intro</a><br>
+ <a href="fclient-more.html">fclient</a><br>
+ <a href="fcp-more.html">fcp</a><br>
+
+ </iframe>
+ </td>
+ </tr>
+
+
+ <!-- footer -->
+ <tr>
+
+ <td class="frame" width="100%" valign="bottom">
+ [<a href="http://www.freenetproject.org">Freenet</a>]
+ <!-- [<a href="http://epydoc.sourceforge.net/">Epydoc</a>] -->
+ </td>
+ <td class="frame" valign="bottom">
+ <a href="http://sourceforge.net/donate/index.php?group_id=206970"><img src="http://images.sourceforge.net/images/project-support.jpg" width="88" height="32" border="0" alt="Support This Project" /> </a>
+ </td>
+ <td class="frame" valign="bottom">
+ <a href="http://sourceforge.net"><img src="http://sflogo.sourceforge.net/sflogo.php?group_id=206970&type=4" width="125" height="37" border="0" alt="SourceForge.net Logo" /></a>
+ </td>
+
+ </tr>
+
+ <!-- end footer -->
+
+ </table>
+
+ </body>
+</html>
\ No newline at end of file
Added: trunk/web/intro.html
===================================================================
--- trunk/web/intro.html (rev 0)
+++ trunk/web/intro.html 2008-02-16 11:00:47 UTC (rev 219)
@@ -0,0 +1,29 @@
+<html>
+ <head>
+ <link rel="StyleSheet" href="default.css" type="text/css" media="screen">
+ </head>
+ <body>
+ <div class="navHeader">
+ <a href="" class="navRef">fclient</a>
+ </div>
+
+
+ <div class="topic">
+ <b>fclient:</b> Gui frontend for freenet written in Qt and python. Yet to come
+
+ <br>
+ [<a href="more-fclient.html" target="mainFrame">..More</a>] [<a href="download-fclient.html" target="mainFrame">Download</a>] [<a href="screenshots-fclient.html" target="mainFrame">Screenshots</a>]
+ <hr>
+ </div>
+
+
+ <div class="topic">
+ <b>fcp:</b> high level wrapper for the freenet client protocol written in python. Automatic
+ conversions from Fcp to python types, access to node and peer configurations and more
+ <br>
+ [<a href="more-fcp.html" target="mainFrame">..More</a>] [<a href="download-fcp.html" target="mainFrame">Download</a>] [<a href="screenshots-fcp.html" target="mainFrame">Screenshots</a>]
+ </div>
+
+
+ </body>
+</html>
\ No newline at end of file
Added: trunk/web/more-fclient.html
===================================================================
--- trunk/web/more-fclient.html (rev 0)
+++ trunk/web/more-fclient.html 2008-02-16 11:00:47 UTC (rev 219)
@@ -0,0 +1,20 @@
+<html>
+ <head>
+ <link rel="StyleSheet" href="default.css" type="text/css" media="screen">
+ </head>
+ <body>
+
+ <div class="navHeader">
+ <a class="navRef" href="intro.html" target="mainFrame">fclient</a><span class="navRef">::more-fclient</span>
+ </div>
+
+
+ <div class="topic">
+ <br>
+ <br>
+ Nothing to see here, move along
+ </div>
+
+
+ </body>
+</html>
\ No newline at end of file
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ju...@us...> - 2008-02-16 10:09:53
|
Revision: 218
http://fclient.svn.sourceforge.net/fclient/?rev=218&view=rev
Author: jurner
Date: 2008-02-16 02:09:58 -0800 (Sat, 16 Feb 2008)
Log Message:
-----------
comb over
Modified Paths:
--------------
trunk/sandbox/fcp/fcp_lib/numbers.py
Modified: trunk/sandbox/fcp/fcp_lib/numbers.py
===================================================================
--- trunk/sandbox/fcp/fcp_lib/numbers.py 2008-02-16 10:09:26 UTC (rev 217)
+++ trunk/sandbox/fcp/fcp_lib/numbers.py 2008-02-16 10:09:58 UTC (rev 218)
@@ -6,11 +6,19 @@
#***************************************************************
#
#***************************************************************
-def format_num_bytes(num, short=True, conform=True):
+class ByteSizeNames:
+ Binary = ('B', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB', 'ZiB', 'YiB')
+ Common = ('B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB')
+
+
+
+def format_num_bytes(num, binary=False, names=None, format_strings=('%i%s', '%01.2f%s') ):
"""Formats a number representing a number of bytes to a human readable string
@param num: (int) number to fomat
- @param short: use short names
- @param conform: if True factor is 1000, else factor is 1024
+ @param binary: if True conversion factor is 1024, else factor is 1000
+ @param names: (tuple) names to use as suffix or None to use default names (see L{ByteSizeNames})
+ @param format_strings: (tuple) format strings to be used or None to use the default formating.
+ The first member of the tuple is used to format bytes, the seconds anything > one kilobyte
@return: (str) formated number
>>> format_num_bytes(100)
@@ -19,43 +27,24 @@
>>> format_num_bytes(1000)
'1.00KB'
- >>> format_num_bytes(1024, conform=False)
+ >>> format_num_bytes(1024, binary=True)
'1.00KiB'
- >>> format_num_bytes(1000, short=False)
- '1.00Kilobyte'
+ >>> format_num_bytes(1000, names=('W', 'X', 'Y', 'Z'))
+ '1.00X'
+ >>> format_num_bytes(1000, format_strings=('%s%i', '%01.4f%s'))
+ '1.0000KB'
+
"""
- if conform:
+ if binary:
+ factor = 1024
+ if names is None:
+ names = ByteSizeNames.Binary
+ else:
factor = 1000
- if short:
- names = ('B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB')
- else:
- names = ('Byte',
- 'Kilobyte',
- 'Megabyte',
- 'Gigabyte',
- 'Terabyte',
- 'Petabyte',
- 'Exabyte',
- 'Zettabyte',
- 'Yottabyte'
- )
- else:
- factor = 1024
- if short:
- names = ('B', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB', 'ZiB', 'YiB')
- else:
- names = ('Byte',
- 'Kibibyte',
- 'Mebibyte',
- 'Gibibyte',
- 'Tebibyte',
- 'Pebibyte',
- 'Exibyte',
- 'Zebibyte',
- 'Yobiabyte'
- )
+ if names is None:
+ names = ByteSizeNames.Common
name = names[0]
if num >= factor:
@@ -66,11 +55,78 @@
if num < factor:
break
else:
- return '%i%s' % (num, name)
+ return format_strings[0] % (num, name)
+ return format_strings[1] % (num, name)
+
+
+NumBytesPat = re.compile('''\A (\d+ \. \d+) | (\d+)''', re.X)
+def num_bytes_to_bytes(num, binary=False, names=None):
+ """Converts a string containing a bytes size to an integer
+ @param num: (str) string to convert
+ @param binary: if True conversion factor is 1024, else factor is 1000
+ @param names: (tuple) names to use as suffix or None to use default names (see L{ByteSizeNames})
+
+ @return: (int) number of bytes
+ @note: postfixes are handled case sensitive
+
+ >>> num_bytes_to_bytes('1000B')
+ 1000
+
+ >>> num_bytes_to_bytes('1GB')
+ 1000000000
+
+ >>> num_bytes_to_bytes('1.2KB')
+ 1200
+
+ >>> num_bytes_to_bytes('1.5678B')
+ 2
+
+ >>> num_bytes_to_bytes('1MiB', binary=True)
+ 1048576
+
+ >>> num_bytes_to_bytes('1X', names=('X', ))
+ 1
- return '%01.2f%s' % (num, name)
+ >>> num_bytes_to_bytes('foo')
+ Traceback (most recent call last):
+ ...
+ ValueError: No number found in input string
+
+ >>> num_bytes_to_bytes('1foo')
+ Traceback (most recent call last):
+ ...
+ ValueError: Unknown size postfix
+ """
+ if names is None:
+ if binary:
+ names = ByteSizeNames.Binary
+ else:
+ names = ByteSizeNames.Common
+ names = list(names)
+
+ match = NumBytesPat.match(num)
+ if match is None:
+ raise ValueError('No number found in input string')
+
+ isfloat, isint = match.groups()
+ if isfloat:
+ z = len(isfloat)
+ tmp_num = float(isfloat)
+ else:
+ z = len(isint)
+ tmp_num = int(isint)
+
+ postfix = num[z: ]
+ try:
+ exp = names.index(postfix)
+ except ValueError:
+ raise ValueError('Unknown size postfix')
+ factor = 1024 if binary else 1000
+
+ #TODO: 1.96B is returned rounded as 2. Should we complain?
+ return int(round(tmp_num * (factor ** exp)))
+
-
#***************************************************************
#
#***************************************************************
@@ -245,6 +301,7 @@
num = pat.sub('', num)
return num
+
#*****************************************************************
#
#****************************************************************
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ju...@us...> - 2008-02-16 10:09:21
|
Revision: 217
http://fclient.svn.sourceforge.net/fclient/?rev=217&view=rev
Author: jurner
Date: 2008-02-16 02:09:26 -0800 (Sat, 16 Feb 2008)
Log Message:
-----------
added a few new config params
still working on how to handle byte amounts and time deltas
Modified Paths:
--------------
trunk/sandbox/fcp/fcp2_0_types.py
Modified: trunk/sandbox/fcp/fcp2_0_types.py
===================================================================
--- trunk/sandbox/fcp/fcp2_0_types.py 2008-02-16 10:07:55 UTC (rev 216)
+++ trunk/sandbox/fcp/fcp2_0_types.py 2008-02-16 10:09:26 UTC (rev 217)
@@ -3,6 +3,24 @@
This module handles type conversions from Fcp to Python and vice versa
"""
+import os, sys
+
+#--> rel import hack
+class SysPathHack(object):
+ def __init__(self, n):
+ fpath = os.path.abspath(__file__)
+ for i in xrange(n): fpath = os.path.dirname(fpath)
+ sys.path.insert(0, fpath)
+ def __del__(self): sys.path.pop(0)
+hack = SysPathHack(3)
+
+
+from fcp_lib import numbers
+
+
+del hack
+#<-- rel import hack
+
import base64
import fcp2_0_consts as consts
@@ -112,7 +130,8 @@
def fcpToPython(clss, value):
return int(value) / 1000
-
+#TODO: how to handle time deltas? Convert them to seconds?
+class FcpTypeTimeDelta(FcpType): pass
class FcpTypeIP(FcpType): pass
class FcpTypeIPList(FcpType): pass
@@ -120,7 +139,37 @@
class FcpTypeStringList(FcpType): pass
class FcpTypeDirname(FcpType): pass
class FcpTypeFilename(FcpType): pass
-class FcpTypeNumBytes(FcpType): pass
+
+#TODO: how to handle byte amounts? Convert them to (int) bytes?
+class FcpTypeNumBytes(FcpType):
+ """Type conversion """
+
+ NamesBinary = ('', 'K', 'M', 'G', 'T', 'P', 'E')
+ NamesCommon = ('', 'k', 'm', 'g', 't', 'p', 'e')
+
+ @classmethod
+ def pythonToFcp(clss, value):
+ return format_num_bytes(value, binary=True, names=clss.NamesBinary)
+
+ @classmethod
+ def fcpToPython(clss, value):
+ result = -1
+ if value and value != '-1':
+ if value[-1] in clss.NamesBinary:
+ names = clss.NamesBinary
+ binary = True
+ else:
+ names = clss.NamesCommon
+ binary = False
+ try:
+ result = numbers.num_bytes_to_bytes(value, binary=binary, names=names)
+ except ValueError:
+ pass
+ return result
+
+
+
+
class FcpTypePercent(FcpTypeFloat): pass
class FcpTypeUri(FcpType): pass
@@ -207,6 +256,7 @@
ParamClassForceWriteFlag,
ParamClassShortDescription,
ParamClassLongDescription,
+ ParamClassSortOrder,
)
# all known config keys (param class stripped)
@@ -227,7 +277,7 @@
'fcp.enabled': FcpTypeBool,
'fcp.persistentDownloadsEnabled': FcpTypeBool,
'fcp.persistentDownloadsFile': FcpTypeFilename,
- 'fcp.persistentDownloadsInterval': FcpTypeIntWithBounds(0, None),
+ 'fcp.persistentDownloadsInterval': FcpTypeTimeDelta,
'fcp.port': FcpTypeIPort,
'fcp.ssl': FcpTypeBool,
@@ -246,7 +296,7 @@
'logger.dirname': FcpTypeDirname,
'logger.enabled': FcpTypeBool,
- 'logger.interval': FcpType, # ??? 1HOUR ??
+ 'logger.interval': FcpTypeTimeDelta,
'logger.maxCachedBytes': FcpTypeNumBytes,
'logger.maxCachedLines': FcpTypeNumBytes, # ???
'logger.maxZippedLogsSize': FcpTypeNumBytes, # ???
@@ -262,6 +312,11 @@
'node.disableProbabilisticHTLs': FcpTypeBool,
'node.downloadAllowedDirs': FcpTypeChoiceNodeDownloadAllowedDirs,
'node.downloadsDir': FcpTypeDirname,
+ 'node.enableARKs': FcpTypeBool,
+ 'node.enablePerNodeFailureTables': FcpTypeBool,
+ 'node.enableSwapping': FcpTypeBool,
+ 'node.enableSwapQueueing': FcpTypeBool,
+ 'node.enableULPRDataPropagation': FcpTypeBool,
'node.extraPeerDataDir': FcpTypeDirname,
'node.includeLocalAddressesInNoderefs': FcpTypeBool,
'node.inputBandwidthLimit': FcpTypeNumBytes, # -1 is possible as value aswell
@@ -280,6 +335,7 @@
'node.storeDir': FcpTypeDirname,
'node.storeForceBigShrinks': FcpTypeBool,
'node.storeSize': FcpTypeNumBytes,
+ 'node.storeType': FcpTypeString,
'node.tempDir': FcpTypeDirname,
'node.tempIPAddressHint': FcpTypeIP, # ???
'node.testingDropPacketsEvery': FcpTypeIntWithBounds(0, None),
@@ -343,7 +399,11 @@
@param paramName: (str) parameter name to split
@return: (tuple) paramClass, tail
"""
- return paramName.split(self.ComponentSep, 1)
+ result = paramName.split(self.ComponentSep, 1)
+ if len(result) == 2:
+ if result[0] in self.ParamClasses:
+ return result
+ return '', paramName
def get(self, paramName, default=None):
@@ -363,7 +423,7 @@
@return: (FcpType)
"""
paramClass, paramKey = self.splitParamClass(paramName)
- if paramClass == self.ParamClassCurrent:
+ if paramClass == self.ParamClassCurrent or paramClass == '':
return self.Params[paramKey]
elif paramClass == self.ParamClassDefault:
return self.Params[paramKey]
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ju...@us...> - 2008-02-16 10:07:49
|
Revision: 216
http://fclient.svn.sourceforge.net/fclient/?rev=216&view=rev
Author: jurner
Date: 2008-02-16 02:07:55 -0800 (Sat, 16 Feb 2008)
Log Message:
-----------
worked a bit on uploads. Still a sketch
Modified Paths:
--------------
trunk/sandbox/fcp/fcp2_0_requests.py
Modified: trunk/sandbox/fcp/fcp2_0_requests.py
===================================================================
--- trunk/sandbox/fcp/fcp2_0_requests.py 2008-02-16 10:07:11 UTC (rev 215)
+++ trunk/sandbox/fcp/fcp2_0_requests.py 2008-02-16 10:07:55 UTC (rev 216)
@@ -4,28 +4,29 @@
#******************************************************************************************************************
#
#******************************************************************************************************************
+#TODO: if only one item is added its name is ignored so far. How to handle self.targetName vs. item['Name']
+#TODO: Metadata.ContentType vs. ContentType is pretty inconsistent
class Upload(object):
- """Wrapper class to represent a freenet upload
+ """Wrapper class to manage a freenet uploads
+ @ivar defaultItem: (int) for directories or multiple uploads the name of this item is used as
+ default item when a page is displayed
@ivar directoryAdded: (bool) True if the upload contains a directory, False otherwise
@ivar items: (list) of dicts containing paramaters for each upload
@ivar keyType: L{consts.KeyType} the type of key to upload
@ivar params: (dict) request parameters
@ivar privateKey: (str) private keey (required for SSK or USK uploads)
+ @ivar targetName: (str) for CHKs the name to be appended to the CHK. For SSKs and USKs the
+ (target-name/version) part of the key
@ivar targetNames: (list) of names already in use (for multi-uploads)
@note: you can upload one or more items of any kind (data, files, redirects), except from directories
wich have to be the only item to upload
"""
+ PrivateParamNames = ('Data', 'RequestType', 'Name')
- ReservedParamPrefix = 'Fc' # params prefixed with this are skipped when generating the message
- ItemTypeData = 0
- ItemTypeDirectory = 1
- ItemTypeFile = 2
- ItemTypeRedirect = 3
-
def __init__(self,
keyType,
dontCompress=None,
@@ -35,6 +36,7 @@
priorityClass=consts.Priority.Medium,
privateKey=None,
+ targetName=None,
):
"""
@param keyType: (L{consts.KeyType}) the desired key type to upload
@@ -45,14 +47,19 @@
@param priorityClass:
@param privateKey: (str) privateKey if keyType is SSK or USK
+ @param targetName:
"""
if keyType not in consts.KeyType.TypesAll:
raise ValueError('Invalid key type: %r' % keyType)
- if keyType in (consts.KeyType.SSK, consts.KeyType.USK) and privateKey is None:
- raise ValueError('For %s a public key is required' % keyType)
+ if keyType in (consts.KeyType.SSK, consts.KeyType.USK) :
+ if privateKey is None:
+ raise ValueError('For %s a public key is required' % keyType)
+ if not targetName:
+ raise ValueError('For %s a target name is required' % keyType)
elif keyType in (consts.KeyType.CHK, consts.KeyType.KSK) and privateKey is not None:
raise ValueError('For %s no public key is required' % keyType)
+ self.defaultItem = 0
self.directoryAdded = False
self.items = []
self.keyType = keyType
@@ -64,15 +71,16 @@
'PriorityClass': priorityClass,
}
self.privateKey = privateKey
+ self.targetName = targetName
self.targetNames = [] # record to check if names are unique (assert order is arbitrary)
- def _addItem(self, **params):
+ def _addItem(self, isDefault=False, **params):
"""Private method to add an upload item"""
if self.directoryAdded:
raise ValueError('A directory has already been added, no other items allowed')
- if params['FcItemType'] == self.ItemTypeDirectory:
+ if params['RequestType'] == self.RequestTypeDirectory:
if self.directoryAdded:
raise ValueError('An item has already been added, no additional directory allowed')
else:
@@ -85,16 +93,22 @@
self.targetNames.append(name)
self.items.append(params)
+ if isDefault:
+ self.defaultItem =len(self.items) -1
+
- def addData(self, name, data, contentType=None):
+ def addData(self, name, data, contentType=None, isDefault=False):
"""Adds data to be uploaded
@param name: target name
@param data: (str) data to upload
@param contentType: (str) content type of the data (if desired)
+ @param isDefault: (bool) if True, the item is the default item
"""
return self._addItem(
- FcItemType=self.ItemTypeData,
- FcData=data,
+ isDefault=isDefault,
+
+ RequestType=consts.RequestType.PutData,
+ Data=data,
ContentType=contentType,
DataLength=len(data),
Name=name,
@@ -111,7 +125,7 @@
@note: if you add a directory, every attempt to add anything else will fail
"""
return self._addItem(
- FcItemType=self.ItemTypeDirectory,
+ RequestType=consts.RequestType.PutDir,
AllowUnreadableFiles=allowUnreadableFiles,
Filename=directory,
Name=name,
@@ -119,28 +133,34 @@
)
- def addFile(self, name, filename, contentType=None):
+ def addFile(self, name, filename, contentType=None, isDefault=False):
"""Adds a file to be uploaded
@param name: target name
@param filename: (abspath) of the file to be uploaded
@param contentType: (str) content type of the file (if desired)
+ @param isDefault: (bool) if True, the item is the default item
"""
return self._addItem(
- FcItemType=self.ItemTypeFile,
+ isDefault=isDefault,
+
+ RequestType=sconsts.RequestType.PutFile,
ContentType=contentType,
Filename=filename,
Name=name,
UploadFrom=consts.UploadFrom.Disk,
)
-
- def addRedirect(self, name, redirect):
+ #TODO: isDefault for redirects???
+ def addRedirect(self, name, redirect, isDefault=False):
"""Adds a redirect to be uploaded
@param name: target name
@param redirect: (freenet-key) to redirect to
+ @param isDefault: (bool) if True, the item is the default item
"""
return self._addItem(
- FcItemType=self.ItemTypeRedirect,
+ isDefault=isDefault,
+
+ RequestType=consts.RequestType.PutRedirect,
ContentType=contentType,
DataLength=len(data),
Name=name,
@@ -152,81 +172,80 @@
def getMessage(self, messageClass):
"""Returns the message for the request, ready to send the request to the node
@param messageClass: (L{fcp2_0_message.Message}) class to fill in
- @return: (L{fcp2_0_message.Message}) instance
+ @return: (tuple) (L{consts.RequestType}, L{fcp2_0_message.Message}) or (None, None)
+ if ther is nothing to upload
"""
n = len(self.items)
if n == 0:
- return None
+ return None, None
- elif n == 1 and self.items[0]['FcItemType'] == self.ItemTypeDirectory:
- msg = messageClass(consts.Message.ClientPutDiskDir)
- params = self.items[0]
- targetName = params.pop('Name')
- for param, value in params.items():
- if value is None:
- continue
- if param.startswith(self.ReservedParamPrefix):
- continue
- msg[param] = value
+ elif n == 1:
+ requestType = self.items[0]['RequestType']
- elif n == 1:
- msg = messageClass(consts.Message.ClientPut)
- params = self.items[0]
- targetFilename = params.pop('Name')
- for param, value in params.items():
- if value is None:
- continue
- if param.startswith(self.ReservedParamPrefix):
- continue
+ if requestType == consts.RequestType.PutDir:
+ msg = messageClass(consts.Message.ClientPutDiskDir)
+ params = self.items[0]
+ for param, value in params.items():
+ if value is None or param in PrivateParamNames:
+ continue
+ msg[param] = value
+
+ item = self.items[self.defaultItem]
+ msg['DefaultName'] = item['Name']
+
+ else:
+ msg = messageClass(consts.Message.ClientPut)
+ for param, value in params.items():
+ if value is None or param in PrivateParamNames:
+ continue
+ if param == 'ContentType':
+ param = 'Metadata.ContentType'
+ msg[param] = value
+
+ if params['RequestType'] == self.RequestTypeData:
+ msg.data = params['Data']
- if param == 'ContentType':
- param = 'Metadata.ContentType'
- msg[param] = value
-
- if params['FcItemType'] == self.ItemTypeData:
- msg.data = params['FcData']
- if self.keyType == consts.KeyType.CHK:
- msg['TargetFilename'] = targetFilename
-
-
- #TODO: USK@s allowed for complex dirs?
else:
-
- #NOTE: for simplicity we take the first item as default item and its name
- # as TargetName if that causes any problems, pass it twice
+ requestType = consts.PutMultipole
msg = messageClass(consts.Message.ClientPutComplexDir)
- msg.data = ''
- header = self.items.pop(0)
- targetFilename = header['Name']
- msg['DefaultName'] = self.items[0]['Name']
- k = 0
- for itemParams in self.items:
+ data = None
+ for n, itemParams in enumerate(self.items):
for param, value in itemParams.items():
- if value is None:
+ if param == 'Data':
+ if data is None:
+ data = ''
+ data += value
continue
- if param.startswith(self.ReservedParamPrefix):
- if param == 'FcData':
- msg.data += value
+
+ if param == 'Name':
+ param = 'Files.%s.%s' % (n, param)
+ msg[param] = value
continue
-
+
+ if value is None or param in PrivateParamNames:
+ continue
+
if param == 'ContentType':
param = 'Metadata.ContentType'
- param = 'Files.%s.%s' % (k, param)
+ param = 'Files.%s.%s' % (n, param)
msg[param] = value
- k += 1
+
+ item = self.items[self.defaultItem]
+ msg['DefaultName'] = item['Name']
+ if data is not None:
+ msg.data = data
- if not msg.data:
- msg.data = None
-
# determine Uri
if self.keyType == consts.KeyType.CHK:
msg['URI'] = consts.KeyType.CHK
+ if self.targetName:
+ msg['TargetFilename'] = self.targetName
elif self.keyType == consts.KeyType.KSK:
- msg['URI'] = consts.KeyType.KSK + targetFilename
+ msg['URI'] = consts.KeyType.KSK + self.targetName
elif self.keyType == consts.KeyType.SSK:
- msg['URI'] = self.privateKey + targetFilename
+ msg['URI'] = self.privateKey + self.targetName
elif self.keyType == consts.KeyType.USK:
- msg['URI'] = self.privateKey + targetFilename
+ msg['URI'] = self.privateKey + self.targetName
# set params and some defaults
msg['Global'] = False
@@ -236,5 +255,5 @@
continue
msg[param] = value
- return msg
+ return requestType, msg
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ju...@us...> - 2008-02-16 10:07:06
|
Revision: 215
http://fclient.svn.sourceforge.net/fclient/?rev=215&view=rev
Author: jurner
Date: 2008-02-16 02:07:11 -0800 (Sat, 16 Feb 2008)
Log Message:
-----------
some more consts
Modified Paths:
--------------
trunk/sandbox/fcp/fcp2_0_consts.py
Modified: trunk/sandbox/fcp/fcp2_0_consts.py
===================================================================
--- trunk/sandbox/fcp/fcp2_0_consts.py 2008-02-16 10:06:20 UTC (rev 214)
+++ trunk/sandbox/fcp/fcp2_0_consts.py 2008-02-16 10:07:11 UTC (rev 215)
@@ -215,6 +215,14 @@
TypesAll = (SSK, KSK, CHK, USK, SVK)
+class LoggerNames:
+ """Logger names"""
+ Fcp = ''
+ Client = 'Client'
+ Config = 'Config'
+
+
+
class LogMessages:
"""Strings used for log infos"""
@@ -340,6 +348,25 @@
RemovedFromQueue = 0x2000000
+class PeerNodeStatus:
+ Connected = 'CONNECTED'
+ BackedOff = 'BACKED OFF'
+ TooNew = 'TOO NEW'
+ TooOld = 'TOO OLD'
+ Disconnected = 'DISCONNECTED'
+ NeverConnected = 'NEVER CONNECTED'
+ Disabled = 'DISABLED'
+ ClockProblem = 'CLOCK PROBLEM'
+ ConnectionError = 'CONNECTION ERROR'
+ RoutingDisabled = 'ROUTING DISABLED'
+ ListenOnly = 'LISTEN ONLY'
+ Listening = 'LISTENING'
+ Bursting = 'BURSTING'
+ Disconnecting = 'DISCONNECTING'
+ Unknown = 'UNKNOWN STATUS'
+
+
+
class RequestType(BaseBitFlags):
"""Consts indicating the type of a request"""
@@ -347,9 +374,11 @@
GetData = 0x1
GetFile = 0x2
GetKeyInfo = 0x4
- Put = 0x8
- PutDiskDir = 0x10
- PutComplexDir = 0x20
+ PutData = 0x8
+ PutFile = 0x10
+ PutDir = 0x20
+ PutMultiple = 0x40
+ PutRedirect = 0x80
GenerateSSKKeypair = 0x1000
GenerateUSKKeypair = 0x2000
@@ -362,7 +391,7 @@
MaskGet = GetData | GetFile | GetKeyInfo
MaskGenerateKeypair = GenerateSSKKeypair | GenerateUSKKeypair
MaskPlugin = PluginInfo | PluginMessage
- MaskPut = Put | PutDiskDir | PutComplexDir
+ MaskPut = PutData | PutFile | PutDir | PutMultiple | PutRedirect
#TODO: no idea how fcp handles strings as in <Peer volatile.status=CONNECTED>
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ju...@us...> - 2008-02-16 10:06:21
|
Revision: 214
http://fclient.svn.sourceforge.net/fclient/?rev=214&view=rev
Author: jurner
Date: 2008-02-16 02:06:20 -0800 (Sat, 16 Feb 2008)
Log Message:
-----------
added logging for unknown config params
Modified Paths:
--------------
trunk/sandbox/fcp/fcp2_0_config.py
Modified: trunk/sandbox/fcp/fcp2_0_config.py
===================================================================
--- trunk/sandbox/fcp/fcp2_0_config.py 2008-02-16 10:05:34 UTC (rev 213)
+++ trunk/sandbox/fcp/fcp2_0_config.py 2008-02-16 10:06:20 UTC (rev 214)
@@ -1,6 +1,7 @@
"""Sketch for fcp config tree"""
-
+import logging
+import fcp2_0_consts as consts
import fcp2_0_types as types
#****************************************************************************************
#
@@ -67,6 +68,7 @@
self.name = None
self.children = {}
self._configMessageParams = types.ConfigMessageParams()
+ self._log = logging.getLogger(consts.LoggerNames.Config)
if configDataMsg is not None:
for key, value in configDataMsg.params.items():
@@ -93,13 +95,17 @@
"""Adds a value to an item
@param key: (str) key to add the value to (including ParamClass prefix)
@param value to associate
+ @return: (bool) True if the key has been added, False otherwise
+
@note: if the item does not exist, it is created
+ @note: if the key is unknown its type will always be set to L{types.FcpType}
"""
paramClass, components = self._configMessageParams.splitParamClass(key)
paramType = self._configMessageParams.get(key, None)
if paramType is None:
- raise ValueError('Unknown key: %r' % components)
-
+ paramType = types.FcpType
+ self._log.warning('Unknown key: %r' % components)
+
# find or create new config item if necessary
components = self._configMessageParams.splitAll(components)
parent = self
@@ -110,9 +116,9 @@
parent.children[component] = item
parent = item
parent.values[paramClass] = (value, paramType)
-
+
+
-
def removeParamClass(self, key):
"""Removes the paramClass component if necessary
@param key: (str) key to remove the param class from
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ju...@us...> - 2008-02-16 10:05:30
|
Revision: 213
http://fclient.svn.sourceforge.net/fclient/?rev=213&view=rev
Author: jurner
Date: 2008-02-16 02:05:34 -0800 (Sat, 16 Feb 2008)
Log Message:
-----------
bit more work on uploads. Still not decided how to process.
++ some fixes
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-02-12 15:59:48 UTC (rev 212)
+++ trunk/sandbox/fcp/fcp2_0_client.py 2008-02-16 10:05:34 UTC (rev 213)
@@ -152,8 +152,16 @@
# x. Fcp seems to use kibibytes. Autoconvert to kilobytes?
#
#------------------------------------------------------------------------------------------------------------------------------------------------
+# logging
+#
+# x. should uris (...) always be visible in log output? Certainly in memory. Maybe a specialized
+# "save" logger could be useful (like for user feedback).
+#
+#------------------------------------------------------------------------------------------------------------------------------------------------
+
+
import atexit
import copy
import cPickle
@@ -266,7 +274,7 @@
# suggested by Mathew Toseland to use about 32k for mimeType requests
# basic sizes of keys are: 1k for SSks and 32k for CHKs
# without MaxSize DataFound will have DataLength set to 0 (?!)
- MaxSizeKeyInfo = 32768 #TODO: 32k
+ MaxSizeKeyInfo = 32768
SocketTimeout = 0.1
ExpectedFcpVersion = 2.0
ExpectedNodeBuild = 1107
@@ -293,7 +301,7 @@
self._ddaTests = [] # currently running DDA tests (request0, ... requestN)
self._requests = {} # currently running requests (requestIdentifier --> request)
- self._log = logging.getLogger(self.__class__.__name__)
+ self._log = logging.getLogger(consts.LoggerNames.Client)
self._nodeHelloMessage = None
self._socket = None
@@ -402,8 +410,8 @@
'FcUserData': userData, # any user defined runtime data here
# params for SSKKeypair
- 'FcInsertUri': None,
- 'FcRequestUri': None,
+ 'FcPrivateKey': None,
+ 'FcPublicKey': None,
# params from DataFound
'FcMetadataContentType': '', # contecnt type
@@ -1071,11 +1079,11 @@
)
# determine initial message name
- if requestType == consts.RequestType.Put:
+ if requestType in (consts.RequestType.PutData, consts.RequestType.PutFile):
initialRequest.name = consts.Message.ClientPut
- elif requestType == consts.RequestType.PutDiskDir:
+ elif requestType == consts.RequestType.PutDir:
initialRequest.name = consts.Message.ClientPutDiskDir
- elif requestType == consts.RequestType.PutComplexDir:
+ elif requestType == consts.RequestType.PutMultiple:
initialRequest.name = consts.Message.ClientPutComplexDir
#FIX: remove Started param from PersistentGet / Put
@@ -1344,7 +1352,6 @@
## config related methods
##
#########################################################
- #TODO: WithDefault never returns defaults
def getConfig(self,
withCurrent=True,
withDefaults=True,
@@ -1645,28 +1652,20 @@
########################################################
def putUpload(self, upload, userData=None, persistentUserData=''):
- msg = upload.getMessage(self.Message)
- if msg is None:
+ requestType, msg = upload.getMessage(self.Message)
+ if requestType is None:
raise ValueError('Nothing to upload')
- # determine SubType
- if msg.name == consts.Message.ClientPut:
- messageType = consts.RequestType.Put
- elif msg.name == consts.Message.ClientPutDiskDir:
- messageType = consts.RequestType.PutDiskDir
- else:
- messageType = consts.RequestType.PutComplexDir
-
self._registerRequest(
msg,
- messageType,
+ requestType,
persistentUserData=persistentUserData,
userData=userData,
)
if upload.keyType in (consts.KeyType.SSK, consts.KeyType.USK):
- msg['FcInsertUri'] = upload.privateKey
- #NOTE: the caller may use the 'FcInsertUri' member to store the private key
+ msg['FcPrivateKey'] = upload.privateKey
+ #NOTE: the caller may use the 'FcPrivateKey' member to store the private key
self.sendMessageEx(msg)
@@ -1678,11 +1677,18 @@
data=None,
persistentUserData='',
userData=None,
-
+ items=None,
**messageParams
):
- msg = self.Message(consts.Message.ClientPut, URI=uri)
+ if requestType in (consts.Message.ClientPutData, consts.Message.ClientPutFile):
+ msgName = consts.Message.ClientPut
+ elif requestType == consts.Message.ClientPutDir:
+ msgName = consts.Message.ClientPutDiskDir
+ else:
+ msgName = consts.Message.ClientPutComplexDir
+
+ msg = self.Message(msgName, URI=uri)
for paramName, value in messageParams.items():
if value is not None:
if paramName == 'ContentType':
@@ -1691,6 +1697,10 @@
if data is not None:
msg.data = data
+ if items:
+ pass
+
+
self._registerRequest(
msg,
requestType,
@@ -1720,7 +1730,7 @@
@param data: ()
"""
return self.clientPut(
- consts.RequestType.Put,
+ consts.RequestType.PutData,
consts.KeyType.CHK,
data=data,
@@ -1742,9 +1752,50 @@
Verbosity=consts.Verbosity.ReportProgress | consts.Verbosity.ReportCompression,
)
- def chkPutDir(self):
+ def chkPutDir(self,
+ directory,
+ allowUnreadableFiles=False,
+ contentType=None,
+ defaultName=None,
+ dontCompress=None,
+ maxRetries=None,
+ persistence=consts.Persistence.Connection,
+ priorityClass=consts.Priority.Medium,
+ targetFilename=None,
+
+ userData=None,
+ persistentUserData='',
+
+ ):
+ """
+ @param TargetFilename: (str) filename to append to the CHK key or None (may not contain slashes)
+ """
- pass
+ return self.clientPut(
+ consts.RequestType.PutDir,
+ consts.KeyType.CHK,
+
+ data=None,
+ persistentUserData=persistentUserData,
+ userData=userData,
+
+
+ # fcp params
+ Filename=directory,
+ AllowUnreadableFiles=allowUnreadableFiles,
+ ContentType=contentType,
+ DefaultName=defaultName,
+ #EarlyEncode='false',
+ #GetCHKOnly='false',
+ Global=False,
+ Identifier=None,
+ MaxRetries=maxRetries,
+ DontCompress=dontCompress,
+ Persistence=persistence,
+ TergetFilename=targetFilename,
+ UploadFrom=consts.UploadFrom.Disk,
+ Verbosity=consts.Verbosity.ReportProgress | consts.Verbosity.ReportCompression,
+ )
def chkPutFile(self,
@@ -1765,7 +1816,7 @@
"""
return self.clientPut(
- consts.RequestType.Put,
+ consts.RequestType.PutFile,
consts.KeyType.CHK,
data=None,
@@ -1790,21 +1841,52 @@
def chkPutMultiple(self,
+ directory,
items,
+
+ allowUnreadableFiles=False,
+ contentType=None,
defaultName=None,
- ):
+ dontCompress=None,
+ maxRetries=None,
+ persistence=consts.Persistence.Connection,
+ priorityClass=consts.Priority.Medium,
+ targetFilename=None,
+
+ userData=None,
+ persistentUserData='',
+
+ ):
+ """
+ @param TargetFilename: (str) filename to append to the CHK key or None (may not contain slashes)
+ """
- msg = self.Message(
- consts.PutComplexDir,
- URI=consts.KeyType.CHK
+ return self.clientPut(
+ consts.RequestType.PutMultiple,
+ consts.KeyType.CHK,
+
+ data=None,
+ persistentUserData=persistentUserData,
+ userData=userData,
+ items=items,
+
+ # fcp params
+ Filename=directory,
+ AllowUnreadableFiles=allowUnreadableFiles,
+ ContentType=contentType,
+ DefaultName=defaultName,
+ #EarlyEncode='false',
+ #GetCHKOnly='false',
+ Global=False,
+ Identifier=None,
+ MaxRetries=maxRetries,
+ DontCompress=dontCompress,
+ Persistence=persistence,
+ TergetFilename=targetFilename,
+ UploadFrom=consts.UploadFrom.Disk,
+ Verbosity=consts.Verbosity.ReportProgress | consts.Verbosity.ReportCompression,
)
-
- for n, item in enumerate(items):
-
- for paramName, value in item.items():
- pass
-
########################################################
##
## SSK ClientPut related methods
@@ -2200,7 +2282,7 @@
connectionName='test',
debugVerbosity=consts.DebugVerbosity.Debug
)
- log = c.getLogger()
+ #log = c.getLogger()
fpath = os.path.join(Dir, 'test.log')
handler = logging.FileHandler(fpath, 'w')
logging.getLogger('').addHandler(handler)
@@ -2291,12 +2373,12 @@
#c.sendMessage(c.consts.Message.GetRequestStatus, Identifier=identifier)
c.events.RequestCompleted += cb
- for i in xrange(55):
- c.next()
+ #for i in xrange(55):
+ # c.next()
#c.removeRequest(identifier)
#for i in xrange(5):
# c.next()
- c.events.RequestCompleted -= cb
+ c.run()
#testGetKeyInfo()
@@ -2390,6 +2472,9 @@
from fcp2_0_config import Config
def cb(event, msg):
+
+ #print msg['current.fcp.persistentDownloadsInterval']
+ #return
root=Config(configDataMsg=msg)
print
@@ -2420,7 +2505,31 @@
#testConfigData()
+ #testConfigData()
+
+ def testModifyConfig():
+
+ from fcp2_0_config import Config
+
+ def cb(event, msg):
+ print msg['current.logger.interval']
+ #print msg['current.fcp.persistentDownloadsInterval']
+
+ c.setDebugVerbosity(c.consts.DebugVerbosity.Warning)
+
+ c.events.ConfigData += cb
+ #c.modifyConfig({'fcp.persistentDownloadsInterval': '3000000h'})
+
+ c.modifyConfig({'logger.interval': '1'})
+
+ for i in xrange(10):
+ c.next()
+
+ #testModifyConfig()
+
+
+
def testNodeData():
def cb(event, msg):
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|