def _add_to_object_list(self, objlist, obj, objtype): """ Adds a value to a list of objects. The `obj` and any objects in the `objlist` must be instances of that type. The `objlist` may be None. If `obj` is not currently a member of the list, it is appended to the list. If it is already a member, the list returned will have the same members as the original list. :param: objlist: A list of objects, possibly None :param: obj: An object :param: objtype: The required type of the objects and the list :return: The updated list. """ validate_type(obj,objtype) found = False newlist = [] if objlist is not None: validate_list_of_type(objlist, objtype) for item in objlist: found = found or item is obj newlist.append(item) if not found: newlist.append(obj) return newlist
def _add_to_object_list(self, objlist, obj, objtype): """ Adds a value to a list of objects. The `obj` and any objects in the `objlist` must be instances of that type. The `objlist` may be None. If `obj` is not currently a member of the list, it is appended to the list. If it is already a member, the list returned will have the same members as the original list. :param: objlist: A list of objects, possibly None :param: obj: An object :param: objtype: The required type of the objects and the list :return: The updated list. """ validate_type(obj, objtype) found = False newlist = [] if objlist is not None: validate_list_of_type(objlist, objtype) for item in objlist: found = found or item is obj newlist.append(item) if not found: newlist.append(obj) return newlist
def _remove_from_object_list(self, objlist, obj, objtype): """ Removes a value from the list. The `obj` and any objects in the `objlist` must be instances of that type. The `objlist` may be None. If `obj` is currently a member of the list, it is removed. The resulting list is returned. If the resulting list is empty, None is returned. :param: objlist: A list of objects, possibly None :param: obj: An object :param: objtype: The required type of the objects and the list :return: The updated list. """ validate_type(obj,objtype) newlist = [] if objlist is not None: validate_list_of_type(objlist, objtype) for item in objlist: if item is not obj: newlist.append(item) if newlist: return newlist else: return None
def _remove_from_object_list(self, objlist, obj, objtype): """ Removes a value from the list. The `obj` and any objects in the `objlist` must be instances of that type. The `objlist` may be None. If `obj` is currently a member of the list, it is removed. The resulting list is returned. If the resulting list is empty, None is returned. :param: objlist: A list of objects, possibly None :param: obj: An object :param: objtype: The required type of the objects and the list :return: The updated list. """ validate_type(obj, objtype) newlist = [] if objlist is not None: validate_list_of_type(objlist, objtype) for item in objlist: if item is not obj: newlist.append(item) if newlist: return newlist else: return None