Commit 4d5910f3 authored by Hanno Schlichting's avatar Hanno Schlichting

Add better blob support to HTTPRequest.ZopeFieldStorage.

parent e575c54b
...@@ -14,6 +14,8 @@ Bugs Fixed ...@@ -14,6 +14,8 @@ Bugs Fixed
Features Added Features Added
++++++++++++++ ++++++++++++++
- Add better blob support to HTTPRequest.ZopeFieldStorage.
Restructuring Restructuring
+++++++++++++ +++++++++++++
......
...@@ -19,10 +19,15 @@ from cgi import FieldStorage ...@@ -19,10 +19,15 @@ from cgi import FieldStorage
import codecs import codecs
from copy import deepcopy from copy import deepcopy
import os import os
from os import unlink
from os.path import isfile
import random import random
import re import re
import sys import sys
import tempfile from tempfile import (
mkstemp,
_TemporaryFileWrapper,
)
import time import time
from urllib import unquote from urllib import unquote
from urllib import splittype from urllib import splittype
...@@ -1601,10 +1606,33 @@ def sane_environment(env): ...@@ -1601,10 +1606,33 @@ def sane_environment(env):
return dict return dict
class TemporaryFileWrapper(_TemporaryFileWrapper):
"""
Variant of tempfile._TemporaryFileWrapper that doesn't rely on the
automatic Windows behavior of deleting closed files, which even
happens, when the file has been moved -- e.g. to the blob storage,
and doesn't complain about such a move either.
"""
unlink = staticmethod(unlink)
isfile = staticmethod(isfile)
def close(self):
if not self.close_called:
self.close_called = True
self.file.close()
def __del__(self):
self.close()
if self.isfile(self.name):
self.unlink(self.name)
class ZopeFieldStorage(FieldStorage): class ZopeFieldStorage(FieldStorage):
def make_file(self, binary=None): def make_file(self, binary=None):
return tempfile.NamedTemporaryFile("w+b") handle, name = mkstemp()
return TemporaryFileWrapper(os.fdopen(handle, 'w+b'), name)
# Original version: zope.publisher.browser.FileUpload # Original version: zope.publisher.browser.FileUpload
...@@ -1648,7 +1676,7 @@ class FileUpload: ...@@ -1648,7 +1676,7 @@ class FileUpload:
# self.headers so that managed code can access them. # self.headers so that managed code can access them.
try: try:
self.headers.__allow_access_to_unprotected_subobjects__ = 1 self.headers.__allow_access_to_unprotected_subobjects__ = 1
except: except Exception:
pass pass
def __nonzero__(self): def __nonzero__(self):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment