<p dir="ltr">Oh, okay. Sounds good.</p>
<div class="gmail_quote">On Apr 15, 2013 12:28 AM, "Steven Hiscocks" <<a href="mailto:steven-systemd@hiscocks.me.uk">steven-systemd@hiscocks.me.uk</a>> wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
On 15/04/13 04:05, David Strauss wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Maybe I'm missing something in the Gist patch, but won't<br>
Reader.get('__REALTIME_<u></u>TIMESTAMP') fail with "field name is not<br>
valid"?<br>
<br>
</blockquote>
You're right, but `get` is changed to `_get`, so is "private". Use `get_next` and `get_previous` does on the traversal and getting of both special and standard fields to simplify use of the Reader.<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
On Sun, Apr 14, 2013 at 10:49 AM, Zbigniew Jędrzejewski-Szmek<br>
<<a href="mailto:zbyszek@in.waw.pl" target="_blank">zbyszek@in.waw.pl</a>> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
On Sun, Apr 14, 2013 at 03:28:31PM +0100, Steven Hiscocks wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
On 14/04/13 03:36, David Strauss wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
I keep writing lengthy emails about how we can use this as an<br>
opportunity to reduce redundancy and improve consistency, but I should<br>
probably ping you on #systemd IRC to hash it out. I can't think of<br>
anything elegant that doesn't involve altering the existing journal.py<br>
or _reader.c code.<br>
</blockquote></blockquote>
Hi Steven, hi David,<br>
<br>
I read your discussion on IRC... I agree that backwards compatibility<br>
is not (yet) something that we need to keep very. I think that the<br>
number of people using those Python interfaces is quite small so far,<br>
and having a nice interface is more important than some small breakage.<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
As a starter, I want to enumerate the places where<br>
__REALTIME_TIMESTAMP has special handling:<br>
  (1) Existing code: A C-based member function in _reader.c.<br>
  (2) Existing code: A native Python conversion function in journal.py.<br>
  (3) Existing code: An entry in DEFAULT_CONVERTERS.<br>
  (4) Added in your patch: A key setting in get_next().<br>
  (5) Added in your patch: A Python-based member function in journal.py<br>
that overrides (1).<br>
  (6) Added in your patch: A condition in get() that invokes (1) when<br>
the specific field is requested.<br>
<br>
While I want to fix this bug, I also don't want six scattered special<br>
cases for __REALTIME_TIMESTAMP and similar fields.<br>
<br>
</blockquote>
<br>
Thanks for the chat earlier on IRC David, especially given your<br>
localtime :-).<br>
<br>
I thought about the points discussed: keeping things similar to<br>
journalctl -o json output (i.e. include special fields); get,<br>
get_next, and get_realtime, etc methods create duplication and<br>
multiple ways to get the same/some values (could cause confusion);<br>
issue with `next` clashing with python2 __iter__ next; trying to<br>
stabilise the interface (note: not declared stable yet); performance<br>
issues with unnecessary dictionary field conversions.<br>
<br>
I've therefore created another patch for consideration:<br>
<a href="https://gist.github.com/kwirk/5382783" target="_blank">https://gist.github.com/kwirk/<u></u>5382783</a><br>
</blockquote>
This looks pretty nice, and I think it can be committed. Could<br>
you create a patch with a commit message, including some of the<br>
rationale, so that people understand what's happenning? ;)<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
I've removed the get_next and get_previous methods from _Reader, as<br>
these didn't align with the C API. This is replaced with:`_get_all`<br>
private method (effectively a wrapper around C API macro<br>
sd_journal_{enumerate,restart}<u></u>_data/SD_JOURNAL_FOREACH_DATA)<u></u>;<br>
renamed `next` method to `_next`, such to avoid name clash (and I<br>
believe should be private); `_previous` method for consistency.<br>
<br>
The `get_next` and `get_previous` methods are now in Reader only.<br>
These call `_next` method, followed by `_get_all` and then fetch the<br>
special fields, before passing whole dictionary to converters. This<br>
makes all the traversal, and getting standard and special fields<br>
from the journal transparent to the user.<br>
<br>
With the changes of removing `get_next` in _Reader, the iter methods<br>
don't function as you'd expect. To that end, I've moved them to<br>
Reader with get_next as iter next call as before.<br>
<br>
I understand the points about performance, but don't think the<br>
performance hit is that bad, or critical in most use cases. These<br>
changes should allow a custom class to inherit _Reader, and the<br>
create a more optimised version if that is required. (One option if<br>
this is a major issue, is a custom dictionary class could be<br>
returned by `get_next`, which uses the __get__ method to lazy<br>
convert the fields on access. This is starting to get complicated<br>
thought...)<br>
</blockquote>
I think we can always do that later on. Maybe it makes sense<br>
to document that get_next() returns something dictionary-like<br>
(collections.abc.Mapping) that right now is just a dict, but<br>
could become something different later on.<br>
<br>
Zbyszek<br>
</blockquote>
<br>
<br>
<br>
</blockquote>
<br>
<br>
-- <br>
Steven Hiscocks<br>
</blockquote></div>