summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSteven Hiscocks <steven@hiscocks.me.uk>2013-02-08 22:04:42 +0000
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2013-02-22 16:57:43 +0100
commit2d0603bd976978a62165c79129fc3a1f8d36b9e6 (patch)
tree9ad4deeee1a7f0b6150508ca59f7f05c18c012d7 /src
parentc4e9b5b557ba956e316933c31bbefa8b48fa3f93 (diff)
systemd-python: moved PyRun_String to journal.py code
Diffstat (limited to 'src')
-rw-r--r--src/python-systemd/_reader.c55
-rw-r--r--src/python-systemd/journal.py48
2 files changed, 50 insertions, 53 deletions
diff --git a/src/python-systemd/_reader.c b/src/python-systemd/_reader.c
index 963da11dc6..69c6d02a9e 100644
--- a/src/python-systemd/_reader.c
+++ b/src/python-systemd/_reader.c
@@ -46,57 +46,8 @@ Journal_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
self = (Journal *)type->tp_alloc(type, 0);
if (self != NULL) {
- PyObject *globals, *temp;
-
- globals = PyEval_GetBuiltins();
- temp = PyImport_ImportModule("functools");
- PyDict_SetItemString(globals, "functools", temp);
- Py_DECREF(temp);
- temp = PyImport_ImportModule("datetime");
- PyDict_SetItemString(globals, "datetime", temp);
- Py_DECREF(temp);
-
-#if PY_MAJOR_VERSION >=3
- self->default_call = PyRun_String("functools.partial(str, encoding='utf-8')", Py_eval_input, globals, NULL);
-#else
- self->default_call = PyRun_String("functools.partial(unicode, encoding='utf-8')", Py_eval_input, globals, NULL);
-#endif
-
- self->call_dict = PyRun_String("{"
- "'PRIORITY': int,"
- "'LEADER': int,"
- "'SESSION_ID': int,"
- "'USERSPACE_USEC': int,"
- "'INITRD_USEC': int,"
- "'KERNEL_USEC': int,"
- "'_UID': int,"
- "'_GID': int,"
- "'_PID': int,"
- "'SYSLOG_FACILITY': int,"
- "'SYSLOG_PID': int,"
- "'_AUDIT_SESSION': int,"
- "'_AUDIT_LOGINUID': int,"
- "'_SYSTEMD_SESSION': int,"
- "'_SYSTEMD_OWNER_UID': int,"
- "'CODE_LINE': int,"
- "'ERRNO': int,"
- "'EXIT_STATUS': int,"
- "'_SOURCE_REALTIME_TIMESTAMP': lambda x: datetime.datetime.fromtimestamp(float(x)/1E6),"
- "'__REALTIME_TIMESTAMP': lambda x: datetime.datetime.fromtimestamp(float(x)/1E6),"
- "'_SOURCE_MONOTONIC_TIMESTAMP': lambda x: datetime.timedelta(microseconds=float(x)),"
- "'__MONOTONIC_TIMESTAMP': lambda x: datetime.timedelta(microseconds=float(x)),"
-#if PY_MAJOR_VERSION >=3
- "'COREDUMP': bytes,"
-#else
- "'COREDUMP': str,"
-#endif
- "'COREDUMP_PID': int,"
- "'COREDUMP_UID': int,"
- "'COREDUMP_GID': int,"
- "'COREDUMP_SESSION': int,"
- "'COREDUMP_SIGNAL': int,"
- "'COREDUMP_TIMESTAMP': lambda x: datetime.datetime.fromtimestamp(float(x)/1E6),"
- "}", Py_eval_input, globals, NULL);
+ self->call_dict = PyDict_New();
+ self->default_call = Py_None;
}
return (PyObject *) self;
@@ -1149,7 +1100,7 @@ init_reader(void)
#endif
Py_INCREF(&JournalType);
- PyModule_AddObject(m, "Journal", (PyObject *)&JournalType);
+ PyModule_AddObject(m, "_Journal", (PyObject *)&JournalType);
PyModule_AddIntConstant(m, "NOP", SD_JOURNAL_NOP);
PyModule_AddIntConstant(m, "APPEND", SD_JOURNAL_APPEND);
PyModule_AddIntConstant(m, "INVALIDATE", SD_JOURNAL_INVALIDATE);
diff --git a/src/python-systemd/journal.py b/src/python-systemd/journal.py
index a1543b884e..1f0aafc7fe 100644
--- a/src/python-systemd/journal.py
+++ b/src/python-systemd/journal.py
@@ -19,15 +19,61 @@
# You should have received a copy of the GNU Lesser General Public License
# along with systemd; If not, see <http://www.gnu.org/licenses/>.
+import datetime
+import functools
+import sys
import traceback as _traceback
import os as _os
import logging as _logging
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
-from ._reader import (Journal, NOP, APPEND, INVALIDATE,
+from ._reader import (_Journal, NOP, APPEND, INVALIDATE,
LOCAL_ONLY, RUNTIME_ONLY, SYSTEM_ONLY)
+class Journal(_Journal):
+ def __new__(cls, *args, **kwargs):
+ self = _Journal.__new__(cls, *args, **kwargs)
+ if sys.version_info[0] >= 3:
+ self.default_call = functools.partial(str, encoding='utf-8')
+ else:
+ self.default_call = functools.partial(unicode, encoding='utf-8')
+ self.call_dict = {
+ 'PRIORITY': int,
+ 'LEADER': int,
+ 'SESSION_ID': int,
+ 'USERSPACE_USEC': int,
+ 'INITRD_USEC': int,
+ 'KERNEL_USEC': int,
+ '_UID': int,
+ '_GID': int,
+ '_PID': int,
+ 'SYSLOG_FACILITY': int,
+ 'SYSLOG_PID': int,
+ '_AUDIT_SESSION': int,
+ '_AUDIT_LOGINUID': int,
+ '_SYSTEMD_SESSION': int,
+ '_SYSTEMD_OWNER_UID': int,
+ 'CODE_LINE': int,
+ 'ERRNO': int,
+ 'EXIT_STATUS': int,
+ '_SOURCE_REALTIME_TIMESTAMP': lambda x: datetime.datetime.fromtimestamp(float(x)/1E6),
+ '__REALTIME_TIMESTAMP': lambda x: datetime.datetime.fromtimestamp(float(x)/1E6),
+ '_SOURCE_MONOTONIC_TIMESTAMP': lambda x: datetime.timedelta(microseconds=float(x)),
+ '__MONOTONIC_TIMESTAMP': lambda x: datetime.timedelta(microseconds=float(x)),
+ 'COREDUMP_PID': int,
+ 'COREDUMP_UID': int,
+ 'COREDUMP_GID': int,
+ 'COREDUMP_SESSION': int,
+ 'COREDUMP_SIGNAL': int,
+ 'COREDUMP_TIMESTAMP': lambda x: datetime.datetime.fromtimestamp(float(x)/1E6),
+ }
+ if sys.version_info[0] >= 3:
+ self.call_dict['COREDUMP'] = bytes
+ else:
+ self.call_dict['COREDUMP'] = str
+ return self
+
def _make_line(field, value):
if isinstance(value, bytes):
return field.encode('utf-8') + b'=' + value