comparison MoinMoin/action/AttachFile.py @ 3706:f0532fa90c6d

AttachFile action: catch runtime error raised by zipfile when trying to view a defective zip
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Thu, 12 Jun 2008 21:57:20 +0200
parents ac48fad2e117
children ce632fad1b03
comparison
equal deleted inserted replaced
3705:ac48fad2e117 3706:f0532fa90c6d
983 content = wikiutil.escape(content) 983 content = wikiutil.escape(content)
984 request.write(request.formatter.text(content)) 984 request.write(request.formatter.text(content))
985 request.write(request.formatter.preformatted(0)) 985 request.write(request.formatter.preformatted(0))
986 return 986 return
987 987
988 package = packages.ZipPackage(request, fpath) 988 try:
989 if package.isPackage(): 989 package = packages.ZipPackage(request, fpath)
990 request.write("<pre><b>%s</b>\n%s</pre>" % (_("Package script:"), wikiutil.escape(package.getScript()))) 990 if package.isPackage():
991 return 991 request.write("<pre><b>%s</b>\n%s</pre>" % (_("Package script:"), wikiutil.escape(package.getScript())))
992 992 return
993 if zipfile.is_zipfile(fpath) and mt.minor == 'zip': 993
994 zf = zipfile.ZipFile(fpath, mode='r') 994 if zipfile.is_zipfile(fpath) and mt.minor == 'zip':
995 request.write("<pre>%-46s %19s %12s\n" % (_("File Name"), _("Modified")+" "*5, _("Size"))) 995 zf = zipfile.ZipFile(fpath, mode='r')
996 for zinfo in zf.filelist: 996 request.write("<pre>%-46s %19s %12s\n" % (_("File Name"), _("Modified")+" "*5, _("Size")))
997 date = "%d-%02d-%02d %02d:%02d:%02d" % zinfo.date_time 997 for zinfo in zf.filelist:
998 request.write(wikiutil.escape("%-46s %s %12d\n" % (zinfo.filename, date, zinfo.file_size))) 998 date = "%d-%02d-%02d %02d:%02d:%02d" % zinfo.date_time
999 request.write("</pre>") 999 request.write(wikiutil.escape("%-46s %s %12d\n" % (zinfo.filename, date, zinfo.file_size)))
1000 request.write("</pre>")
1001 return
1002 except RuntimeError:
1003 # We don't want to crash with a traceback here (an exception
1004 # here could be caused by an uploaded defective zip file - and
1005 # if we crash here, the user does not get a UI to remove the
1006 # defective zip file again).
1007 # RuntimeError is raised by zipfile stdlib module in case of
1008 # problems (like inconsistent slash and backslash usage in the
1009 # archive).
1010 logging.exception("An exception within zip file attachment handling occurred:")
1000 return 1011 return
1001 1012
1002 from MoinMoin import macro 1013 from MoinMoin import macro
1003 from MoinMoin.parser.text import Parser 1014 from MoinMoin.parser.text import Parser
1004 1015