Skip to content

Commit

Permalink
Merge pull request #233 from zopefoundation/223-use-cgi-fieldstorage
Browse files Browse the repository at this point in the history
Drop 'ZopeFieldStorage' in favor of 'cgi.FieldStorage'.
  • Loading branch information
tseaver committed Dec 5, 2017
2 parents 4669b8e + e2f83e6 commit d500cb2
Showing 1 changed file with 3 additions and 36 deletions.
39 changes: 3 additions & 36 deletions src/ZPublisher/HTTPRequest.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,12 @@
""" HTTP request management.
"""

from cgi import FieldStorage
import cgi
import codecs
import collections
from copy import deepcopy
import os
from os import unlink
from os.path import isfile
import random
import re
from tempfile import (
mkstemp,
_TemporaryFileWrapper,
)
import time

from AccessControl.tainted import TaintedString
Expand Down Expand Up @@ -511,7 +504,7 @@ def processInputs(
environ['QUERY_STRING'] = ''

meth = None
fs = ZopeFieldStorage(fp=fp, environ=environ, keep_blank_values=1)
fs = cgi.FieldStorage(fp=fp, environ=environ, keep_blank_values=1)

# Keep a reference to the FieldStorage. Otherwise it's
# __del__ method is called too early and closing FieldStorage.file.
Expand Down Expand Up @@ -1641,34 +1634,8 @@ def sane_environment(env):
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.
"""

if PY2:
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):
ZopeFieldStorage = cgi.FieldStorage # BBB

def make_file(self, binary=None):
handle, name = mkstemp()
return TemporaryFileWrapper(os.fdopen(handle, 'w+b'), name)

# Original version: zope.publisher.browser.FileUpload
class FileUpload(object):
Expand Down

0 comments on commit d500cb2

Please sign in to comment.