Skip to content

Commit

Permalink
Merge pull request #643 from Morg42/develop
Browse files Browse the repository at this point in the history
lib.item: remove old list/dict methods
  • Loading branch information
Morg42 authored Mar 9, 2024
2 parents f18c147 + 61e2253 commit b058142
Showing 1 changed file with 0 additions and 105 deletions.
105 changes: 0 additions & 105 deletions lib/item/item.py
Original file line number Diff line number Diff line change
Expand Up @@ -1505,111 +1505,6 @@ def _build_trigger_condition_eval(self, trigger_condition):

return result

#
# drop-in functions for list/dict handling
#
# these mimic list/dict modification functions by wrapping around __call__
#
# on item type initialization, only the "matching" method can be inserted
# into the item instance as methods with their respective "original" names,
# i.e. Item.__list__append becomes Item.append
#
# To keep some compatibility, all methods support optional caller, source and
# dest arguments, which are directly passed to __call__
#
# these don't provide error handling as no sensible result would be possible.
# As in using "raw" lists/dicts, errors must be handles by the caller
# (logic, eval, console, ...)
#

# list functions

def __list_append(self, value, caller='Logic', source=None, dest=None):
self.__call__(value, caller, source, dest, index='append')

def __list_prepend(self, value, caller='Logic', source=None, dest=None):
self.__call__(value, caller, source, dest, index='prepend')

def __list_insert(self, index, value, caller='Logic', source=None, dest=None):
tmplist = copy.deepcopy(self._value)
tmplist.insert(index, value)
self.__call__(tmplist, caller, source, dest)

def __list_pop(self, index=None, caller='Logic', source=None, dest=None):
tmplist = copy.deepcopy(self._value)
if index is None:
ret = tmplist.pop()
else:
ret = tmplist.pop(index)
self.__call__(tmplist, caller, source, dest)
return ret

def __list_extend(self, value, caller='Logic', source=None, dest=None):
tmplist = copy.deepcopy(self._value)
tmplist.extend(value)
self.__call__(tmplist, caller, source, dest)

def __list_clear(self, caller='Logic', source=None, dest=None):
self.__call__([], caller, source, dest)

def __list_delete(self, value, caller='Logic', source=None, dest=None):
"""
mimic the del list[x:y] behaviour - supply "x:y" as value
needs to be called delete instead of del for syntax reasons
"""
splits = str(value).count(':')
tmplist = copy.deepcopy(self._value)
if splits == 0:
x = int(value)
del tmplist[x]
if splits == 1:
x, y = [int(i) for i in value.split(':')]
del tmplist[x:y]
elif splits == 2:
x, y, z = [int(i) for i in value.split(':')]
del tmplist[x:y:z]
self.__call__(tmplist, caller, source, dest)

def __list_remove(self, value, caller='Logic', source=None, dest=None):
tmplist = copy.deepcopy(self._value)
tmplist.remove(value)
self.__call__(tmplist, caller, source, dest)

# dict functions

def get(self, key, caller='Logic', source=None, dest=None, default=None):
return self.__call__(key=key, default=default, caller=caller, source=source, dest=dest)

def delete(self, key, caller='Logic', source=None, dest=None):
""" needs to be called delete instead of del for syntax reasons """
tmpdict = copy.deepcopy(self._value)
del tmpdict[key]
self.__call__(tmpdict, caller, source, dest)

def clear(self, caller='Logic', source=None, dest=None):
self.__call__({}, caller, source, dest)

def pop(self, key, caller='Logic', source=None, dest=None, default=None):
tmpdict = copy.deepcopy(self._value)
ret = tmpdict.pop(key, default)
self.__call__(tmpdict, caller, source, dest)
return ret

def popitem(self, caller='Logic', source=None, dest=None):
tmpdict = copy.deepcopy(self._value)
ret = tmpdict.popitem()
self.__call__(tmpdict, caller, source, dest)
return ret

def update(self, value, caller='Logic', source=None, dest=None):
tmpdict = copy.deepcopy(self._value)
tmpdict.update(value)
self.__call__(tmpdict, caller, source, dest)

#
#
#

def __call__(self, value=None, caller='Logic', source=None, dest=None, key=None, index=None, default=None):
# return value
if value is None or self._type is None:
Expand Down

0 comments on commit b058142

Please sign in to comment.