From: Mark Wooding Date: Sat, 16 Mar 2013 00:31:03 +0000 (+0000) Subject: operation.py: Refactor `polswitch' a little. X-Git-Tag: 1.0.0~14 X-Git-Url: https://git.distorted.org.uk/~mdw/chopwood/commitdiff_plain/d6b72d90e658140961b040e53c009d82fa0f11c9?hp=ea3f041b2d50610848bfd7eabc81588ca7d9e223 operation.py: Refactor `polswitch' a little. We're going to use this structure again. --- diff --git a/operation.py b/operation.py index 1184e3d..e10a1b5 100644 --- a/operation.py +++ b/operation.py @@ -41,6 +41,16 @@ import util as U ### password.) ###-------------------------------------------------------------------------- +### Some utilities. + +OPS = ['set', 'reset', 'clear'] +## A list of the available operations. + +class polswitch (U.struct): + """A small structure holding a value for each operation.""" + __slots__ = OPS + +###-------------------------------------------------------------------------- ### Operation protocol. ## An operation deals with a single service/user pair. The protocol works @@ -243,14 +253,11 @@ CONF.export('ClearRequest') ###-------------------------------------------------------------------------- ### Master policy switch. -class polswitch (U.struct): - __slots__ = ['set', 'reset', 'clear'] - CONF.DEFAULTS.update( ## Map a request type `set', `reset', or `clear', to the appropriate ## request class. - RQCLASS = polswitch(None, None, None), + RQCLASS = polswitch(**dict((i, None) for i in OPS)), ## Alternatively, set this to a mixin class to apply common policy to all ## the kinds of requests.