change None to undefined when it's needed
This commit is contained in:
parent
3ab0688c46
commit
aa0734591d
@ -10,3 +10,4 @@ Sat Apr 12 11:37:27 CEST 2014 Emmanuel Garette <egarette@cadoles.com>
|
||||
object MasterSlaves for all code related to master/slaves options
|
||||
* tiramisu/option/masterslave.py: master and slaves values (length,
|
||||
consistency, ...) are now check every time
|
||||
* change None to undefined when needed
|
||||
|
@ -22,7 +22,7 @@
|
||||
import weakref
|
||||
from tiramisu.error import PropertiesOptionError, ConfigError
|
||||
from tiramisu.option import OptionDescription, Option, SymLinkOption
|
||||
from tiramisu.setting import groups, Settings, default_encoding
|
||||
from tiramisu.setting import groups, Settings, default_encoding, undefined
|
||||
from tiramisu.storage import get_storages, get_storage, set_storage, \
|
||||
_impl_getstate_setting
|
||||
from tiramisu.value import Values, Multi
|
||||
@ -256,7 +256,7 @@ class SubConfig(object):
|
||||
validate=validate,
|
||||
force_permissive=force_permissive)
|
||||
|
||||
def find(self, bytype=None, byname=None, byvalue=None, type_='option',
|
||||
def find(self, bytype=None, byname=None, byvalue=undefined, type_='option',
|
||||
check_properties=True, force_permissive=False):
|
||||
"""
|
||||
finds a list of options recursively in the config
|
||||
@ -273,7 +273,7 @@ class SubConfig(object):
|
||||
check_properties=check_properties,
|
||||
force_permissive=force_permissive)
|
||||
|
||||
def find_first(self, bytype=None, byname=None, byvalue=None,
|
||||
def find_first(self, bytype=None, byname=None, byvalue=undefined,
|
||||
type_='option', display_error=True, check_properties=True,
|
||||
force_permissive=False):
|
||||
"""
|
||||
@ -306,7 +306,7 @@ class SubConfig(object):
|
||||
return False
|
||||
|
||||
def _filter_by_value():
|
||||
if byvalue is None:
|
||||
if byvalue is undefined:
|
||||
return True
|
||||
try:
|
||||
value = self.getattr(path, force_permissive=force_permissive)
|
||||
@ -344,7 +344,7 @@ class SubConfig(object):
|
||||
if not _filter_by_type():
|
||||
continue
|
||||
#remove option with propertyerror, ...
|
||||
if byvalue is None and check_properties:
|
||||
if byvalue is undefined and check_properties:
|
||||
try:
|
||||
value = self.getattr(path,
|
||||
force_permissive=force_permissive)
|
||||
@ -375,7 +375,7 @@ class SubConfig(object):
|
||||
return find_results
|
||||
|
||||
def make_dict(self, flatten=False, _currpath=None, withoption=None,
|
||||
withvalue=None, force_permissive=False):
|
||||
withvalue=undefined, force_permissive=False):
|
||||
"""exports the whole config into a `dict`, for example:
|
||||
|
||||
>>> print cfg.make_dict()
|
||||
@ -415,7 +415,7 @@ class SubConfig(object):
|
||||
pathsvalues = []
|
||||
if _currpath is None:
|
||||
_currpath = []
|
||||
if withoption is None and withvalue is not None:
|
||||
if withoption is None and withvalue is not undefined:
|
||||
raise ValueError(_("make_dict can't filtering with value without "
|
||||
"option"))
|
||||
if withoption is not None:
|
||||
@ -433,7 +433,7 @@ class SubConfig(object):
|
||||
if mypath is not None:
|
||||
if mypath == path:
|
||||
withoption = None
|
||||
withvalue = None
|
||||
withvalue = undefined
|
||||
break
|
||||
else:
|
||||
tmypath = mypath + '.'
|
||||
@ -535,7 +535,7 @@ class _CommonConfig(SubConfig):
|
||||
"""
|
||||
self._impl_values.set_information(key, value)
|
||||
|
||||
def impl_get_information(self, key, default=None):
|
||||
def impl_get_information(self, key, default=undefined):
|
||||
"""retrieves one information's item
|
||||
|
||||
:param key: the item string (ex: "help")
|
||||
@ -661,7 +661,7 @@ class GroupConfig(_CommonConfig):
|
||||
except PropertiesOptionError:
|
||||
pass
|
||||
|
||||
def find_firsts(self, byname=None, bypath=None, byvalue=None,
|
||||
def find_firsts(self, byname=None, bypath=None, byvalue=undefined,
|
||||
type_='path', display_error=True):
|
||||
"""Find first not in current GroupConfig, but in each children
|
||||
"""
|
||||
@ -671,7 +671,7 @@ class GroupConfig(_CommonConfig):
|
||||
try:
|
||||
if bypath is None and byname is not None and \
|
||||
isinstance(self, MetaConfig):
|
||||
bypath = self._find(bytype=None, byvalue=None, byname=byname,
|
||||
bypath = self._find(bytype=None, byvalue=undefined, byname=byname,
|
||||
first=True, type_='path',
|
||||
check_properties=False,
|
||||
display_error=display_error)
|
||||
@ -684,7 +684,7 @@ class GroupConfig(_CommonConfig):
|
||||
if bypath is not None:
|
||||
#if byvalue is None, try if not raise
|
||||
value = getattr(child, bypath)
|
||||
if byvalue is not None:
|
||||
if byvalue is not undefined:
|
||||
if isinstance(value, Multi):
|
||||
if byvalue in value:
|
||||
ret.append(child)
|
||||
|
@ -24,7 +24,7 @@ from types import FunctionType
|
||||
import warnings
|
||||
|
||||
from tiramisu.i18n import _
|
||||
from tiramisu.setting import log
|
||||
from tiramisu.setting import log, undefined
|
||||
from tiramisu.autolib import carry_out_calculation
|
||||
from tiramisu.error import ConfigError, ValueWarning
|
||||
|
||||
@ -164,14 +164,14 @@ class BaseOption(object):
|
||||
"""
|
||||
self._impl_informations[key] = value
|
||||
|
||||
def impl_get_information(self, key, default=None):
|
||||
def impl_get_information(self, key, default=undefined):
|
||||
"""retrieves one information's item
|
||||
|
||||
:param key: the item string (ex: "help")
|
||||
"""
|
||||
if key in self._impl_informations:
|
||||
return self._impl_informations[key]
|
||||
elif default is not None:
|
||||
elif default is not undefined:
|
||||
return default
|
||||
else:
|
||||
raise ValueError(_("information's item not found: {0}").format(
|
||||
|
@ -396,7 +396,7 @@ class Values(object):
|
||||
"""
|
||||
self._p_.set_information(key, value)
|
||||
|
||||
def get_information(self, key, default=None):
|
||||
def get_information(self, key, default=undefined):
|
||||
"""retrieves one information's item
|
||||
|
||||
:param key: the item string (ex: "help")
|
||||
@ -404,7 +404,7 @@ class Values(object):
|
||||
try:
|
||||
return self._p_.get_information(key)
|
||||
except ValueError:
|
||||
if default is not None:
|
||||
if default is not undefined:
|
||||
return default
|
||||
else:
|
||||
raise ValueError(_("information's item"
|
||||
|
Loading…
Reference in New Issue
Block a user