Mercurial > moin > 1.9
comparison MoinMoin/action/AttachFile.py @ 4432:253a1e691b19
fix saving of drawings to use WSGI/werkzeug API correctly
author | Thomas Waldmann <tw AT waldmann-edv DOT de> |
---|---|
date | Mon, 24 Nov 2008 00:24:45 +0100 |
parents | 8982d8226218 |
children | a499a137ecf5 |
comparison
equal
deleted
inserted
replaced
4431:436048b821a5 | 4432:253a1e691b19 |
---|---|
586 _ = request.getText | 586 _ = request.getText |
587 | 587 |
588 if not request.user.may.write(pagename): | 588 if not request.user.may.write(pagename): |
589 return _('You are not allowed to save a drawing on this page.') | 589 return _('You are not allowed to save a drawing on this page.') |
590 | 590 |
591 file_upload = request.files.get('filepath') | |
592 if not file_upload: | |
593 # This might happen when trying to upload file names | |
594 # with non-ascii characters on Safari. | |
595 return _("No file content. Delete non ASCII characters from the file name and try again.") | |
596 | |
591 filename = request.form['filename'] | 597 filename = request.form['filename'] |
592 filecontent = request.form['filepath'] | |
593 | 598 |
594 basepath, basename = os.path.split(filename) | 599 basepath, basename = os.path.split(filename) |
595 basename, ext = os.path.splitext(basename) | 600 basename, ext = os.path.splitext(basename) |
596 | 601 |
597 # get directory, and possibly create it | 602 # get directory, and possibly create it |
598 attach_dir = getAttachDir(request, pagename, create=1) | 603 attach_dir = getAttachDir(request, pagename, create=1) |
599 savepath = os.path.join(attach_dir, basename + ext) | 604 savepath = os.path.join(attach_dir, basename + ext) |
600 | 605 |
601 if ext == '.draw': | 606 if ext == '.draw': |
602 _addLogEntry(request, 'ATTDRW', pagename, basename + ext) | 607 _addLogEntry(request, 'ATTDRW', pagename, basename + ext) |
603 filecontent = filecontent.read() # read file completely into memory | 608 filecontent = file_upload.stream.read() # read file completely into memory |
604 filecontent = filecontent.replace("\r", "") | 609 filecontent = filecontent.replace("\r", "") |
605 elif ext == '.map': | 610 elif ext == '.map': |
606 filecontent = filecontent.read() # read file completely into memory | 611 filecontent = file_upload.stream.read() # read file completely into memory |
607 filecontent = filecontent.strip() | 612 filecontent = filecontent.strip() |
608 | 613 |
609 if filecontent: | 614 if filecontent: |
610 # filecontent is either a file or a non-empty string | 615 # filecontent is either a file or a non-empty string |
611 stream = open(savepath, 'wb') | 616 stream = open(savepath, 'wb') |