SF.net SVN: fclient: [197] trunk/sandbox/fcp/fcp2_0_consts.py
Status: Pre-Alpha
Brought to you by:
jurner
From: <ju...@us...> - 2008-02-09 09:36:13
|
Revision: 197 http://fclient.svn.sourceforge.net/fclient/?rev=197&view=rev Author: jurner Date: 2008-02-09 01:36:15 -0800 (Sat, 09 Feb 2008) Log Message: ----------- some fixes and a debug helper for bitflags 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-09 09:35:22 UTC (rev 196) +++ trunk/sandbox/fcp/fcp2_0_consts.py 2008-02-09 09:36:15 UTC (rev 197) @@ -6,6 +6,31 @@ #************************************************************************ # #************************************************************************ +class BaseBitFlags(object): + """Base class for classes containing bitflags (bitflags only that is)""" + + @classmethod + def humanReadable(clss, flags): + """Returns a list containing human readable names of bitflags as + defined in the class + @param flags: bit flags to translate into human readables + @return: (list) + + @note: use this for debugging for example + """ + out = [] + for name in dir(clss): + if name[0].isupper(): + const = getattr(clss, name) + if isinstance(const, (int, long)): + if flags & const: + out.append(name) + return out + +#************************************************************************ +# +#************************************************************************ + FcpTrue = 'true' FcpFalse = 'false' @@ -146,7 +171,7 @@ Warning = logging.WARNING -class DisconnectReason: +class DisconnectReason(BaseBitFlags): """Reasons for client disconnect @cvar ConnectingFailed: connection could not be established @cvar DuplicateClientName: another client opend a connection with the same connection name @@ -154,14 +179,14 @@ @cvar SocketDied: connection to the node died unexpectingly @cvar VersionMissmatch: node or Fcp version did not match """ - ConnectingFailed = 1 - DuplicateClientName = 2 - Shutdown = 3 - SocketDied = 4 - VersionMissmatch = 5 #TODO: implement??? + ConnectingFailed = 0x1 + DuplicateClientName = 0x2 + Shutdown = 0x4 + SocketDied = 0x8 + VersionMissmatch = 0x10 #TODO: implement??? -class FilenameCollision: +class FilenameCollision(BaseBitFlags): """Filename collision flags @cvar HandleNever: don't handle filename collisions @cvar HandleRename: rename file on collisions @@ -215,7 +240,7 @@ ClientPut = 'ClientPut' ClientPutDiskDir = 'ClientPutDiskDir' ClientPutComplexDir = 'ClientPutComplexDir' - FCPPlugin = 'FCPPlugin' + FCPPluginMessage = 'FCPPluginMessage' GenerateSSK = 'GenerateSSK' GetConfig = 'GetConfig' # (since 1027) GetNode = 'GetNode' @@ -279,19 +304,8 @@ ClientSocketDied = 2 ClientDisconnected = 3 - ClientKeyRequestMessages = ( - ClientGet, - ClientPut, - ClientPutDiskDir, - ClientPutComplexDir, - ) - ClientPluginMessages = ( - GetPluginInfo, - FCPPlugin, - ) - -class RequestStatus: +class RequestStatus(BaseBitFlags): """Request status flags @cvar Null: no status @cvar Restored: the request was restored when the client was started @@ -318,9 +332,9 @@ Completed =0x10000000 RemovedFromQueue = 0x2000000 - - -class RequestType: + + +class RequestType(BaseBitFlags): """Consts indicating the type of a request""" Null = 0 @@ -383,7 +397,7 @@ Low = '4' -class RequestModified: +class RequestModified(BaseBitFlags): """Flags indicating what of a request has been modified @cvar Filename: the filename has been modified @cvar Identifier: the identifier has been moodified @@ -412,7 +426,7 @@ Redirect = 'redirect' -class Verbosity: +class Verbosity(BaseBitFlags): ReportCompletion = 0x0 ReportProgress = 0x1 ReportCompression = 0x200 This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |