[systemd-devel] [PATCH] python-systemd: Reader return special fields and _Reader changes

Zbigniew Jędrzejewski-Szmek zbyszek at in.waw.pl
Wed May 15 21:47:03 PDT 2013


On Sun, May 12, 2013 at 01:03:46PM +0100, Steven Hiscocks wrote:
> On 14/04/13 20:55, Steven Hiscocks wrote:
> >      def get_next(self, skip=1):
> >-        """Return the next log entry as a dictionary of fields.
> >+        """Return the next log entry as a mapping type, currently
> >+        a standard dictionary of fields.
> >
> >          Optional skip value will return the `skip`\-th log entry.
> >
> >          Entries will be processed with converters specified during
> >          Reader creation.
> >          """
> >-        return self._convert_entry(
> >-            super(Reader, self).get_next(skip))
> >+        if super(Reader, self)._next(skip):
> >+            entry = super(Reader, self)._get_all()
> >+            if entry:
> >+                entry['__REALTIME_TIMESTAMP'] =  self._get_realtime()
> >+                entry['__MONOTONIC_TIMESTAMP']  = self._get_monotonic()
> >+                entry['__CURSOR']  = self._get_cursor()
> I've picked up on a bug here in python3, `_get_cursor` returns a
> string, which then gets passed to the default bytes->string
> conversion in `_convert_field` which in turn throws a TypeError. It
> can be worked around by adding "__CUSROR" entry to converters, with
> suitable conversion (direct return or str).
Good catch. I think that adding __CURSOR to converters is the
best approach, because we really know that the string is a valid
string (it is generated in a simple way by journal code, so we know
that it'll always be plain ASCII). This way we also preserve
symmetry, because seek_cursor accepts a string.
I'm pushing a patch adding an entry to converters.

Zbyszek


More information about the systemd-devel mailing list