# HG changeset patch # User Thomas De Schampheleire # Date 2020-10-09 20:09:40 # Node ID 1394d16cc82a5c9df5ea36f09d10b9c8b8be3204 # Parent 9398244a25256620339a674d5d889290f835635d lib: remove now unused class Optional Last usage was removed in previous commit. diff --git a/kallithea/lib/utils2.py b/kallithea/lib/utils2.py --- a/kallithea/lib/utils2.py +++ b/kallithea/lib/utils2.py @@ -466,48 +466,6 @@ def get_current_authuser(): return None -class Optional(object): - """ - Defines an optional parameter:: - - param = param.getval() if isinstance(param, Optional) else param - param = param() if isinstance(param, Optional) else param - - is equivalent of:: - - param = Optional.extract(param) - - """ - - def __init__(self, type_): - self.type_ = type_ - - def __repr__(self): - return '' % self.type_.__repr__() - - def __call__(self): - return self.getval() - - def getval(self): - """ - returns value from this Optional instance - """ - return self.type_ - - @classmethod - def extract(cls, val): - """ - Extracts value from Optional() instance - - :param val: - :return: original value if it's not Optional instance else - value of instance - """ - if isinstance(val, cls): - return val.getval() - return val - - def urlreadable(s, _cleanstringsub=re.compile('[^-a-zA-Z0-9./]+').sub): return _cleanstringsub('_', s).rstrip('_') diff --git a/kallithea/tests/api/api_base.py b/kallithea/tests/api/api_base.py --- a/kallithea/tests/api/api_base.py +++ b/kallithea/tests/api/api_base.py @@ -135,16 +135,6 @@ class _BaseTestApi(object): given = ext_json.loads(given) assert expected == given, (expected, given) - def test_Optional_object(self): - from kallithea.controllers.api.api import Optional - - option1 = Optional(None) - assert '' % None == repr(option1) - assert option1() is None - - assert 1 == Optional.extract(Optional(1)) - assert 'trololo' == Optional.extract('trololo') - def test_api_wrong_key(self): id_, params = _build_data('trololo', 'get_user') response = api_call(self, params)