changeset 912:751e70074df4 storage-ng

serialization code: make it reusable
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Sat, 01 Oct 2011 17:28:45 +0200
parents 0fb6c5bfe6a8
children 10a358208aba
files MoinMoin/storage/middleware/serialization.py
diffstat 1 files changed, 12 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/storage/middleware/serialization.py	Fri Sep 30 18:41:52 2011 +0200
+++ b/MoinMoin/storage/middleware/serialization.py	Sat Oct 01 17:28:45 2011 +0200
@@ -29,10 +29,11 @@
     dst.writelines(serialize_iter(backend))
 
 
-def serialize_iter(backend):
-    for revid in backend:
-        meta, data = backend.retrieve(revid)
-
+def serialize_rev(meta, data):
+    if meta is None:
+        # this is the end!
+        yield struct.pack('!i', 0)
+    else:
         text = json.dumps(meta, ensure_ascii=False)
         meta_str = text.encode('utf-8')
         yield struct.pack('!i', len(meta_str))
@@ -42,8 +43,14 @@
             if not block:
                 break
             yield block
-    yield struct.pack('!i', 0)
 
+def serialize_iter(backend):
+    for revid in backend:
+        meta, data = backend.retrieve(revid)
+        for data in serialize_rev(meta, data):
+            yield data
+    for data in serialize_rev(None, None):
+        yield data
 
 def deserialize(src, backend):
     while True: