Thread: SF.net SVN: fclient: [257] trunk/sandbox/fcp2
Status: Pre-Alpha
Brought to you by:
jurner
|
From: <ju...@us...> - 2008-02-26 10:01:24
|
Revision: 257
http://fclient.svn.sourceforge.net/fclient/?rev=257&view=rev
Author: jurner
Date: 2008-02-26 02:01:29 -0800 (Tue, 26 Feb 2008)
Log Message:
-----------
adjusted package imports
Modified Paths:
--------------
trunk/sandbox/fcp2/client.py
trunk/sandbox/fcp2/config.py
trunk/sandbox/fcp2/events.py
trunk/sandbox/fcp2/message.py
trunk/sandbox/fcp2/params.py
trunk/sandbox/fcp2/scripts/gen_docs.py
trunk/sandbox/fcp2/scripts/gen_messagecheatsheet.py
trunk/sandbox/fcp2/test_fcp/test_client.py
trunk/sandbox/fcp2/test_fcp/test_config.py
trunk/sandbox/fcp2/test_fcp/test_message.py
trunk/sandbox/fcp2/types.py
trunk/sandbox/fcp2/uri.py
Modified: trunk/sandbox/fcp2/client.py
===================================================================
--- trunk/sandbox/fcp2/client.py 2008-02-26 09:52:41 UTC (rev 256)
+++ trunk/sandbox/fcp2/client.py 2008-02-26 10:01:29 UTC (rev 257)
@@ -197,15 +197,15 @@
hack = _RelImportHack(2)
-import fcp.fcp2_0_consts as consts
-from fcp.fcp2_0_events import Events
-from fcp.fcp2_0_config import Config
-from fcp.fcp2_0_message import Message
-import fcp.fcp2_0_params as FcParams
-from fcp.fcp2_0_uri import Uri
+from fcp2 import consts
+from fcp2.config import Config
+from fcp2.events import Events
+from fcp2.message import Message
+import fcp2.params as FcParams
+from fcp2.uri import Uri
-from fcp.fcp_lib import namespace
-from fcp.fcp_lib import tools
+from fcp2.fcp_lib import namespace
+from fcp2.fcp_lib import tools
del hack
Modified: trunk/sandbox/fcp2/config.py
===================================================================
--- trunk/sandbox/fcp2/config.py 2008-02-26 09:52:41 UTC (rev 256)
+++ trunk/sandbox/fcp2/config.py 2008-02-26 10:01:29 UTC (rev 257)
@@ -12,9 +12,9 @@
def __del__(self): sys.path.pop(0)
hack = _RelImportHack(2)
-from fcp import fcp2_0_consts as consts
-from fcp import fcp2_0_types as types
-from fcp.fcp_lib import uuid
+from fcp2 import consts
+from fcp2 import types
+from fcp2.fcp_lib import uuid
del hack
Modified: trunk/sandbox/fcp2/events.py
===================================================================
--- trunk/sandbox/fcp2/events.py 2008-02-26 09:52:41 UTC (rev 256)
+++ trunk/sandbox/fcp2/events.py 2008-02-26 10:01:29 UTC (rev 257)
@@ -13,8 +13,8 @@
def __del__(self): sys.path.pop(0)
hack = _RelImportHack(2)
-from fcp import fcp2_0_types as types
-from fcp.fcp_lib import events
+from fcp2 import types
+from fcp2.fcp_lib import events
del hack
Modified: trunk/sandbox/fcp2/message.py
===================================================================
--- trunk/sandbox/fcp2/message.py 2008-02-26 09:52:41 UTC (rev 256)
+++ trunk/sandbox/fcp2/message.py 2008-02-26 10:01:29 UTC (rev 257)
@@ -13,9 +13,9 @@
def __del__(self): sys.path.pop(0)
hack = _RelImportHack(2)
-from fcp import fcp2_0_consts as consts
-from fcp import fcp2_0_types as types
-from fcp.fcp_lib import uuid
+from fcp2 import consts
+from fcp2 import types
+from fcp2.fcp_lib import uuid
del hack
Modified: trunk/sandbox/fcp2/params.py
===================================================================
--- trunk/sandbox/fcp2/params.py 2008-02-26 09:52:41 UTC (rev 256)
+++ trunk/sandbox/fcp2/params.py 2008-02-26 10:01:29 UTC (rev 257)
@@ -13,7 +13,7 @@
def __del__(self): sys.path.pop(0)
hack = _RelImportHack(2)
-from fcp.fcp_lib import uuid
+from fcp2.fcp_lib import uuid
del hack
Modified: trunk/sandbox/fcp2/scripts/gen_docs.py
===================================================================
--- trunk/sandbox/fcp2/scripts/gen_docs.py 2008-02-26 09:52:41 UTC (rev 256)
+++ trunk/sandbox/fcp2/scripts/gen_docs.py 2008-02-26 10:01:29 UTC (rev 257)
@@ -21,7 +21,7 @@
def __del__(self): sys.path.pop(0)
hack = _RelImportHack(3)
-from fcp.scripts import fcpscripts_consts as consts
+from fcp2.scripts import fcpscripts_consts as consts
del hack
Modified: trunk/sandbox/fcp2/scripts/gen_messagecheatsheet.py
===================================================================
--- trunk/sandbox/fcp2/scripts/gen_messagecheatsheet.py 2008-02-26 09:52:41 UTC (rev 256)
+++ trunk/sandbox/fcp2/scripts/gen_messagecheatsheet.py 2008-02-26 10:01:29 UTC (rev 257)
@@ -32,7 +32,7 @@
def __del__(self): sys.path.pop(0)
hack = _RelImportHack(3)
-from fcp.scripts import fcpscripts_consts as consts
+from fcp2.scripts import fcpscripts_consts as consts
del hack
Modified: trunk/sandbox/fcp2/test_fcp/test_client.py
===================================================================
--- trunk/sandbox/fcp2/test_fcp/test_client.py 2008-02-26 09:52:41 UTC (rev 256)
+++ trunk/sandbox/fcp2/test_fcp/test_client.py 2008-02-26 10:01:29 UTC (rev 257)
@@ -17,9 +17,9 @@
def __del__(self): sys.path.pop(0)
hack = _RelImportHack(3)
-from fcp import fcp2_0_client
-from fcp.fcp2_0_client import FcpClient
-from fcp import fcp2_0_consts as consts
+from fcp2 import client
+from fcp2.client import FcpClient
+from fcp2 import consts
del hack
@@ -123,7 +123,7 @@
# inject our customized socket module
socketModule = DummySocketModule()
- fcp2_0_client.socket = socketModule
+ client.socket = socketModule
def __init__(self, *args, **kwargs):
Modified: trunk/sandbox/fcp2/test_fcp/test_config.py
===================================================================
--- trunk/sandbox/fcp2/test_fcp/test_config.py 2008-02-26 09:52:41 UTC (rev 256)
+++ trunk/sandbox/fcp2/test_fcp/test_config.py 2008-02-26 10:01:29 UTC (rev 257)
@@ -13,9 +13,9 @@
def __del__(self): sys.path.pop(0)
hack = _RelImportHack(3)
-from fcp.fcp2_0_client import FcpClient
+from fcp2.client import FcpClient
Message = FcpClient.Message
-from fcp import fcp2_0_types as types
+from fcp2 import types
del hack
#<-- rel import hack
Modified: trunk/sandbox/fcp2/test_fcp/test_message.py
===================================================================
--- trunk/sandbox/fcp2/test_fcp/test_message.py 2008-02-26 09:52:41 UTC (rev 256)
+++ trunk/sandbox/fcp2/test_fcp/test_message.py 2008-02-26 10:01:29 UTC (rev 257)
@@ -13,9 +13,9 @@
def __del__(self): sys.path.pop(0)
hack = _RelImportHack(3)
-from fcp.fcp2_0_client import FcpClient
+from fcp2.client import FcpClient
Message = FcpClient.Message
-from fcp import fcp2_0_consts as consts
+from fcp2 import consts
del hack
Modified: trunk/sandbox/fcp2/types.py
===================================================================
--- trunk/sandbox/fcp2/types.py 2008-02-26 09:52:41 UTC (rev 256)
+++ trunk/sandbox/fcp2/types.py 2008-02-26 10:01:29 UTC (rev 257)
@@ -15,8 +15,8 @@
def __del__(self): sys.path.pop(0)
hack =_RelImportHack(2)
-from fcp import fcp2_0_consts as consts
-from fcp.fcp_lib import numbers
+from fcp2 import consts
+from fcp2.fcp_lib import numbers
del hack
Modified: trunk/sandbox/fcp2/uri.py
===================================================================
--- trunk/sandbox/fcp2/uri.py 2008-02-26 09:52:41 UTC (rev 256)
+++ trunk/sandbox/fcp2/uri.py 2008-02-26 10:01:29 UTC (rev 257)
@@ -14,10 +14,9 @@
def __del__(self): sys.path.pop(0)
hack = _RelImportHack(2)
+from fcp2 import consts
-from fcp import fcp2_0_consts as consts
-
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-26 15:29:59
|
Revision: 273
http://fclient.svn.sourceforge.net/fclient/?rev=273&view=rev
Author: jurner
Date: 2008-02-26 07:30:00 -0800 (Tue, 26 Feb 2008)
Log Message:
-----------
renames
Added Paths:
-----------
trunk/sandbox/fcp2/fcparams.py
Removed Paths:
-------------
trunk/sandbox/fcp2/params.py
Copied: trunk/sandbox/fcp2/fcparams.py (from rev 257, trunk/sandbox/fcp2/params.py)
===================================================================
--- trunk/sandbox/fcp2/fcparams.py (rev 0)
+++ trunk/sandbox/fcp2/fcparams.py 2008-02-26 15:30:00 UTC (rev 273)
@@ -0,0 +1,154 @@
+"""Handling of persistent request parameters"""
+
+import sys, os
+import base64
+import time
+
+#--> rel import hack
+class _RelImportHack(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 = _RelImportHack(2)
+
+from fcp2.fcp_lib import uuid
+
+
+del hack
+#<-- rel import hack
+#*********************************************************************************************
+#
+#*********************************************************************************************
+def validateFcpBool(value):
+ if value in ('true', 'false'):
+ return str(value)
+ return None
+
+def validateFloat(value):
+ try:
+ return float(value)
+ except ValueError:
+ return None
+
+def validateInt(value):
+ try:
+ return int(value)
+ except ValueError:
+ return None
+
+#TODO: validate FcPersistentUserData... only ASCII (???) chars allowed
+def validateString(value):
+ try:
+ return str(value)
+ except UnicodeEncodeError:
+ return None
+
+
+def validateUuid(value):
+ result = uuid.UUID_EXACT_MATCH_PAT.match(value)
+ if result:
+ return str(result.group(0))
+ return None
+
+
+#*********************************************************************************************
+#
+#*********************************************************************************************
+FcParamsSep = '\x01'
+MAGIC = '{8a7808d0-3934-465a-b1b4-b7150ed109a5}' # magic string to identify our requests
+
+FcParams = (
+ ('FcRequestType', validateInt),
+ ('FcInitTime', validateFloat), # can not take it from uuid cos requests may be resend multiple times
+ ('FcFilenameCollision', validateInt),
+ ('FcPersistentUserData', validateString),
+ )
+
+IRequestType = 0
+IInitTime = 1
+IFilenameCollision = 2
+IPersistentUserData = 3
+
+def paramsFromRequest(msg):
+ """Extracts fclient parameters from the identifier of a request
+ @param msg: message to extract the parameters from
+ @return: (list) parameters or None if something went wrong
+
+ >>> params = [1, 123.456, 'false', 'false', uuid.uuid_time(), 123456789]
+ >>> identifier = FcParamsSep.join( [str(i) for i in params] )
+ >>> result = paramsFromRequest({'Identifier': identifier})
+ >>> result == params
+ True
+
+ """
+ userData = msg.get('ClientToken', None)
+ if userData is None:
+ return None
+
+ params = userData.split(FcParamsSep)
+ if len(params) != len(FcParams) +1:
+ return None
+
+ # validate and drop our magic string
+ uuid_ = params.pop(0)
+ result = validateUuid(uuid_)
+ if result is None:
+ return None
+ if result != MAGIC:
+ return None
+
+ for i, (paramName, paramValidator) in enumerate(FcParams):
+ result = paramValidator(params[i])
+ if result is None:
+ return None
+ params[i] = result
+
+ # decode user data
+ try:
+ params[IPersistentUserData] = base64.b64decode(params[IPersistentUserData])
+ except TypeError:
+ return None
+
+ return params
+
+
+def messageToParams(msg):
+ """Generates fc params from a message
+ @param msg: message to create the identifier from
+ @return: (str) params
+
+ """
+ params = []
+ for paramName, paramValidator in FcParams:
+ params.append( str(msg[paramName]) )
+
+ # encode user data
+ params[IPersistentUserData] = base64.b64encode(params[IPersistentUserData])
+ params.insert(0, MAGIC)
+
+ return FcParamsSep.join(params)
+
+
+def newUuid(uuids=None):
+ """Creates a new unique identifier
+ @param uuids: if desired any iterable containing uuids to enshure the identifier is unique in the iterable
+ @return: (str) uuid
+
+ """
+ uuid_ = uuid.uuid_time()
+ if uuids is not None:
+ while uuid_ in uuids:
+ uuid_ = uuid_time()
+ return uuid_
+
+
+#*********************************************************************************
+#
+#*********************************************************************************
+if __name__ == '__main__2':
+ import doctest
+ doctest.testmod()
+
+
Deleted: trunk/sandbox/fcp2/params.py
===================================================================
--- trunk/sandbox/fcp2/params.py 2008-02-26 15:18:18 UTC (rev 272)
+++ trunk/sandbox/fcp2/params.py 2008-02-26 15:30:00 UTC (rev 273)
@@ -1,154 +0,0 @@
-"""Handling of persistent request parameters"""
-
-import sys, os
-import base64
-import time
-
-#--> rel import hack
-class _RelImportHack(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 = _RelImportHack(2)
-
-from fcp2.fcp_lib import uuid
-
-
-del hack
-#<-- rel import hack
-#*********************************************************************************************
-#
-#*********************************************************************************************
-def validateFcpBool(value):
- if value in ('true', 'false'):
- return str(value)
- return None
-
-def validateFloat(value):
- try:
- return float(value)
- except ValueError:
- return None
-
-def validateInt(value):
- try:
- return int(value)
- except ValueError:
- return None
-
-#TODO: validate FcPersistentUserData... only ASCII (???) chars allowed
-def validateString(value):
- try:
- return str(value)
- except UnicodeEncodeError:
- return None
-
-
-def validateUuid(value):
- result = uuid.UUID_EXACT_MATCH_PAT.match(value)
- if result:
- return str(result.group(0))
- return None
-
-
-#*********************************************************************************************
-#
-#*********************************************************************************************
-FcParamsSep = '\x01'
-MAGIC = '{8a7808d0-3934-465a-b1b4-b7150ed109a5}' # magic string to identify our requests
-
-FcParams = (
- ('FcRequestType', validateInt),
- ('FcInitTime', validateFloat), # can not take it from uuid cos requests may be resend multiple times
- ('FcFilenameCollision', validateInt),
- ('FcPersistentUserData', validateString),
- )
-
-IRequestType = 0
-IInitTime = 1
-IFilenameCollision = 2
-IPersistentUserData = 3
-
-def paramsFromRequest(msg):
- """Extracts fclient parameters from the identifier of a request
- @param msg: message to extract the parameters from
- @return: (list) parameters or None if something went wrong
-
- >>> params = [1, 123.456, 'false', 'false', uuid.uuid_time(), 123456789]
- >>> identifier = FcParamsSep.join( [str(i) for i in params] )
- >>> result = paramsFromRequest({'Identifier': identifier})
- >>> result == params
- True
-
- """
- userData = msg.get('ClientToken', None)
- if userData is None:
- return None
-
- params = userData.split(FcParamsSep)
- if len(params) != len(FcParams) +1:
- return None
-
- # validate and drop our magic string
- uuid_ = params.pop(0)
- result = validateUuid(uuid_)
- if result is None:
- return None
- if result != MAGIC:
- return None
-
- for i, (paramName, paramValidator) in enumerate(FcParams):
- result = paramValidator(params[i])
- if result is None:
- return None
- params[i] = result
-
- # decode user data
- try:
- params[IPersistentUserData] = base64.b64decode(params[IPersistentUserData])
- except TypeError:
- return None
-
- return params
-
-
-def messageToParams(msg):
- """Generates fc params from a message
- @param msg: message to create the identifier from
- @return: (str) params
-
- """
- params = []
- for paramName, paramValidator in FcParams:
- params.append( str(msg[paramName]) )
-
- # encode user data
- params[IPersistentUserData] = base64.b64encode(params[IPersistentUserData])
- params.insert(0, MAGIC)
-
- return FcParamsSep.join(params)
-
-
-def newUuid(uuids=None):
- """Creates a new unique identifier
- @param uuids: if desired any iterable containing uuids to enshure the identifier is unique in the iterable
- @return: (str) uuid
-
- """
- uuid_ = uuid.uuid_time()
- if uuids is not None:
- while uuid_ in uuids:
- uuid_ = uuid_time()
- return uuid_
-
-
-#*********************************************************************************
-#
-#*********************************************************************************
-if __name__ == '__main__2':
- import doctest
- doctest.testmod()
-
-
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ju...@us...> - 2008-02-26 19:00:12
|
Revision: 283
http://fclient.svn.sourceforge.net/fclient/?rev=283&view=rev
Author: jurner
Date: 2008-02-26 11:00:14 -0800 (Tue, 26 Feb 2008)
Log Message:
-----------
minor changes
Modified Paths:
--------------
trunk/sandbox/fcp2/LICENCE.MIT
trunk/sandbox/fcp2/README
Modified: trunk/sandbox/fcp2/LICENCE.MIT
===================================================================
--- trunk/sandbox/fcp2/LICENCE.MIT 2008-02-26 18:54:12 UTC (rev 282)
+++ trunk/sandbox/fcp2/LICENCE.MIT 2008-02-26 19:00:14 UTC (rev 283)
@@ -1,4 +1,4 @@
- Fcp - a python wraper library for the freenet client protocol. See: [http://www.freenetproject.org]
+ Fcp2 - a python wraper library for the freenet client protocol version 2. See: [http://www.freenetproject.org]
Copyright (c) 2008 J\xFCrgen Urner
Modified: trunk/sandbox/fcp2/README
===================================================================
--- trunk/sandbox/fcp2/README 2008-02-26 18:54:12 UTC (rev 282)
+++ trunk/sandbox/fcp2/README 2008-02-26 19:00:14 UTC (rev 283)
@@ -1,4 +1,4 @@
-Fcp - a python wraper library for the freenet client protocol. See: [http://www.freenetproject.org]
+Fcp - a python wraper library for the freenet client protocol version 2. See: [http://www.freenetproject.org]
@@ -8,6 +8,8 @@
*******************************************************************
0.1.0
*******************************************************************
+Initial release
+
news:
x.
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|