summaryrefslogtreecommitdiff
path: root/src/if_py_both.h
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2012-09-21 14:00:35 +0200
committerBram Moolenaar <Bram@vim.org>2012-09-21 14:00:35 +0200
commit66b7985ec9e4924abc370636077ed33114d0327d (patch)
treed3fc6e02af7989af008caade8eff1eb53e5ad52c /src/if_py_both.h
parent770456589e5e53507fcd32013a190b520f4fc688 (diff)
downloadvim-66b7985ec9e4924abc370636077ed33114d0327d.zip
updated for version 7.3.672
Problem: Not possible to lock/unlock lists in Python interface. Solution: Add .locked and .scope attributes. (ZyX)
Diffstat (limited to 'src/if_py_both.h')
-rw-r--r--src/if_py_both.h76
1 files changed, 76 insertions, 0 deletions
diff --git a/src/if_py_both.h b/src/if_py_both.h
index 0909981c2..0a1ef1b9e 100644
--- a/src/if_py_both.h
+++ b/src/if_py_both.h
@@ -808,6 +808,44 @@ pymap_to_tv(PyObject *obj, typval_T *tv, PyObject *lookupDict)
}
static PyInt
+DictionarySetattr(DictionaryObject *self, char *name, PyObject *val)
+{
+ if (val == NULL)
+ {
+ PyErr_SetString(PyExc_AttributeError, _("Cannot delete DictionaryObject attributes"));
+ return -1;
+ }
+
+ if (strcmp(name, "locked") == 0)
+ {
+ if (self->dict->dv_lock == VAR_FIXED)
+ {
+ PyErr_SetString(PyExc_TypeError, _("Cannot modify fixed dictionary"));
+ return -1;
+ }
+ else
+ {
+ if (!PyBool_Check(val))
+ {
+ PyErr_SetString(PyExc_TypeError, _("Only boolean objects are allowed"));
+ return -1;
+ }
+
+ if (val == Py_True)
+ self->dict->dv_lock = VAR_LOCKED;
+ else
+ self->dict->dv_lock = 0;
+ }
+ return 0;
+ }
+ else
+ {
+ PyErr_SetString(PyExc_AttributeError, _("Cannot set this attribute"));
+ return -1;
+ }
+}
+
+ static PyInt
DictionaryLength(PyObject *self)
{
return ((PyInt) ((((DictionaryObject *)(self))->dict->dv_hashtab.ht_used)));
@@ -1271,6 +1309,44 @@ ListConcatInPlace(PyObject *self, PyObject *obj)
return self;
}
+ static int
+ListSetattr(ListObject *self, char *name, PyObject *val)
+{
+ if (val == NULL)
+ {
+ PyErr_SetString(PyExc_AttributeError, _("Cannot delete DictionaryObject attributes"));
+ return -1;
+ }
+
+ if (strcmp(name, "locked") == 0)
+ {
+ if (self->list->lv_lock == VAR_FIXED)
+ {
+ PyErr_SetString(PyExc_TypeError, _("Cannot modify fixed list"));
+ return -1;
+ }
+ else
+ {
+ if (!PyBool_Check(val))
+ {
+ PyErr_SetString(PyExc_TypeError, _("Only boolean objects are allowed"));
+ return -1;
+ }
+
+ if (val == Py_True)
+ self->list->lv_lock = VAR_LOCKED;
+ else
+ self->list->lv_lock = 0;
+ }
+ return 0;
+ }
+ else
+ {
+ PyErr_SetString(PyExc_AttributeError, _("Cannot set this attribute"));
+ return -1;
+ }
+}
+
static struct PyMethodDef ListMethods[] = {
{"extend", (PyCFunction)ListConcatInPlace, METH_O, ""},
{ NULL, NULL, 0, NULL }