[pypy-svn] r32765 - pypy/branch/even-more-config/pypy/config
cfbolz at codespeak.net
cfbolz at codespeak.net
Sat Sep 30 13:20:58 CEST 2006
Author: cfbolz
Date: Sat Sep 30 13:20:55 2006
New Revision: 32765
Modified:
pypy/branch/even-more-config/pypy/config/config.py
Log:
use cfgimpl as a prefix, as proposed by samuele
Modified: pypy/branch/even-more-config/pypy/config/config.py
==============================================================================
--- pypy/branch/even-more-config/pypy/config/config.py (original)
+++ pypy/branch/even-more-config/pypy/config/config.py Sat Sep 30 13:20:55 2006
@@ -2,49 +2,48 @@
from py.compat import optparse
class Config(object):
- _cprefix_frozen = False
+ _cfgimpl_frozen = False
def __init__(self, descr, parent=None, **overrides):
- self._cprefix_descr = descr
- self._cprefix_value_owners = {}
- self._cprefix_parent = parent
- self._cprefix_values = {}
- self._cprefix_build(overrides)
- self._cprefix_read = {}
+ self._cfgimpl_descr = descr
+ self._cfgimpl_value_owners = {}
+ self._cfgimpl_parent = parent
+ self._cfgimpl_values = {}
+ self._cfgimpl_build(overrides)
- def _cprefix_build(self, overrides):
- for child in self._cprefix_descr._children:
+ def _cfgimpl_build(self, overrides):
+ for child in self._cfgimpl_descr._children:
if isinstance(child, Option):
- self._cprefix_values[child._name] = child.default
- self._cprefix_value_owners[child._name] = 'default'
+ self._cfgimpl_values[child._name] = child.default
+ self._cfgimpl_value_owners[child._name] = 'default'
elif isinstance(child, OptionDescription):
- self._cprefix_values[child._name] = Config(child, parent=self)
+ self._cfgimpl_values[child._name] = Config(child, parent=self)
self.override(overrides)
def override(self, overrides):
for name, value in overrides.iteritems():
- subconfig, name = self._cprefix_get_by_path(name)
+ subconfig, name = self._cfgimpl_get_by_path(name)
setattr(subconfig, name, value)
def __setattr__(self, name, value):
- if self._cprefix_frozen and getattr(self, name) != value:
+ if self._cfgimpl_frozen and getattr(self, name) != value:
raise TypeError("trying to change a frozen option object")
- if name.startswith('_cprefix_'):
+ if name.startswith('_cfgimpl_'):
self.__dict__[name] = value
return
self.setoption(name, value, 'user')
def __getattr__(self, name):
- if name not in self._cprefix_values:
+ if name not in self._cfgimpl_values:
raise AttributeError("%s object has no attribute %s" %
(self.__class__, name))
- return self._cprefix_values[name]
+ return self._cfgimpl_values[name]
def setoption(self, name, value, who):
- if name not in self._cprefix_values:
+ if name not in self._cfgimpl_values:
raise ValueError('unknown option %s' % (name,))
- child = getattr(self._cprefix_descr, name)
- oldowner = self._cprefix_value_owners[child._name]
+ child = getattr(self._cfgimpl_descr, name)
+ oldowner = self._cfgimpl_value_owners[child._name]
oldvalue = getattr(self, name)
if oldowner == 'required':
if oldvalue != value:
@@ -52,29 +51,29 @@
(value, name))
return
child.setoption(self, value)
- self._cprefix_value_owners[name] = who
+ self._cfgimpl_value_owners[name] = who
def require(self, name, value):
self.setoption(name, value, "required")
- def _cprefix_get_by_path(self, path):
+ def _cfgimpl_get_by_path(self, path):
"""returns tuple (config, name)"""
path = path.split('.')
for step in path[:-1]:
self = getattr(self, step)
return self, path[-1]
- def _cprefix_get_toplevel(self):
- while self._cprefix_parent is not None:
- self = self._cprefix_parent
+ def _cfgimpl_get_toplevel(self):
+ while self._cfgimpl_parent is not None:
+ self = self._cfgimpl_parent
return self
def _freeze_(self):
- self.__dict__['_cprefix_frozen'] = True
+ self.__dict__['_cfgimpl_frozen'] = True
return True
def getkey(self):
- return self._cprefix_descr.getkey(self)
+ return self._cfgimpl_descr.getkey(self)
def __hash__(self):
return hash(self.getkey())
@@ -86,15 +85,15 @@
return not self == other
def __iter__(self):
- for child in self._cprefix_descr._children:
+ for child in self._cfgimpl_descr._children:
if isinstance(child, Option):
yield child._name, getattr(self, child._name)
def __str__(self):
result = "[%s]\n" % (self._descr._name, )
- for child in self._cprefix_descr._children:
+ for child in self._cfgimpl_descr._children:
if isinstance(child, Option):
- if self._cprefix_value_owners[child._name] == 'default':
+ if self._cfgimpl_value_owners[child._name] == 'default':
continue
result += " %s = %s\n" % (
child._name, getattr(self, child._name))
@@ -112,7 +111,7 @@
if currpath is None:
currpath = []
paths = []
- for option in self._cprefix_descr._children:
+ for option in self._cfgimpl_descr._children:
attr = option._name
if attr.startswith('_'):
continue
@@ -148,7 +147,7 @@
name = self._name
if not self.validate(value):
raise ValueError('invalid value %s for option %s' % (value, name))
- config._cprefix_values[name] = value
+ config._cfgimpl_values[name] = value
def getkey(self, value):
return value
@@ -169,8 +168,8 @@
def setoption(self, config, value):
name = self._name
for path, reqvalue in self._requires.get(value, []):
- toplevel = config._cprefix_get_toplevel()
- subconfig, name = toplevel._cprefix_get_by_path(path)
+ toplevel = config._cfgimpl_get_toplevel()
+ subconfig, name = toplevel._cfgimpl_get_by_path(path)
subconfig.require(name, reqvalue)
super(ChoiceOption, self).setoption(config, value)
@@ -313,14 +312,14 @@
for path in useoptions:
if path.endswith(".*"):
path = path[:-2]
- subconf, name = config._cprefix_get_by_path(path)
+ subconf, name = config._cfgimpl_get_by_path(path)
children = [
path + "." + child._name
- for child in getattr(subconf, name)._cprefix_descr._children]
+ for child in getattr(subconf, name)._cfgimpl_descr._children]
useoptions.extend(children)
else:
- subconf, name = config._cprefix_get_by_path(path)
- option = getattr(subconf._cprefix_descr, name)
+ subconf, name = config._cfgimpl_get_by_path(path)
+ option = getattr(subconf._cfgimpl_descr, name)
if option.cmdline is DEFAULT_OPTION_NAME:
chunks = ('--%s' % (path.replace('.', '-'),),)
elif option.cmdline is None:
@@ -328,7 +327,7 @@
else:
chunks = option.cmdline.split(' ')
try:
- grp = get_group(path, subconf._cprefix_descr.doc)
+ grp = get_group(path, subconf._cfgimpl_descr.doc)
option.add_optparse_option(chunks, grp, subconf)
except ValueError:
# an option group that does not only contain bool values
More information about the Pypy-commit
mailing list