summaryrefslogtreecommitdiff
path: root/src/python-systemd
diff options
context:
space:
mode:
authorSteven Hiscocks <steven@hiscocks.me.uk>2013-02-16 13:40:44 +0000
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2013-02-22 16:57:44 +0100
commitbf1ced5503bf02fa8c18f0089f4cf74a5456c3c9 (patch)
tree0a07ffcd565b6a0dda0e58174372e29180b564e2 /src/python-systemd
parent6a71de70e5f5a244b656d9ccb373cc7241033e15 (diff)
systemd-python: some python3 and bug fixes
Diffstat (limited to 'src/python-systemd')
-rw-r--r--src/python-systemd/_reader.c19
-rw-r--r--src/python-systemd/journal.py11
2 files changed, 21 insertions, 9 deletions
diff --git a/src/python-systemd/_reader.c b/src/python-systemd/_reader.c
index 06bdf1694e..ae3d77cfe9 100644
--- a/src/python-systemd/_reader.c
+++ b/src/python-systemd/_reader.c
@@ -383,7 +383,7 @@ Journal_seek(Journal *self, PyObject *args, PyObject *keywds)
&offset, &whence))
return NULL;
- PyObject *arg;
+ PyObject *result=NULL;
if (whence == SEEK_SET){
int r;
Py_BEGIN_ALLOW_THREADS
@@ -394,10 +394,10 @@ Journal_seek(Journal *self, PyObject *args, PyObject *keywds)
return NULL;
}
if (offset > 0LL) {
- Py_DECREF(PyObject_CallMethod((PyObject *)self, "get_next", "L", offset));
+ result = PyObject_CallMethod((PyObject *)self, "get_next", "L", offset);
}
}else if (whence == SEEK_CUR){
- Py_DECREF(PyObject_CallMethod((PyObject *)self, "get_next", "L", offset));
+ result = PyObject_CallMethod((PyObject *)self, "get_next", "L", offset);
}else if (whence == SEEK_END){
int r;
Py_BEGIN_ALLOW_THREADS
@@ -407,14 +407,19 @@ Journal_seek(Journal *self, PyObject *args, PyObject *keywds)
PyErr_SetString(PyExc_RuntimeError, "Error seeking to tail");
return NULL;
}
- Py_DECREF(PyObject_CallMethod((PyObject *)self, "get_next", "L", -1LL));
if (offset < 0LL) {
- Py_DECREF(PyObject_CallMethod((PyObject *)self, "get_next", "L", offset));
+ result = PyObject_CallMethod((PyObject *)self, "get_next", "L", offset);
+ }else{
+ result = PyObject_CallMethod((PyObject *)self, "get_next", "L", -1LL);
}
}else{
PyErr_SetString(PyExc_ValueError, "Invalid value for whence");
- return NULL;
}
+
+ if (result)
+ Py_DECREF(result);
+ if (PyErr_Occurred())
+ return NULL;
Py_RETURN_NONE;
}
@@ -607,7 +612,7 @@ Journal_iter(PyObject *self)
static PyObject *
Journal_iternext(PyObject *self)
{
- PyObject *dict, *arg;
+ PyObject *dict;
Py_ssize_t dict_size;
dict = PyObject_CallMethod(self, "get_next", "");
diff --git a/src/python-systemd/journal.py b/src/python-systemd/journal.py
index 533a8754a4..6e82a460b5 100644
--- a/src/python-systemd/journal.py
+++ b/src/python-systemd/journal.py
@@ -26,6 +26,8 @@ import uuid
import traceback as _traceback
import os as _os
import logging as _logging
+if sys.version_info >= (3,):
+ from collections import ChainMap
from syslog import (LOG_EMERG, LOG_ALERT, LOG_CRIT, LOG_ERR,
LOG_WARNING, LOG_NOTICE, LOG_INFO, LOG_DEBUG)
from ._journal import sendv, stream_fd
@@ -90,7 +92,7 @@ class Journal(_Journal):
def _convert_field(self, key, value):
try:
result = self.converters[key](value)
- except KeyError:
+ except:
# Default conversion in unicode
try:
result = _convert_unicode(value)
@@ -101,13 +103,18 @@ class Journal(_Journal):
def _convert_entry(self, entry):
result = {}
- for key, value in entry.iteritems():
+ for key, value in entry.items():
if isinstance(value, list):
result[key] = [self._convert_field(key, val) for val in value]
else:
result[key] = self._convert_field(key, value)
return result
+ def add_match(self, *args, **kwargs):
+ args = list(args)
+ args.extend(_make_line(key, val) for key, val in kwargs.items())
+ super(Journal, self).add_match(*args)
+
def get_next(self, *args, **kwargs):
return self._convert_entry(
super(Journal, self).get_next(*args, **kwargs))