works on sqlalchemy storage
This commit is contained in:
@ -103,11 +103,11 @@ class Base(StorageBase):
|
||||
if not valid_name(name): # pragma: optional cover
|
||||
raise ValueError(_("invalid name: {0} for option").format(name))
|
||||
if requires is not None:
|
||||
self._calc_properties, self._requires = validate_requires_arg(
|
||||
calc_properties, requires = validate_requires_arg(
|
||||
requires, name)
|
||||
#else:
|
||||
# self._calc_properties = frozenset()
|
||||
# self._requires = []
|
||||
else:
|
||||
calc_properties = frozenset()
|
||||
requires = undefined
|
||||
if not multi and default_multi is not None: # pragma: optional cover
|
||||
raise ValueError(_("a default_multi is set whereas multi is False"
|
||||
" in option: {0}").format(name))
|
||||
@ -127,17 +127,18 @@ class Base(StorageBase):
|
||||
if validator is not None:
|
||||
validate_callback(validator, validator_params, 'validator')
|
||||
self._set_validator(validator, validator_params)
|
||||
if self.impl_get_calc_properties() != frozenset([]) and properties is not tuple(): # pragma: optional cover
|
||||
set_forbidden_properties = self.impl_get_calc_properties() & set(properties)
|
||||
if calc_properties != frozenset([]) and properties is not tuple(): # pragma: optional cover
|
||||
set_forbidden_properties = calc_properties & set(properties)
|
||||
if set_forbidden_properties != frozenset():
|
||||
raise ValueError('conflict: properties already set in '
|
||||
'requirement {0}'.format(
|
||||
list(set_forbidden_properties)))
|
||||
super(Base, self).__init__(name, _multi, warnings_only, doc, extra)
|
||||
StorageBase.__init__(self, name, _multi, warnings_only, doc, extra,
|
||||
calc_properties, requires, properties)
|
||||
self._set_default_values(default, default_multi)
|
||||
if callback is not False:
|
||||
self.impl_set_callback(callback, callback_params)
|
||||
self._properties = properties
|
||||
self.commit()
|
||||
|
||||
def impl_set_callback(self, callback, callback_params=None):
|
||||
if callback is None and callback_params is not None: # pragma: optional cover
|
||||
@ -275,12 +276,12 @@ class BaseOption(Base):
|
||||
except AttributeError: # pragma: optional cover
|
||||
raise SystemError(_('cannot serialize Option, '
|
||||
'only in OptionDescription'))
|
||||
slots = set()
|
||||
for subclass in self.__class__.__mro__:
|
||||
if subclass is not object:
|
||||
slots.update(subclass.__slots__)
|
||||
slots -= frozenset(['_cache_paths', '_cache_consistencies',
|
||||
'__weakref__'])
|
||||
if isinstance(self, SymLinkOption):
|
||||
slots = frozenset(['_name', '_state_opt', '_stated'])
|
||||
else:
|
||||
slots = self._impl_getattributes()
|
||||
slots -= frozenset(['_cache_paths', '_cache_consistencies',
|
||||
'__weakref__'])
|
||||
states = {}
|
||||
for slot in slots:
|
||||
# remove variable if save variable converted
|
||||
@ -338,9 +339,10 @@ class BaseOption(Base):
|
||||
"""
|
||||
if name not in ('_option', '_is_build_cache') \
|
||||
and not isinstance(value, tuple) and \
|
||||
not name.startswith('_state'):
|
||||
not name.startswith('_state') and \
|
||||
not name == '_sa_instance_state':
|
||||
is_readonly = False
|
||||
# never change _name
|
||||
# never change _name dans _opt
|
||||
if name == '_name':
|
||||
try:
|
||||
if self.impl_getname() is not None:
|
||||
@ -348,13 +350,21 @@ class BaseOption(Base):
|
||||
is_readonly = True
|
||||
except (KeyError, AttributeError):
|
||||
pass
|
||||
elif name == '_opt':
|
||||
try:
|
||||
if self._impl_getopt() is not None:
|
||||
#so _opt is already set
|
||||
is_readonly = True
|
||||
except (KeyError, AttributeError):
|
||||
pass
|
||||
elif name != '_readonly':
|
||||
is_readonly = self.impl_is_readonly()
|
||||
if is_readonly: # pragma: optional cover
|
||||
raise AttributeError(_("'{0}' ({1}) object attribute '{2}' is"
|
||||
" read-only").format(
|
||||
self.__class__.__name__,
|
||||
self.impl_getname(),
|
||||
self,
|
||||
#self.impl_getname(),
|
||||
name))
|
||||
super(BaseOption, self).__setattr__(name, value)
|
||||
|
||||
@ -844,29 +854,31 @@ def validate_requires_arg(requires, name):
|
||||
|
||||
|
||||
class SymLinkOption(OnlyOption):
|
||||
__slots__ = ('_opt', '_state_opt', '_readonly')
|
||||
# __slots__ = ('_opt', '_state_opt')
|
||||
|
||||
def __init__(self, name, opt):
|
||||
if not isinstance(opt, Option): # pragma: optional cover
|
||||
raise ValueError(_('malformed symlinkoption '
|
||||
'must be an option '
|
||||
'for symlink {0}').format(name))
|
||||
self._opt = opt
|
||||
self._set_readonly()
|
||||
super(Base, self).__init__(name, undefined, undefined, undefined, undefined)
|
||||
super(Base, self).__init__(name, undefined, undefined, undefined,
|
||||
undefined, undefined, undefined, undefined,
|
||||
opt)
|
||||
self.commit()
|
||||
|
||||
def __getattr__(self, name, context=undefined):
|
||||
if name in ('_opt', '_opt_type', '_readonly', 'impl_getpath', '_name', '_state_opt'):
|
||||
if name in ('_opt', '_opt_type', '_readonly', 'impl_getpath', '_name',
|
||||
'_state_opt', '_impl_setopt'):
|
||||
return object.__getattr__(self, name)
|
||||
else:
|
||||
return getattr(self._opt, name)
|
||||
return getattr(self._impl_getopt(), name)
|
||||
|
||||
def _impl_getstate(self, descr):
|
||||
self._stated = True
|
||||
self._state_opt = descr.impl_get_path_by_opt(self._opt)
|
||||
self._state_opt = descr.impl_get_path_by_opt(self._impl_getopt())
|
||||
|
||||
def _impl_setstate(self, descr):
|
||||
self._opt = descr.impl_get_opt_by_path(self._state_opt)
|
||||
self._impl_setopt(descr.impl_get_opt_by_path(self._state_opt))
|
||||
del(self._state_opt)
|
||||
try:
|
||||
del(self._stated)
|
||||
@ -875,46 +887,56 @@ class SymLinkOption(OnlyOption):
|
||||
self._set_readonly()
|
||||
|
||||
def impl_get_information(self, key, default=undefined):
|
||||
return self._opt.impl_get_information(key, default)
|
||||
|
||||
def _set_readonly(self):
|
||||
self._readonly = True
|
||||
return self._impl_getopt().impl_get_information(key, default)
|
||||
|
||||
def impl_is_readonly(self):
|
||||
try:
|
||||
return self._readonly
|
||||
except AttributeError:
|
||||
return False
|
||||
return True
|
||||
|
||||
def impl_getproperties(self):
|
||||
return self._opt._properties
|
||||
return self._impl_getopt()._properties
|
||||
|
||||
def impl_get_callback(self):
|
||||
return self._opt.impl_get_callback()
|
||||
return self._impl_getopt().impl_get_callback()
|
||||
|
||||
def impl_has_callback(self):
|
||||
"to know if a callback has been defined or not"
|
||||
return self._opt.impl_has_callback()
|
||||
return self._impl_getopt().impl_has_callback()
|
||||
|
||||
def impl_is_multi(self):
|
||||
return self._impl_getopt().impl_is_multi()
|
||||
|
||||
def _is_subdyn(self):
|
||||
try:
|
||||
return self._opt._subdyn is not None
|
||||
return self._impl_getopt()._subdyn is not None
|
||||
except AttributeError:
|
||||
return False
|
||||
|
||||
|
||||
class DynSymLinkOption(SymLinkOption):
|
||||
__slots__ = ('_dyn',)
|
||||
class DynSymLinkOption(object):
|
||||
__slots__ = ('_dyn', '_opt', '_name')
|
||||
|
||||
def __init__(self, name, opt, dyn):
|
||||
self._name = name
|
||||
self._dyn = dyn
|
||||
super(DynSymLinkOption, self).__init__(name, opt)
|
||||
self._opt = opt
|
||||
|
||||
def __getattr__(self, name, context=undefined):
|
||||
if name in ('_opt', '_opt_type', '_readonly', 'impl_getpath', '_name', '_state_opt'):
|
||||
return object.__getattr__(self, name)
|
||||
else:
|
||||
return getattr(self._impl_getopt(), name)
|
||||
|
||||
def impl_getname(self):
|
||||
return self._name
|
||||
|
||||
def _impl_getopt(self):
|
||||
return self._opt
|
||||
|
||||
def impl_getsuffix(self):
|
||||
return self._dyn.split('.')[-1][len(self._opt.impl_getname()):]
|
||||
return self._dyn.split('.')[-1][len(self._impl_getopt().impl_getname()):]
|
||||
|
||||
def impl_getpath(self, context):
|
||||
path = self._opt.impl_getpath(context)
|
||||
path = self._impl_getopt().impl_getpath(context)
|
||||
base_path = '.'.join(path.split('.')[:-2])
|
||||
if self.impl_is_master_slaves() and base_path is not '':
|
||||
base_path = base_path + self.impl_getsuffix()
|
||||
@ -925,5 +947,7 @@ class DynSymLinkOption(SymLinkOption):
|
||||
|
||||
def impl_validate(self, value, context=undefined, validate=True,
|
||||
force_index=None, force_submulti_index=None):
|
||||
return self._opt.impl_validate(value, context, validate, force_index,
|
||||
force_submulti_index, current_opt=self)
|
||||
return self._impl_getopt().impl_validate(value, context, validate,
|
||||
force_index,
|
||||
force_submulti_index,
|
||||
current_opt=self)
|
||||
|
@ -168,7 +168,7 @@ class OptionDescription(BaseOption, StorageOptionDescription):
|
||||
return True
|
||||
#consistencies is something like [('_cons_not_equal', (opt1, opt2))]
|
||||
if isinstance(option, DynSymLinkOption):
|
||||
consistencies = self._cache_consistencies.get(option._opt)
|
||||
consistencies = self._cache_consistencies.get(option._impl_getopt())
|
||||
else:
|
||||
consistencies = self._cache_consistencies.get(option)
|
||||
if consistencies is not None:
|
||||
@ -177,7 +177,7 @@ class OptionDescription(BaseOption, StorageOptionDescription):
|
||||
#all_cons_opts[0] is the option where func is set
|
||||
if isinstance(option, DynSymLinkOption):
|
||||
subpath = '.'.join(option._dyn.split('.')[:-1])
|
||||
namelen = len(option._opt.impl_getname())
|
||||
namelen = len(option._impl_getopt().impl_getname())
|
||||
suffix = option.impl_getname()[namelen:]
|
||||
opts = []
|
||||
for opt in all_cons_opts:
|
||||
@ -361,6 +361,9 @@ class SynDynOptionDescription(object):
|
||||
def impl_getpaths(self, include_groups=False, _currpath=None):
|
||||
return _impl_getpaths(self, include_groups, _currpath)
|
||||
|
||||
def _impl_getopt(self):
|
||||
return self._opt
|
||||
|
||||
|
||||
def _impl_getpaths(klass, include_groups, _currpath):
|
||||
"""returns a list of all paths in klass, recursively
|
||||
|
Reference in New Issue
Block a user