From 07d3cb1037e5d7e28a8bd68c357fb0733700e27b Mon Sep 17 00:00:00 2001 From: gwen Date: Mon, 10 Dec 2012 09:53:13 +0100 Subject: [PATCH] constants heritage --- tiramisu/setting.py | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/tiramisu/setting.py b/tiramisu/setting.py index 2bc3a9f..927fae3 100644 --- a/tiramisu/setting.py +++ b/tiramisu/setting.py @@ -20,48 +20,47 @@ # the rough pypy's guys: http://codespeak.net/svn/pypy/dist/pypy/config/ # the whole pypy projet is under MIT licence # ____________________________________________________________ - class _const: """convenient class that emulates a module - and builds constants (that is, unique group names)""" - class GroupError(TypeError): pass + and builds constants (that is, unique names)""" + class ConstError(TypeError): pass def __setattr__(self, name, value): if self.__dict__.has_key(name): - raise self.GroupError, "Can't rebind group (%s)"%name + raise self.ConstError, "Can't rebind group (%s)"%name self.__dict__[name] = value def __delattr__(self, name): if self.__dict__.has_key(name): - raise self.GroupError, "Can't unbind group (%s)"%name + raise self.ConstError, "Can't unbind group (%s)"%name raise NameError, name - -groups = _const() -def populate_groups(): - "populates the available groups in the appropriate namespaces" - _available_group_names = ('default', 'family', 'group') - _available_groups_with_a_master = ('group', ) +# ____________________________________________________________ +class GroupModule(_const): + "emulates a module to manage unique group (OptionDescription) names" class GroupName(str): """allowed normal group (OptionDescription) names *normal* means : groups that are not master """ pass - class MasterGroupName(GroupName): """allowed normal group (OptionDescription) names *master* means : groups that have the 'master' attribute set """ pass +# setting.groups (emulates a module) +groups = GroupModule() - groups.GroupName = GroupName - groups.MasterGroupName = MasterGroupName +def populate_groups(): + "populates the available groups in the appropriate namespaces" + _available_group_names = ('default', 'family', 'group') + _available_groups_with_a_master = ('group', ) # populates normal or master groups for grp in _available_group_names: if grp in _available_groups_with_a_master: - setattr(groups, grp, MasterGroupName(grp)) + setattr(groups, grp, groups.MasterGroupName(grp)) else: - setattr(groups, grp, GroupName(grp)) - + setattr(groups, grp, groups.GroupName(grp)) +# names are in the module now populate_groups() # ____________________________________________________________