chiark / gitweb /
systemd-python: fix iteration
[elogind.git] / src / python-systemd / journal.py
index 9ef1ede229e8f9b695f252e97cbe726fe50d278a..adcc844f465abbb837b39d7e1e996ffc216bdfce 100644 (file)
@@ -55,6 +55,9 @@ def _convert_realtime(t):
 def _convert_timestamp(s):
     return _datetime.datetime.fromtimestamp(int(s) / 1000000)
 
+def _convert_trivial(x):
+    return x
+
 if _sys.version_info >= (3,):
     def _convert_uuid(s):
         return _uuid.UUID(s.decode())
@@ -87,6 +90,7 @@ DEFAULT_CONVERTERS = {
     '__REALTIME_TIMESTAMP': _convert_realtime,
     '_SOURCE_MONOTONIC_TIMESTAMP': _convert_source_monotonic,
     '__MONOTONIC_TIMESTAMP': _convert_monotonic,
+    '__CURSOR': _convert_trivial,
     'COREDUMP': bytes,
     'COREDUMP_PID': int,
     'COREDUMP_UID': int,
@@ -187,18 +191,18 @@ class Reader(_Reader):
         """
         return self
 
-    if _sys.version_info >= (3,):
-        def __next__(self):
-            """Part of iterator protocol.
-            Returns self.get_next().
-            """
-            return self.get_next()
-    else:
-        def next(self):
-            """Part of iterator protocol.
-            Returns self.get_next().
-            """
-            return self.get_next()
+    def __next__(self):
+        """Part of iterator protocol.
+        Returns self.get_next() or raises StopIteration.
+        """
+        ans = self.get_next()
+        if ans:
+            return ans
+        else:
+            raise StopIteration()
+
+    if _sys.version_info < (3,):
+        next = __next__
 
     def add_match(self, *args, **kwargs):
         """Add one or more matches to the filter journal log entries.