api: permissive => forcepermissive

api: add permissive object
test api: permissive
config: unwrap_from_path check properties for option, not only optiondescription
option: _RegexpOption => RegexpOption
This commit is contained in:
2017-11-03 21:52:13 +01:00
parent 39348a14aa
commit 2e412b64fd
16 changed files with 1073 additions and 986 deletions

View File

@ -404,15 +404,16 @@ class BaseOption(Base):
name = name.encode('utf8')
return name
def reset_cache(self, opt, obj, type_, orig_opts):
context = obj._getcontext()
path = self.impl_getpath(context)
obj._p_.delcache(path)
orig_opts.add(opt)
context.cfgimpl_reset_cache(only=(type_,),
opt=self,
path=path,
orig_opts=orig_opts)
def reset_cache(self, opt, obj, type_, resetted_opts):
if opt in resetted_opts:
return
if not type_ == 'values' or not opt.impl_is_optiondescription():
path = opt.impl_getpath(obj._getcontext())
if type_ != 'permissives':
obj._p_.delcache(path)
if type_ in ['settings', 'permissives']:
obj._pp_.delcache(path)
resetted_opts.add(opt)
def _is_symlinkoption(self):
return False

View File

@ -21,10 +21,10 @@
import re
from ..i18n import _
from .option import _RegexpOption
from .option import RegexpOption
class EmailOption(_RegexpOption):
class EmailOption(RegexpOption):
__slots__ = tuple()
#https://www.w3.org/TR/html-markup/input.email.html#input.email.attrs.value.single.
_regexp = re.compile(r"^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$")

View File

@ -21,10 +21,10 @@
import re
from ..i18n import _
from .option import _RegexpOption
from .option import RegexpOption
class FilenameOption(_RegexpOption):
class FilenameOption(RegexpOption):
__slots__ = tuple()
_regexp = re.compile(r"^[a-zA-Z0-9\-\._~/+]+$")
_display_name = _('file name')

View File

@ -503,7 +503,7 @@ class Option(OnlyOption):
all_cons_opts = tuple([self] + list(other_opts))
unknown_params = set(params.keys()) - set(['warnings_only', 'transitive'])
if unknown_params != set():
raise ValueError(_('unknow parameter {0} in consistency').format(unknown_params))
raise ValueError(_('unknown parameter {0} in consistency').format(unknown_params))
self._add_consistency(func, all_cons_opts, params)
#validate default value when add consistency
err = self.impl_validate(self.impl_getdefault())
@ -660,7 +660,7 @@ class Option(OnlyOption):
return hasattr(self, '_consistencies')
class _RegexpOption(Option):
class RegexpOption(Option):
__slots__ = tuple()
def _validate(self, value, context=undefined, current_opt=undefined):
@ -670,3 +670,7 @@ class _RegexpOption(Option):
match = self._regexp.search(value)
if not match:
return ValueError()
#FIXME compatibility
_RegexpOption = RegexpOption

View File

@ -358,11 +358,10 @@ class OptionDescriptionWalk(CacheOptionDescription):
for child in self._impl_st_getchildren(context):
cname = child.impl_getname()
if dyn and child.impl_is_dynoptiondescription():
path = cname
for value in child._impl_get_suffixes(context):
yield SynDynOptionDescription(child,
cname + value,
path + value, value)
value)
else:
yield child
@ -383,17 +382,16 @@ class OptionDescriptionWalk(CacheOptionDescription):
for child in self._impl_st_getchildren(context, only_dyn=True):
cname = child.impl_getname()
if name.startswith(cname):
path = cname
for value in child._impl_get_suffixes(context):
if name == cname + value:
return SynDynOptionDescription(child, name, path + value, value)
return SynDynOptionDescription(child, name, value)
return ret
def _impl_get_dynchild(self, child, suffix):
name = child.impl_getname() + suffix
path = self.impl_getname() + suffix + '.' + name
if isinstance(child, OptionDescription):
return SynDynOptionDescription(child, name, path, suffix)
return SynDynOptionDescription(child, name, suffix)
else:
return child._impl_to_dyn(name, path)
@ -524,12 +522,11 @@ class DynOptionDescription(OptionDescription):
class SynDynOptionDescription(object):
__slots__ = ('_opt', '_name', '_path', '_suffix')
__slots__ = ('_opt', '_name', '_suffix')
def __init__(self, opt, name, path, suffix):
def __init__(self, opt, name, suffix):
self._opt = opt
self._name = name
self._path = path
self._suffix = suffix
def __getattr__(self, name, context=undefined):
@ -549,7 +546,10 @@ class SynDynOptionDescription(object):
return self._impl_getchildren()
def impl_getpath(self, context):
return self._path
path = self._impl_getopt().impl_getpath(context).split('.')
path[-1] += self._suffix
path.append(self._name)
return '.'.join(path)
def impl_getpaths(self, include_groups=False, _currpath=None):
return _impl_getpaths(self, include_groups, _currpath)
@ -825,12 +825,13 @@ class MasterSlaves(OptionDescription):
" which has {1} as master").format(
name, opt.impl_getname()))
def reset_cache(self, opt, values, type_, orig_opts):
path = self.getmaster(opt).impl_getpath(values._getcontext())
values._p_.delcache(path)
for slave in self.getslaves(opt):
slave_path = slave.impl_getpath(values._getcontext())
values._p_.delcache(slave_path)
def reset_cache(self, opt, obj, type_, resetted_opts):
context = obj._getcontext()
#FIXME pb avec dyn, devrait etre une option
mopt = self.getmaster(None)
mopt.reset_cache(mopt, obj, type_, resetted_opts)
for slave in self.getslaves(mopt):
slave.reset_cache(slave, obj, type_, resetted_opts)
def _getattr(self, name, suffix=undefined, context=undefined, dyn=True):
return super(MasterSlaves, self)._getattr(name, suffix, context, dyn)