changeset 5103:6c620a7e2def

anywikidraw/twikidraw action: reduce code duplication, cosmetic changes
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Sun, 13 Sep 2009 16:33:27 +0200
parents 9ae242080889
children b631aca46a48
files MoinMoin/action/anywikidraw.py MoinMoin/action/twikidraw.py
diffstat 2 files changed, 6 insertions(+), 20 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/action/anywikidraw.py	Sun Sep 13 16:01:09 2009 +0200
+++ b/MoinMoin/action/anywikidraw.py	Sun Sep 13 16:33:27 2009 +0200
@@ -19,19 +19,11 @@
 
 from MoinMoin import config, wikiutil
 from MoinMoin.action import AttachFile, do_show
+from MoinMoin.action.AttachFile import _write_stream
 from MoinMoin.Page import Page
 
 action_name = __name__.split('.')[-1]
 
-def _write_stream(content, stream, bufsize=8192):
-    if hasattr(content, 'read'): # looks file-like
-        import shutil
-        shutil.copyfileobj(content, stream, bufsize)
-    elif isinstance(content, str):
-        stream.write(content)
-    else:
-        logging.error("unsupported content object: %r" % content)
-        raise
 
 def gedit_drawing(self, url, text, **kw):
     # This is called for displaying a drawing image by gui editor.
@@ -54,6 +46,7 @@
     kw['src'] = ci.member_url('drawing.png')
     return self.image(**kw)
 
+
 def attachment_drawing(self, url, text, **kw):
     # This is called for displaying a clickable drawing image by text_html formatter.
     # XXX text arg is unused!
@@ -102,6 +95,7 @@
             kw['alt'] = kw['title']
         return self.url(1, drawing_url) + self.image(**kw) + self.url(0)
 
+
 class AnyWikiDraw(object):
     """ anywikidraw action """
     def __init__(self, request, pagename, target):
@@ -214,6 +208,7 @@
         request.theme.send_footer(pagename)
         request.theme.send_closing_html()
 
+
 def execute(pagename, request):
     _ = request.getText
     msg = None
--- a/MoinMoin/action/twikidraw.py	Sun Sep 13 16:01:09 2009 +0200
+++ b/MoinMoin/action/twikidraw.py	Sun Sep 13 16:33:27 2009 +0200
@@ -19,22 +19,13 @@
 
 from MoinMoin import wikiutil, config
 from MoinMoin.action import AttachFile, do_show
+from MoinMoin.action.AttachFile import _write_stream
 from MoinMoin.Page import Page
 from MoinMoin.security.textcha import TextCha
 
 action_name = __name__.split('.')[-1]
 
 
-def _write_stream(content, stream, bufsize=8192):
-    if hasattr(content, 'read'): # looks file-like
-        import shutil
-        shutil.copyfileobj(content, stream, bufsize)
-    elif isinstance(content, str):
-        stream.write(content)
-    else:
-        logging.error("unsupported content object: %r" % content)
-        raise
-
 def gedit_drawing(self, url, text, **kw):
     # This is called for displaying a drawing image by gui editor.
     _ = self.request.getText
@@ -56,6 +47,7 @@
     kw['src'] = ci.member_url('drawing.png')
     return self.image(**kw)
 
+
 def attachment_drawing(self, url, text, **kw):
     # This is called for displaying a clickable drawing image by text_html formatter.
     # XXX text arg is unused!
@@ -239,4 +231,3 @@
 
     TwikiDraw(request, pagename, target).render()
 
-