changeset 204:af274db0ed53

items: move duplicated code to function conv_serialize
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Sat, 30 Apr 2011 16:55:44 +0200
parents 1d416427b7be
children 57078169052b
files MoinMoin/items/__init__.py
diffstat 1 files changed, 17 insertions(+), 22 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/items/__init__.py	Sat Apr 30 16:39:48 2011 +0200
+++ b/MoinMoin/items/__init__.py	Sat Apr 30 16:55:44 2011 +0200
@@ -20,6 +20,7 @@
 import zipfile
 import tempfile
 from StringIO import StringIO
+from array import array
 
 from MoinMoin.security.textcha import TextCha, TextChaizedForm, TextChaValid
 from MoinMoin.util.forms import make_generator
@@ -68,6 +69,15 @@
 ROWS_META = 10
 
 
+def conv_serialize(doc, namespaces):
+    out = array('u')
+    flaskg.clock.start('conv_serialize')
+    doc.write(out.fromunicode, namespaces=namespaces, method='xml')
+    out = out.tounicode()
+    flaskg.clock.stop('conv_serialize')
+    return out
+
+
 class DummyRev(dict):
     """ if we have no stored Revision, we use this dummy """
     def __init__(self, item, mimetype):
@@ -234,27 +244,15 @@
         flaskg.clock.start('conv_dom_html')
         doc = html_conv(doc)
         flaskg.clock.stop('conv_dom_html')
-
-        from array import array
-        out = array('u')
-        flaskg.clock.start('conv_serialize')
-        doc.write(out.fromunicode, namespaces={html.namespace: ''}, method='xml')
-        out = out.tounicode()
-        flaskg.clock.stop('conv_serialize')
-        return out
+        return conv_serialize(doc, {html.namespace: ''})
 
     def _render_data_xml(self):
         doc = self.internal_representation()
-
-        from array import array
-        out = array('u')
-        doc.write(out.fromunicode,
-                  namespaces={moin_page.namespace: '',
-                              xlink.namespace: 'xlink',
-                              html.namespace: 'html',
-                             },
-                  method='xml')
-        return out.tounicode()
+        return conv_serialize(doc,
+                              {moin_page.namespace: '',
+                               xlink.namespace: 'xlink',
+                               html.namespace: 'html',
+                              })
 
     def _render_data_highlight(self):
         # override this in child classes
@@ -1042,10 +1040,7 @@
         # TODO: Real output format
         html_conv = reg.get(type_moin_document, Type('application/x-xhtml-moin-page'))
         doc = html_conv(doc)
-        from array import array
-        out = array('u')
-        doc.write(out.fromunicode, namespaces={html.namespace: ''}, method='xml')
-        return out.tounicode()
+        return conv_serialize(doc, {html.namespace: ''})
 
     def do_modify(self, template_name):
         form = TextChaizedForm.from_defaults()