summaryrefslogtreecommitdiff
path: root/src/python-systemd/_reader.c
diff options
context:
space:
mode:
authorSteven Hiscocks <steven@hiscocks.me.uk>2013-02-16 17:31:18 +0000
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2013-02-22 16:57:44 +0100
commit7a1b9cd5e43c85a3b1f22a0151ac5b6340fb0d0f (patch)
treed74b8099de190ff6f7e98e769923fc69b4e0b19a /src/python-systemd/_reader.c
parent71766afa2d80ffe1b03c410f6d5ffdc140883314 (diff)
systemd-python: Moved _reader datetime usage to python
Diffstat (limited to 'src/python-systemd/_reader.c')
-rw-r--r--src/python-systemd/_reader.c52
1 files changed, 8 insertions, 44 deletions
diff --git a/src/python-systemd/_reader.c b/src/python-systemd/_reader.c
index 5d743eb562..f1c3175bbf 100644
--- a/src/python-systemd/_reader.c
+++ b/src/python-systemd/_reader.c
@@ -426,34 +426,12 @@ PyDoc_STRVAR(Journal_seek_realtime__doc__,
static PyObject *
Journal_seek_realtime(Journal *self, PyObject *args)
{
- PyObject *arg;
- if (! PyArg_ParseTuple(args, "O", &arg))
+ uint64_t timestamp;
+ if (! PyArg_ParseTuple(args, "K", &timestamp))
return NULL;
- uint64_t timestamp=-1LL;
- if (PyDateTime_Check(arg)) {
- PyObject *temp;
- char *timestamp_str;
- temp = PyObject_CallMethod(arg, "strftime", "s", "%s%f");
-#if PY_MAJOR_VERSION >=3
- PyObject *temp2;
- temp2 = PyUnicode_AsUTF8String(temp);
- timestamp_str = PyBytes_AsString(temp2);
- Py_DECREF(temp2);
-#else
- timestamp_str = PyString_AsString(temp);
-#endif
- Py_DECREF(temp);
- timestamp = strtoull(timestamp_str, NULL, 10);
- }else if (PyLong_Check(arg)) {
- timestamp = PyLong_AsUnsignedLongLong(arg);
-#if PY_MAJOR_VERSION <3
- }else if (PyInt_Check(arg)) {
- timestamp = PyInt_AsUnsignedLongLongMask(arg);
-#endif
- }
if ((int64_t) timestamp < 0LL) {
- PyErr_SetString(PyExc_ValueError, "Time must be positive integer or datetime instance");
+ PyErr_SetString(PyExc_ValueError, "Time must be positive integer");
return NULL;
}
@@ -479,30 +457,16 @@ PyDoc_STRVAR(Journal_seek_monotonic__doc__,
static PyObject *
Journal_seek_monotonic(Journal *self, PyObject *args)
{
- PyObject *arg;
+ double timedouble;
char *bootid=NULL;
- if (! PyArg_ParseTuple(args, "O|s", &arg, &bootid))
+ if (! PyArg_ParseTuple(args, "d|z", &timedouble, &bootid))
return NULL;
- uint64_t timestamp=-1LL;
- if PyDelta_Check(arg) {
- PyObject *temp;
- temp = PyObject_CallMethod(arg, "total_seconds", NULL);
- timestamp = (uint64_t) (PyFloat_AsDouble(temp) * 1E6);
- Py_DECREF(temp);
- }else if (PyFloat_Check(arg)) {
- timestamp = (uint64_t) (PyFloat_AsDouble(arg) * 1E6);
- }else if (PyLong_Check(arg)) {
- timestamp = PyLong_AsUnsignedLongLong(arg) * (uint64_t) 1E6;
-#if PY_MAJOR_VERSION <3
- }else if (PyInt_Check(arg)) {
- timestamp = PyInt_AsUnsignedLongLongMask(arg) * (uint64_t) 1E6;
-#endif
-
- }
+ uint64_t timestamp;
+ timestamp = (uint64_t) (timedouble * 1.0E6);
if ((int64_t) timestamp < 0LL) {
- PyErr_SetString(PyExc_ValueError, "Time must be positive number or timedelta instance");
+ PyErr_SetString(PyExc_ValueError, "Time must be positive number");
return NULL;
}