Thread: SF.net SVN: fclient: [286] trunk/sandbox/fcp2/fcparams.py
Status: Pre-Alpha
Brought to you by:
jurner
|
From: <ju...@us...> - 2008-02-27 00:13:16
|
Revision: 286
http://fclient.svn.sourceforge.net/fclient/?rev=286&view=rev
Author: jurner
Date: 2008-02-26 16:13:21 -0800 (Tue, 26 Feb 2008)
Log Message:
-----------
beautifications
Modified Paths:
--------------
trunk/sandbox/fcp2/fcparams.py
Modified: trunk/sandbox/fcp2/fcparams.py
===================================================================
--- trunk/sandbox/fcp2/fcparams.py 2008-02-27 00:13:16 UTC (rev 285)
+++ trunk/sandbox/fcp2/fcparams.py 2008-02-27 00:13:21 UTC (rev 286)
@@ -1,4 +1,4 @@
-"""Handling of persistent request parameters"""
+"""Handling of additional persistent parameters for requests"""
import sys, os
import base64
@@ -45,14 +45,12 @@
except UnicodeEncodeError:
return None
-
def validateUuid(value):
result = uuid.UUID_EXACT_MATCH_PAT.match(value)
if result:
return str(result.group(0))
return None
-
#*********************************************************************************************
#
#*********************************************************************************************
@@ -76,12 +74,6 @@
@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:
@@ -101,6 +93,7 @@
for i, (paramName, paramValidator) in enumerate(FcParams):
result = paramValidator(params[i])
+ print paramName, paramValidator, result
if result is None:
return None
params[i] = result
@@ -143,7 +136,6 @@
uuid_ = uuid_time()
return uuid_
-
#*********************************************************************************
#
#*********************************************************************************
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ju...@us...> - 2008-02-27 12:07:25
|
Revision: 291
http://fclient.svn.sourceforge.net/fclient/?rev=291&view=rev
Author: jurner
Date: 2008-02-27 04:07:31 -0800 (Wed, 27 Feb 2008)
Log Message:
-----------
minor change
Modified Paths:
--------------
trunk/sandbox/fcp2/fcparams.py
Modified: trunk/sandbox/fcp2/fcparams.py
===================================================================
--- trunk/sandbox/fcp2/fcparams.py 2008-02-27 12:06:59 UTC (rev 290)
+++ trunk/sandbox/fcp2/fcparams.py 2008-02-27 12:07:31 UTC (rev 291)
@@ -38,7 +38,6 @@
except ValueError:
return None
-#TODO: validate FcPersistentUserData... only ASCII (???) chars allowed
def validateString(value):
try:
return str(value)
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ju...@us...> - 2008-02-27 13:52:07
|
Revision: 293
http://fclient.svn.sourceforge.net/fclient/?rev=293&view=rev
Author: jurner
Date: 2008-02-27 05:52:12 -0800 (Wed, 27 Feb 2008)
Log Message:
-----------
removed a leftover print statement
Modified Paths:
--------------
trunk/sandbox/fcp2/fcparams.py
Modified: trunk/sandbox/fcp2/fcparams.py
===================================================================
--- trunk/sandbox/fcp2/fcparams.py 2008-02-27 13:51:52 UTC (rev 292)
+++ trunk/sandbox/fcp2/fcparams.py 2008-02-27 13:52:12 UTC (rev 293)
@@ -92,7 +92,6 @@
for i, (paramName, paramValidator) in enumerate(FcParams):
result = paramValidator(params[i])
- print paramName, paramValidator, result
if result is None:
return None
params[i] = result
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jU...@us...> - 2008-03-07 09:54:10
|
Revision: 331
http://fclient.svn.sourceforge.net/fclient/?rev=331&view=rev
Author: jUrner
Date: 2008-03-07 01:54:15 -0800 (Fri, 07 Mar 2008)
Log Message:
-----------
adapt to Fc prefix has gone
Modified Paths:
--------------
trunk/sandbox/fcp2/fcparams.py
Modified: trunk/sandbox/fcp2/fcparams.py
===================================================================
--- trunk/sandbox/fcp2/fcparams.py 2008-03-07 09:53:48 UTC (rev 330)
+++ trunk/sandbox/fcp2/fcparams.py 2008-03-07 09:54:15 UTC (rev 331)
@@ -57,10 +57,10 @@
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),
+ ('RequestType', validateInt),
+ ('InitTime', validateFloat), # can not take it from uuid cos requests may be resend multiple times
+ ('FilenameCollision', validateInt),
+ ('PersistentUserData', validateString),
)
IRequestType = 0
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jU...@us...> - 2008-03-11 01:03:15
|
Revision: 360
http://fclient.svn.sourceforge.net/fclient/?rev=360&view=rev
Author: jUrner
Date: 2008-03-10 18:03:20 -0700 (Mon, 10 Mar 2008)
Log Message:
-----------
no longer needed
Removed Paths:
-------------
trunk/sandbox/fcp2/fcparams.py
Deleted: trunk/sandbox/fcp2/fcparams.py
===================================================================
--- trunk/sandbox/fcp2/fcparams.py 2008-03-11 01:02:55 UTC (rev 359)
+++ trunk/sandbox/fcp2/fcparams.py 2008-03-11 01:03:20 UTC (rev 360)
@@ -1,144 +0,0 @@
-"""Handling of additional persistent parameters for requests"""
-
-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
-
-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 = (
- ('RequestType', validateInt),
- ('InitTime', validateFloat), # can not take it from uuid cos requests may be resend multiple times
- ('FilenameCollision', validateInt),
- ('PersistentUserData', 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
-
- """
- 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.
|