Exemple #1
0
/*	Set new unique item at `i` index in LDAPValueList to `newitem`. Case-insensitive,
	the `newitem` is also appended to the added list, or remove from the deleted list.
	Same goes for the replaced item.
*/
int
LDAPValueList_SetItem(LDAPValueList *self, Py_ssize_t i, PyObject *newitem) {
	int rc = -1;
	PyObject *olditem;

	if (UniqueList_SetItem((UniqueList *)self, i, newitem) != 0) return -1;

	olditem = PyList_GetItem((PyObject *)self, i);
	if (olditem == NULL) return -1;
	rc = UniqueList_Remove_wFlg(self->added, olditem);
	if (rc == -1) return -1;
	if (rc == 0) {
		if (UniqueList_Append(self->deleted, olditem) == -1) {
			PyErr_BadInternalCall();
			return -1;
		}
	}

	rc = UniqueList_Remove_wFlg(self->deleted, newitem);
	if (rc == -1) return -1;
	if (rc == 0) {
		if (UniqueList_Append(self->added, newitem) == -1) {
			PyErr_BadInternalCall();
			return -1;
		}
	}
	return 0;
}
Exemple #2
0
/*	Removes the same items from both list. */
static int
balancing(PyObject *l1, UniqueList *l2) {
	int rc;
	Py_ssize_t i;

	for (i = 0; i < Py_SIZE(l2); i++) {
		rc = UniqueList_Remove_wFlg((UniqueList *)l1, l2->list.ob_item[i]);
		if (rc == 1) {
			UniqueList_SetSlice(l2, i, i+1, (PyObject *)NULL);
		} else if (rc == -1) return -1;
	}
	return 0;
}
Exemple #3
0
int
UniqueList_Remove(UniqueList *self, PyObject *value) {
	int rc;

	rc = UniqueList_Remove_wFlg(self, value);
	if (rc == 0) {
		PyErr_SetString(PyExc_ValueError, "LDAPListValue.remove(x): x not in list");
		return -1;
	} else if (rc == 1) {
		return 0;
	}
	return -1;
}
Exemple #4
0
/*	Insert new unique item to the `where` position in LDAPValueList. Case-insensitive,
	the `newitem` is also appended to the added list, or remove from the deleted list.
*/
int
LDAPValueList_Insert(LDAPValueList *self, Py_ssize_t where, PyObject *newitem) {
	int rc = -1;

	rc = UniqueList_Remove_wFlg(self->deleted, newitem);
	if (rc == -1) return -1;
	if (rc == 0) {
		if (UniqueList_Append(self->added, newitem) == -1) {
			PyErr_BadInternalCall();
			return -1;
		}
	}
    return UniqueList_Insert((UniqueList *)self, where, newitem);
}