+PyDoc_STRVAR(Reader_get_catalog__doc__,
+ "get_catalog() -> str\n\n"
+ "Retrieve a message catalog entry for the current journal entry.\n"
+ "Will throw IndexError if the entry has no MESSAGE_ID\n"
+ "and KeyError is the id is specified, but hasn't been found\n"
+ "in the catalog.\n\n"
+ "Wraps man:sd_journal_get_catalog(3).");
+static PyObject* Reader_get_catalog(Reader *self, PyObject *args) {
+ int r;
+ _cleanup_free_ char *msg = NULL;
+
+ assert(self);
+ assert(!args);
+
+ Py_BEGIN_ALLOW_THREADS
+ r = sd_journal_get_catalog(self->j, &msg);
+ Py_END_ALLOW_THREADS
+
+ if (r == -ENOENT) {
+ const void* mid;
+ size_t mid_len;
+
+ r = sd_journal_get_data(self->j, "MESSAGE_ID", &mid, &mid_len);
+ if (r == 0) {
+ const size_t l = sizeof("MESSAGE_ID");
+ assert(mid_len > l);
+ PyErr_Format(PyExc_KeyError, "%.*s", (int) (mid_len - l),
+ (const char*) mid + l);
+ } else if (r == -ENOENT)
+ PyErr_SetString(PyExc_IndexError, "no MESSAGE_ID field");
+ else
+ set_error(r, NULL, NULL);
+ return NULL;
+ }
+
+ if (set_error(r, NULL, NULL) < 0)
+ return NULL;
+
+ return unicode_FromString(msg);
+}
+
+PyDoc_STRVAR(get_catalog__doc__,
+ "get_catalog(id128) -> str\n\n"
+ "Retrieve a message catalog entry for the given id.\n"
+ "Wraps man:sd_journal_get_catalog_for_message_id(3).");
+static PyObject* get_catalog(PyObject *self, PyObject *args) {
+ int r;
+ char *id_ = NULL;
+ sd_id128_t id;
+ _cleanup_free_ char *msg = NULL;
+
+ assert(args);
+
+ if (!PyArg_ParseTuple(args, "z:get_catalog", &id_))
+ return NULL;
+
+ r = sd_id128_from_string(id_, &id);
+ if (set_error(r, NULL, "Invalid id128") < 0)
+ return NULL;
+
+ Py_BEGIN_ALLOW_THREADS
+ r = sd_journal_get_catalog_for_message_id(id, &msg);
+ Py_END_ALLOW_THREADS
+
+ if (set_error(r, NULL, NULL) < 0)
+ return NULL;
+
+ return unicode_FromString(msg);
+}
+
+PyDoc_STRVAR(data_threshold__doc__,
+ "Threshold for field size truncation in bytes.\n\n"
+ "Fields longer than this will be truncated to the threshold size.\n"
+ "Defaults to 64Kb.");
+
+static PyObject* Reader_get_data_threshold(Reader *self, void *closure) {
+ size_t cvalue;
+ int r;
+
+ r = sd_journal_get_data_threshold(self->j, &cvalue);
+ if (set_error(r, NULL, NULL) < 0)
+ return NULL;
+
+ return long_FromSize_t(cvalue);
+}
+
+static int Reader_set_data_threshold(Reader *self, PyObject *value, void *closure) {
+ int r;
+
+ if (value == NULL) {
+ PyErr_SetString(PyExc_AttributeError, "Cannot delete data threshold");
+ return -1;
+ }
+
+ if (!long_Check(value)){
+ PyErr_SetString(PyExc_TypeError, "Data threshold must be an int");
+ return -1;
+ }
+
+ r = sd_journal_set_data_threshold(self->j, (size_t) long_AsLong(value));
+ return set_error(r, NULL, NULL);
+}
+
+PyDoc_STRVAR(closed__doc__,
+ "True iff journal is closed");
+static PyObject* Reader_get_closed(Reader *self, void *closure) {
+ return PyBool_FromLong(self->j == NULL);
+}
+
+static PyGetSetDef Reader_getsetters[] = {
+ { (char*) "data_threshold",
+ (getter) Reader_get_data_threshold,
+ (setter) Reader_set_data_threshold,
+ (char*) data_threshold__doc__,
+ NULL },
+ { (char*) "closed",
+ (getter) Reader_get_closed,
+ NULL,
+ (char*) closed__doc__,
+ NULL },
+ {} /* Sentinel */
+};
+
+static PyMethodDef Reader_methods[] = {
+ {"fileno", (PyCFunction) Reader_fileno, METH_NOARGS, Reader_fileno__doc__},
+ {"reliable_fd", (PyCFunction) Reader_reliable_fd, METH_NOARGS, Reader_reliable_fd__doc__},
+ {"get_events", (PyCFunction) Reader_get_events, METH_NOARGS, Reader_get_events__doc__},
+ {"get_timeout", (PyCFunction) Reader_get_timeout, METH_NOARGS, Reader_get_timeout__doc__},
+ {"get_timeout_ms", (PyCFunction) Reader_get_timeout_ms, METH_NOARGS, Reader_get_timeout_ms__doc__},
+ {"close", (PyCFunction) Reader_close, METH_NOARGS, Reader_close__doc__},
+ {"get_usage", (PyCFunction) Reader_get_usage, METH_NOARGS, Reader_get_usage__doc__},
+ {"__enter__", (PyCFunction) Reader___enter__, METH_NOARGS, Reader___enter____doc__},
+ {"__exit__", (PyCFunction) Reader___exit__, METH_VARARGS, Reader___exit____doc__},
+ {"_next", (PyCFunction) Reader_next, METH_VARARGS, Reader_next__doc__},
+ {"_previous", (PyCFunction) Reader_previous, METH_VARARGS, Reader_previous__doc__},
+ {"_get", (PyCFunction) Reader_get, METH_VARARGS, Reader_get__doc__},
+ {"_get_all", (PyCFunction) Reader_get_all, METH_NOARGS, Reader_get_all__doc__},
+ {"_get_realtime", (PyCFunction) Reader_get_realtime, METH_NOARGS, Reader_get_realtime__doc__},
+ {"_get_monotonic", (PyCFunction) Reader_get_monotonic, METH_NOARGS, Reader_get_monotonic__doc__},
+ {"add_match", (PyCFunction) Reader_add_match, METH_VARARGS|METH_KEYWORDS, Reader_add_match__doc__},
+ {"add_disjunction", (PyCFunction) Reader_add_disjunction, METH_NOARGS, Reader_add_disjunction__doc__},
+ {"add_conjunction", (PyCFunction) Reader_add_conjunction, METH_NOARGS, Reader_add_conjunction__doc__},
+ {"flush_matches", (PyCFunction) Reader_flush_matches, METH_NOARGS, Reader_flush_matches__doc__},
+ {"seek_head", (PyCFunction) Reader_seek_head, METH_NOARGS, Reader_seek_head__doc__},
+ {"seek_tail", (PyCFunction) Reader_seek_tail, METH_NOARGS, Reader_seek_tail__doc__},
+ {"seek_realtime", (PyCFunction) Reader_seek_realtime, METH_VARARGS, Reader_seek_realtime__doc__},
+ {"seek_monotonic", (PyCFunction) Reader_seek_monotonic, METH_VARARGS, Reader_seek_monotonic__doc__},
+ {"process", (PyCFunction) Reader_process, METH_NOARGS, Reader_process__doc__},
+ {"wait", (PyCFunction) Reader_wait, METH_VARARGS, Reader_wait__doc__},
+ {"seek_cursor", (PyCFunction) Reader_seek_cursor, METH_VARARGS, Reader_seek_cursor__doc__},
+ {"_get_cursor", (PyCFunction) Reader_get_cursor, METH_NOARGS, Reader_get_cursor__doc__},
+ {"test_cursor", (PyCFunction) Reader_test_cursor, METH_VARARGS, Reader_test_cursor__doc__},
+ {"query_unique", (PyCFunction) Reader_query_unique, METH_VARARGS, Reader_query_unique__doc__},
+ {"get_catalog", (PyCFunction) Reader_get_catalog, METH_NOARGS, Reader_get_catalog__doc__},
+ {} /* Sentinel */