changeset 3603:43aa566b0ec7

AttachFile: fix uploading of < 1K files (FieldStorage seems to behave different for that case)
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Sat, 17 May 2008 00:44:32 +0200
parents 3b265efc5eb2
children 2cdff9dcdb1d
files MoinMoin/action/AttachFile.py
diffstat 1 files changed, 8 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/action/AttachFile.py	Thu May 15 00:46:06 2008 +0200
+++ b/MoinMoin/action/AttachFile.py	Sat May 17 00:44:32 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: