python 3.4 support
This commit is contained in:
parent
924692d3ab
commit
7305cfa134
|
@ -372,7 +372,7 @@ def test_config_od_function():
|
||||||
descr = OptionDescription('tiramisu', '', [o])
|
descr = OptionDescription('tiramisu', '', [o])
|
||||||
cfg = Config(descr)
|
cfg = Config(descr)
|
||||||
try:
|
try:
|
||||||
print cfg.impl_get_opt_by_path()
|
print(cfg.impl_get_opt_by_path())
|
||||||
except AttributeError, err:
|
except AttributeError as err:
|
||||||
assert str(err) == _('unknown Option {0} in OptionDescription {1}'
|
assert str(err) == _('unknown Option {0} in OptionDescription {1}'
|
||||||
'').format('impl_get_opt_by_path', descr.impl_getname())
|
'').format('impl_get_opt_by_path', descr.impl_getname())
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
from autopath import do_autopath
|
from autopath import do_autopath
|
||||||
do_autopath()
|
do_autopath()
|
||||||
|
|
||||||
import warnings
|
import warnings, sys
|
||||||
from py.test import raises
|
from py.test import raises
|
||||||
|
|
||||||
from tiramisu.config import Config
|
from tiramisu.config import Config
|
||||||
|
@ -49,14 +49,20 @@ def test_domainname_upper():
|
||||||
has_error = False
|
has_error = False
|
||||||
try:
|
try:
|
||||||
c.d = 'TOTO.COM'
|
c.d = 'TOTO.COM'
|
||||||
except ValueError, err:
|
except ValueError as err:
|
||||||
|
if sys.version_info[0] >= 3: # pragma: optional cover
|
||||||
|
assert msg in str(err)
|
||||||
|
else:
|
||||||
assert msg in unicode(err)
|
assert msg in unicode(err)
|
||||||
has_error = True
|
has_error = True
|
||||||
assert has_error is True
|
assert has_error is True
|
||||||
has_error = False
|
has_error = False
|
||||||
try:
|
try:
|
||||||
c.d = 'toTo.com'
|
c.d = 'toTo.com'
|
||||||
except ValueError, err:
|
except ValueError as err:
|
||||||
|
if sys.version_info[0] >= 3: # pragma: optional cover
|
||||||
|
assert msg in str(err)
|
||||||
|
else:
|
||||||
assert msg in unicode(err)
|
assert msg in unicode(err)
|
||||||
has_error = True
|
has_error = True
|
||||||
assert has_error is True
|
assert has_error is True
|
||||||
|
|
|
@ -207,7 +207,7 @@ def test_prop_dyndescription():
|
||||||
assert str(cfg.cfgimpl_get_settings()[stval2]) in [str(['test']), str([u'test'])]
|
assert str(cfg.cfgimpl_get_settings()[stval2]) in [str(['test']), str([u'test'])]
|
||||||
cfg.cfgimpl_get_settings()[stval2].append('test2')
|
cfg.cfgimpl_get_settings()[stval2].append('test2')
|
||||||
assert str(cfg.cfgimpl_get_settings()[stval1]) in [str(['test']), str([u'test'])]
|
assert str(cfg.cfgimpl_get_settings()[stval1]) in [str(['test']), str([u'test'])]
|
||||||
assert str(cfg.cfgimpl_get_settings()[stval2]) in [str(['test', 'test2']), str([u'test', 'test2'])]
|
assert str(cfg.cfgimpl_get_settings()[stval2]) in [str(['test', 'test2']), str([u'test', 'test2']), str(['test2', 'test'])]
|
||||||
cfg.cfgimpl_get_settings()[stval1].remove('test')
|
cfg.cfgimpl_get_settings()[stval1].remove('test')
|
||||||
assert str(cfg.cfgimpl_get_settings()[stval1]) == str([])
|
assert str(cfg.cfgimpl_get_settings()[stval1]) == str([])
|
||||||
#
|
#
|
||||||
|
@ -417,7 +417,7 @@ def test_prop_dyndescription_context():
|
||||||
assert str(cfg.cfgimpl_get_settings()[stval2]) in [str(['test']), str([u'test'])]
|
assert str(cfg.cfgimpl_get_settings()[stval2]) in [str(['test']), str([u'test'])]
|
||||||
cfg.cfgimpl_get_settings()[stval2].append('test2')
|
cfg.cfgimpl_get_settings()[stval2].append('test2')
|
||||||
assert str(cfg.cfgimpl_get_settings()[stval1]) in [str(['test']), str([u'test'])]
|
assert str(cfg.cfgimpl_get_settings()[stval1]) in [str(['test']), str([u'test'])]
|
||||||
assert str(cfg.cfgimpl_get_settings()[stval2]) in [str(['test', 'test2']), str([u'test', 'test2'])]
|
assert str(cfg.cfgimpl_get_settings()[stval2]) in [str(['test', 'test2']), str([u'test', 'test2']), str(['test2', 'test'])]
|
||||||
cfg.cfgimpl_get_settings()[stval1].remove('test')
|
cfg.cfgimpl_get_settings()[stval1].remove('test')
|
||||||
assert str(cfg.cfgimpl_get_settings()[stval1]) == str([])
|
assert str(cfg.cfgimpl_get_settings()[stval1]) == str([])
|
||||||
|
|
||||||
|
@ -1346,7 +1346,7 @@ def test_invalid_samevalue_dyndescription():
|
||||||
od = OptionDescription('od', '', [dod])
|
od = OptionDescription('od', '', [dod])
|
||||||
cfg = Config(od)
|
cfg = Config(od)
|
||||||
cfg
|
cfg
|
||||||
raises(ConfigError, "print cfg")
|
raises(ConfigError, "print(cfg)")
|
||||||
|
|
||||||
|
|
||||||
def test_invalid_name_dyndescription():
|
def test_invalid_name_dyndescription():
|
||||||
|
@ -1355,4 +1355,4 @@ def test_invalid_name_dyndescription():
|
||||||
od = OptionDescription('od', '', [dod])
|
od = OptionDescription('od', '', [dod])
|
||||||
cfg = Config(od)
|
cfg = Config(od)
|
||||||
cfg
|
cfg
|
||||||
raises(ValueError, "print cfg")
|
raises(ValueError, "print(cfg)")
|
||||||
|
|
|
@ -10,6 +10,7 @@ from tiramisu.storage import delete_session
|
||||||
from tiramisu.error import ConfigError
|
from tiramisu.error import ConfigError
|
||||||
from pickle import dumps, loads
|
from pickle import dumps, loads
|
||||||
from py.test import raises
|
from py.test import raises
|
||||||
|
import sys
|
||||||
|
|
||||||
|
|
||||||
def return_value(value=None):
|
def return_value(value=None):
|
||||||
|
@ -460,7 +461,7 @@ def test_state_groupconfig():
|
||||||
def test_state_unkown_setting_owner():
|
def test_state_unkown_setting_owner():
|
||||||
"""load an unknow _owner, should create it"""
|
"""load an unknow _owner, should create it"""
|
||||||
assert not 'supernewuser' in owners.__dict__
|
assert not 'supernewuser' in owners.__dict__
|
||||||
loads("""ccopy_reg
|
val = """ccopy_reg
|
||||||
_reconstructor
|
_reconstructor
|
||||||
p0
|
p0
|
||||||
(ctiramisu.setting
|
(ctiramisu.setting
|
||||||
|
@ -496,5 +497,8 @@ sS'_properties'
|
||||||
p17
|
p17
|
||||||
(dp18
|
(dp18
|
||||||
sbsb.
|
sbsb.
|
||||||
.""")
|
."""
|
||||||
|
if sys.version_info[0] >= 3: # pragma: optional cover
|
||||||
|
val = bytes(val, "UTF-8")
|
||||||
|
loads(val)
|
||||||
assert 'supernewuser' in owners.__dict__
|
assert 'supernewuser' in owners.__dict__
|
||||||
|
|
|
@ -243,7 +243,7 @@ def calculate(callback, args, kwargs, returns_raise):
|
||||||
if returns_raise:
|
if returns_raise:
|
||||||
try:
|
try:
|
||||||
return callback(*args, **kwargs)
|
return callback(*args, **kwargs)
|
||||||
except ValueError, err:
|
except ValueError as err:
|
||||||
return err
|
return err
|
||||||
else:
|
else:
|
||||||
return callback(*args, **kwargs)
|
return callback(*args, **kwargs)
|
||||||
|
|
|
@ -20,6 +20,7 @@
|
||||||
# ____________________________________________________________
|
# ____________________________________________________________
|
||||||
"options handler global entry point"
|
"options handler global entry point"
|
||||||
import weakref
|
import weakref
|
||||||
|
import sys
|
||||||
|
|
||||||
|
|
||||||
from .error import PropertiesOptionError, ConfigError, ConflictError
|
from .error import PropertiesOptionError, ConfigError, ConflictError
|
||||||
|
@ -33,6 +34,10 @@ from .value import Values, Multi
|
||||||
from .i18n import _
|
from .i18n import _
|
||||||
|
|
||||||
|
|
||||||
|
if sys.version_info[0] >= 3: # pragma: optional cover
|
||||||
|
xrange = range
|
||||||
|
|
||||||
|
|
||||||
class SubConfig(object):
|
class SubConfig(object):
|
||||||
"""Sub configuration management entry.
|
"""Sub configuration management entry.
|
||||||
Tree if OptionDescription's responsability. SubConfig are generated
|
Tree if OptionDescription's responsability. SubConfig are generated
|
||||||
|
|
|
@ -21,6 +21,7 @@
|
||||||
import re
|
import re
|
||||||
from types import FunctionType
|
from types import FunctionType
|
||||||
import warnings
|
import warnings
|
||||||
|
import sys
|
||||||
|
|
||||||
from ..i18n import _
|
from ..i18n import _
|
||||||
from ..setting import log, undefined
|
from ..setting import log, undefined
|
||||||
|
@ -344,6 +345,10 @@ class BaseOption(Base):
|
||||||
return self._properties
|
return self._properties
|
||||||
|
|
||||||
def _impl_valid_unicode(self, value):
|
def _impl_valid_unicode(self, value):
|
||||||
|
if sys.version_info[0] >= 3:
|
||||||
|
if not isinstance(value, str):
|
||||||
|
return ValueError(_('invalid string'))
|
||||||
|
else:
|
||||||
if not isinstance(value, unicode) and not isinstance(value, str):
|
if not isinstance(value, unicode) and not isinstance(value, str):
|
||||||
return ValueError(_('invalid unicode or string'))
|
return ValueError(_('invalid unicode or string'))
|
||||||
|
|
||||||
|
@ -676,7 +681,7 @@ class Option(OnlyOption):
|
||||||
warnings_only, transitive)
|
warnings_only, transitive)
|
||||||
if err:
|
if err:
|
||||||
if warnings_only:
|
if warnings_only:
|
||||||
return ValueWarning(err.message, option)
|
return ValueWarning(str(err), option)
|
||||||
else:
|
else:
|
||||||
return err
|
return err
|
||||||
|
|
||||||
|
|
|
@ -278,6 +278,9 @@ class PortOption(Option):
|
||||||
|
|
||||||
def _validate(self, value, context=undefined, current_opt=undefined):
|
def _validate(self, value, context=undefined, current_opt=undefined):
|
||||||
if isinstance(value, int):
|
if isinstance(value, int):
|
||||||
|
if sys.version_info[0] >= 3: # pragma: optional cover
|
||||||
|
value = str(value)
|
||||||
|
else:
|
||||||
value = unicode(value)
|
value = unicode(value)
|
||||||
err = self._impl_valid_unicode(value)
|
err = self._impl_valid_unicode(value)
|
||||||
if err:
|
if err:
|
||||||
|
|
|
@ -35,6 +35,11 @@ StorageOptionDescription = get_storages_option('optiondescription')
|
||||||
|
|
||||||
name_regexp = re.compile(r'^[a-zA-Z\d\-_]*$')
|
name_regexp = re.compile(r'^[a-zA-Z\d\-_]*$')
|
||||||
|
|
||||||
|
import sys
|
||||||
|
if sys.version_info[0] >= 3: # pragma: optional cover
|
||||||
|
xrange = range
|
||||||
|
del(sys)
|
||||||
|
|
||||||
|
|
||||||
class OptionDescription(BaseOption, StorageOptionDescription):
|
class OptionDescription(BaseOption, StorageOptionDescription):
|
||||||
"""Config's schema (organisation, group) and container of Options
|
"""Config's schema (organisation, group) and container of Options
|
||||||
|
|
|
@ -130,7 +130,7 @@ def get_storages(context, session_id, persistent):
|
||||||
values = imp.Values(storage)
|
values = imp.Values(storage)
|
||||||
try:
|
try:
|
||||||
return settings, values
|
return settings, values
|
||||||
except Exception, err:
|
except Exception as err:
|
||||||
raise Exception(_('unable to get storages:') + str(err))
|
raise Exception(_('unable to get storages:') + str(err))
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -17,11 +17,14 @@
|
||||||
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
#
|
#
|
||||||
# ____________________________________________________________
|
# ____________________________________________________________
|
||||||
|
import sys
|
||||||
from ...i18n import _
|
from ...i18n import _
|
||||||
from ...setting import undefined
|
from ...setting import undefined
|
||||||
from ...error import ConfigError
|
from ...error import ConfigError
|
||||||
static_tuple = tuple()
|
static_tuple = tuple()
|
||||||
static_set = frozenset()
|
static_set = frozenset()
|
||||||
|
if sys.version_info[0] >= 3: # pragma: optional cover
|
||||||
|
xrange = range
|
||||||
|
|
||||||
|
|
||||||
#____________________________________________________________
|
#____________________________________________________________
|
||||||
|
@ -128,7 +131,7 @@ class StorageBase(object):
|
||||||
if isinstance(dico, tuple):
|
if isinstance(dico, tuple):
|
||||||
if key in dico[0]:
|
if key in dico[0]:
|
||||||
return dico[1][dico[0].index(key)]
|
return dico[1][dico[0].index(key)]
|
||||||
elif isinstance(dico, str) or isinstance(dico, unicode):
|
elif self._is_string(dico):
|
||||||
if key == 'doc':
|
if key == 'doc':
|
||||||
return dico
|
return dico
|
||||||
elif isinstance(dico, dict):
|
elif isinstance(dico, dict):
|
||||||
|
@ -262,6 +265,12 @@ class StorageBase(object):
|
||||||
def _impl_setopt(self, opt):
|
def _impl_setopt(self, opt):
|
||||||
self._opt = opt
|
self._opt = opt
|
||||||
|
|
||||||
|
def _is_string(self, infos):
|
||||||
|
if sys.version_info[0] >= 3: # pragma: optional cover
|
||||||
|
return isinstance(infos, str)
|
||||||
|
else:
|
||||||
|
return isinstance(infos, str) or isinstance(infos, unicode)
|
||||||
|
|
||||||
def _impl_convert_zinformations(self, descr, load=False):
|
def _impl_convert_zinformations(self, descr, load=False):
|
||||||
if not load:
|
if not load:
|
||||||
infos = self._informations
|
infos = self._informations
|
||||||
|
@ -269,7 +278,7 @@ class StorageBase(object):
|
||||||
self._state_informations = {}
|
self._state_informations = {}
|
||||||
for idx, key in enumerate(infos[0]):
|
for idx, key in enumerate(infos[0]):
|
||||||
self._state_informations[key] = infos[1][idx]
|
self._state_informations[key] = infos[1][idx]
|
||||||
elif isinstance(infos, str) or isinstance(infos, unicode):
|
elif self._is_string(infos):
|
||||||
self._state_informations = {'doc': infos}
|
self._state_informations = {'doc': infos}
|
||||||
else:
|
else:
|
||||||
self._state_informations = infos
|
self._state_informations = infos
|
||||||
|
|
|
@ -114,8 +114,10 @@ class Cache(object):
|
||||||
return path in self._cache and index in self._cache[path]
|
return path in self._cache and index in self._cache[path]
|
||||||
|
|
||||||
def reset_expired_cache(self, exp):
|
def reset_expired_cache(self, exp):
|
||||||
for key in self._cache.keys():
|
cache_keys = list(self._cache.keys())
|
||||||
for index in self._cache[key].keys():
|
for key in cache_keys:
|
||||||
|
key_cache_keys = list(self._cache[key].keys())
|
||||||
|
for index in key_cache_keys:
|
||||||
val, created = self._cache[key][index]
|
val, created = self._cache[key][index]
|
||||||
if created is not None and exp > created:
|
if created is not None and exp > created:
|
||||||
del(self._cache[key][index])
|
del(self._cache[key][index])
|
||||||
|
|
Loading…
Reference in New Issue