Commit 2a5f5ed5 authored by Bryton Lacquement's avatar Bryton Lacquement 🚪

IntrospectionTool: fix

parent ae7db4ae
...@@ -39,7 +39,8 @@ from Products.ERP5Type import Permissions ...@@ -39,7 +39,8 @@ from Products.ERP5Type import Permissions
from AccessControl.SecurityManagement import setSecurityManager from AccessControl.SecurityManagement import setSecurityManager
from Products.ERP5 import _dtmldir from Products.ERP5 import _dtmldir
from Products.ERP5.Tool.LogMixin import LogMixin from Products.ERP5.Tool.LogMixin import LogMixin
from Products.ERP5Type.Utils import _setSuperSecurityManager from Products.ERP5Type.Utils import \
_setSuperSecurityManager, FileAsStreamIterator
from App.config import getConfiguration from App.config import getConfiguration
from AccessControl import Unauthorized from AccessControl import Unauthorized
from Products.ERP5Type.Cache import CachingMethod from Products.ERP5Type.Cache import CachingMethod
...@@ -155,16 +156,9 @@ class IntrospectionTool(LogMixin, BaseTool): ...@@ -155,16 +156,9 @@ class IntrospectionTool(LogMixin, BaseTool):
tmp_file_path = file_path tmp_file_path = file_path
r = FileAsStreamIterator(tmp_file_path, remove_file=compressed)
with open(tmp_file_path) as f: RESPONSE.setHeader('Content-Length', str(len(r)))
RESPONSE.setHeader('Content-Length', os.stat(tmp_file_path).st_size) return r
for data in f:
RESPONSE.write(data)
if compressed:
os.remove(tmp_file_path)
return ''
def __getEventLogPath(self): def __getEventLogPath(self):
""" """
......
...@@ -1819,3 +1819,25 @@ class IterableAsStreamIterator: ...@@ -1819,3 +1819,25 @@ class IterableAsStreamIterator:
for chunk in self.iterable: for chunk in self.iterable:
return chunk return chunk
raise StopIteration raise StopIteration
@implementer(IStreamIterator)
class FileAsStreamIterator:
def __init__(self, file_path, remove_file=False):
self.file = open(file_path)
self.size = os.stat(tmp_file_path).st_size
self.remove_file = remove_file
def __iter__(self):
return self
def __len__(self):
return self.size
def next(self):
for data in self.file:
return data
self.file.close()
if self.remove_file:
os.remove(self.file)
raise StopIteration
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