changeset 3606:510022f50e79

merge main
author Johannes Berg <johannes AT sipsolutions DOT net>
date Sat, 17 May 2008 11:24:15 +0200
parents d0b5d160d255 (current diff) 2cdff9dcdb1d (diff)
children 691dc24ee12e
files
diffstat 2 files changed, 13 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/action/AttachFile.py	Sat May 17 11:23:53 2008 +0200
+++ b/MoinMoin/action/AttachFile.py	Sat May 17 11:24:15 2008 +0200
@@ -172,11 +172,14 @@
 
 
 def _write_stream(content, stream, bufsize=8192):
-    if isinstance(content, str):
-        stream.write(content)
-    elif isinstance(content, file):
+    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 add_attachment(request, pagename, target, filecontent, overwrite=0):
     """ save <filecontent> to an attachment <target> of page <pagename>
@@ -626,14 +629,12 @@
     attach_dir = getAttachDir(request, pagename, create=1)
     savepath = os.path.join(attach_dir, basename + ext)
 
-    # XXX would be better if it worked without this (at least for the png),
-    # XXX but it does not:
-    filecontent = filecontent.read() # read file completely into memory
-
     if ext == '.draw':
         _addLogEntry(request, 'ATTDRW', pagename, basename + ext)
+        filecontent = filecontent.read() # read file completely into memory
         filecontent = filecontent.replace("\r", "")
     elif ext == '.map':
+        filecontent = filecontent.read() # read file completely into memory
         filecontent = filecontent.strip()
 
     if filecontent:
--- a/MoinMoin/macro/_tests/test_EmbedObject.py	Sat May 17 11:23:53 2008 +0200
+++ b/MoinMoin/macro/_tests/test_EmbedObject.py	Sat May 17 11:24:15 2008 +0200
@@ -28,11 +28,11 @@
 
         AttachFile.getAttachDir(request, pagename)
         test_files = [
-            ('test.ogg', u'vorbis'),
-            ('test.svg', u'SVG'),
-            ('test.mpg', u'MPG'),
-            ('test.pdf', u'PDF'),
-            ('test.mp3', u'MP3'),
+            ('test.ogg', str(u'vorbis')),
+            ('test.svg', str(u'SVG')),
+            ('test.mpg', str(u'MPG')),
+            ('test.pdf', str(u'PDF')),
+            ('test.mp3', str(u'MP3')),
         ]
         for filename, filecontent in test_files:
             AttachFile.add_attachment(request, pagename, filename, filecontent, overwrite=0)