comparison MoinMoin/action/AttachFile.py @ 2286:01f05e74aa9c

Big PEP8 and whitespace cleanup
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Mon, 02 Jul 2007 23:33:20 +0200
parents 316bbfb37f2b
children bb76818db210 10be78f1fa97
comparison
equal deleted inserted replaced
2285:751e149a9a0a 2286:01f05e74aa9c
204 attach_dir = getAttachDir(request, pagename, create=1) 204 attach_dir = getAttachDir(request, pagename, create=1)
205 # save file 205 # save file
206 fpath = os.path.join(attach_dir, target).encode(config.charset) 206 fpath = os.path.join(attach_dir, target).encode(config.charset)
207 exists = os.path.exists(fpath) 207 exists = os.path.exists(fpath)
208 if exists and not overwrite: 208 if exists and not overwrite:
209 msg = _("Attachment '%(target)s' already exists.") % { 'target': target, } 209 msg = _("Attachment '%(target)s' already exists.") % {'target': target, }
210 else: 210 else:
211 if exists: 211 if exists:
212 try: 212 try:
213 os.remove(fpath) 213 os.remove(fpath)
214 except: 214 except:
218 stream.write(filecontent) 218 stream.write(filecontent)
219 finally: 219 finally:
220 stream.close() 220 stream.close()
221 221
222 _addLogEntry(request, 'ATTNEW', pagename, target) 222 _addLogEntry(request, 'ATTNEW', pagename, target)
223 223
224 event = FileAttachedEvent(request, pagename, target, len(filecontent)) 224 event = FileAttachedEvent(request, pagename, target, len(filecontent))
225 messages = send_event(event) 225 messages = send_event(event)
226 msg = "".join(messages) 226 msg = "".join(messages)
227 227
228 if request.cfg.xapian_search: 228 if request.cfg.xapian_search:
610 if request.user.may.read(pagename): 610 if request.user.may.read(pagename):
611 view_file(pagename, request) 611 view_file(pagename, request)
612 else: 612 else:
613 msg = _('You are not allowed to view attachments of this page.') 613 msg = _('You are not allowed to view attachments of this page.')
614 else: 614 else:
615 msg = _('Unsupported upload action: %s') % (wikiutil.escape(do),) 615 msg = _('Unsupported upload action: %s') % (wikiutil.escape(do), )
616 616
617 if msg: 617 if msg:
618 error_msg(pagename, request, msg) 618 error_msg(pagename, request, msg)
619 619
620 def upload_form(pagename, request, msg=''): 620 def upload_form(pagename, request, msg=''):
750 upload_form(pagename, request, msg=_("Attachment '%(filename)s' already exists.") % { 750 upload_form(pagename, request, msg=_("Attachment '%(filename)s' already exists.") % {
751 'filename': new_attachment}) 751 'filename': new_attachment})
752 return 752 return
753 753
754 if new_attachment_path != attachment_path: 754 if new_attachment_path != attachment_path:
755 # move file 755 # move file
756 filesys.rename(attachment_path, new_attachment_path) 756 filesys.rename(attachment_path, new_attachment_path)
757 _addLogEntry(request, 'ATTDEL', pagename, attachment) 757 _addLogEntry(request, 'ATTDEL', pagename, attachment)
758 _addLogEntry(request, 'ATTNEW', new_pagename, new_attachment) 758 _addLogEntry(request, 'ATTNEW', new_pagename, new_attachment)
759 upload_form(pagename, request, msg=_("Attachment '%(filename)s' moved to %(page)s.") % { 759 upload_form(pagename, request, msg=_("Attachment '%(filename)s' moved to %(page)s.") % {
760 'filename': new_attachment, 760 'filename': new_attachment,
999 except IOError: 999 except IOError:
1000 pass 1000 pass
1001 1001
1002 1002
1003 request.write(request.formatter.preformatted(1)) 1003 request.write(request.formatter.preformatted(1))
1004 # If we have text but no colorizing parser we try to decode file contents. 1004 # If we have text but no colorizing parser we try to decode file contents.
1005 content = open(fpath, 'r').read() 1005 content = open(fpath, 'r').read()
1006 content = wikiutil.decodeUnknownInput(content) 1006 content = wikiutil.decodeUnknownInput(content)
1007 content = wikiutil.escape(content) 1007 content = wikiutil.escape(content)
1008 request.write(request.formatter.text(content)) 1008 request.write(request.formatter.text(content))
1009 request.write(request.formatter.preformatted(0)) 1009 request.write(request.formatter.preformatted(0))
1027 from MoinMoin.action.Despam import tmp 1027 from MoinMoin.action.Despam import tmp
1028 macro = tmp() 1028 macro = tmp()
1029 macro.request = request 1029 macro.request = request
1030 macro.formatter = request.html_formatter 1030 macro.formatter = request.html_formatter
1031 1031
1032 # use EmbedObject to view valid mime types 1032 # use EmbedObject to view valid mime types
1033 from MoinMoin.macro.EmbedObject import EmbedObject 1033 from MoinMoin.macro.EmbedObject import EmbedObject
1034 if mt is None: 1034 if mt is None:
1035 request.write('<p>' + _("Unknown file type, cannot display this attachment inline.") + '</p>') 1035 request.write('<p>' + _("Unknown file type, cannot display this attachment inline.") + '</p>')
1036 request.write('For using an external program follow this link <a href="%s">%s</a>' % ( 1036 request.write('For using an external program follow this link <a href="%s">%s</a>' % (
1037 getAttachUrl(pagename, filename, request, escaped=1), wikiutil.escape(filename))) 1037 getAttachUrl(pagename, filename, request, escaped=1), wikiutil.escape(filename)))