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

Steven Hiscocks steven-systemd at hiscocks.me.uk
Sun May 12 05:03:46 PDT 2013


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).

I wasn't sure on the correct approach to fix this:
- Should `_get_cursor` return bytes, like the non-special fields?
- Or should it continue to return string (as it is special, and 
__{REALTIME,MONOTONIC}_TIMESTAMP fields don't return bytes) and 
therefore the DEFAULT_CONVERTERS be updated to handle this?
- One more complex option is making _convert_field aware of the special 
fields, and if no entry exists in the converters, simply just returns 
the value rather than attempting Unicode decode? This would handle the 
case where some one sets the converters to `{}`.
> +                return self._convert_entry(entry)
> +        return dict()
> +

-- 
Steven Hiscocks


More information about the systemd-devel mailing list