Change read and list to return None if key/dir doesn't exist.

Signed-off-by: Christian Limpach <Christian.Limpach@cl.cam.ac.uk>
This commit is contained in:
cl349@firebug.cl.cam.ac.uk committed 2005-09-13 14:45:34 +00:00
1 parent 2f8a6789d2
commit 8e04472036
1 file changed
+14 -3
+14 -3
View File
@@ -74,6 +74,7 @@ static inline PyObject *pyvalue_str(char *val) {
" path [string]: xenstore path\n" \
"\n" \
"Returns: [string] data read.\n" \
" None if key doesn't exist.\n" \
"Raises RuntimeError on error.\n" \
"\n"
@@ -97,7 +98,11 @@ static PyObject *xspy_read(PyObject *self, PyObject *args, PyObject *kwds)
xsval = xs_read(xh, path, &xsval_n);
Py_END_ALLOW_THREADS
if (!xsval) {
PyErr_SetFromErrno(PyExc_RuntimeError);
if (errno == ENOENT) {
Py_INCREF(Py_None);
val = Py_None;
} else
PyErr_SetFromErrno(PyExc_RuntimeError);
goto exit;
}
val = PyString_FromStringAndSize(xsval, xsval_n);
@@ -160,6 +165,7 @@ static PyObject *xspy_write(PyObject *self, PyObject *args, PyObject *kwds)
" path [string]: path to list.\n" \
"\n" \
"Returns: [string array] list of subdirectory names.\n" \
" None if key doesn't exist.\n" \
"Raises RuntimeError on error.\n" \
"\n"
@@ -183,12 +189,17 @@ static PyObject *xspy_ls(PyObject *self, PyObject *args, PyObject *kwds)
xsval = xs_directory(xh, path, &xsval_n);
Py_END_ALLOW_THREADS
if (!xsval) {
PyErr_SetFromErrno(PyExc_RuntimeError);
goto exit;
if (errno == ENOENT) {
Py_INCREF(Py_None);
val = Py_None;
} else
PyErr_SetFromErrno(PyExc_RuntimeError);
goto exit;
}
val = PyList_New(xsval_n);
for (i = 0; i < xsval_n; i++)
PyList_SetItem(val, i, PyString_FromString(xsval[i]));
free(xsval);
exit:
return val;
}
Reference in new issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.