Commit c5cbdc1e authored by Hugo H. Maia Vieira's avatar Hugo H. Maia Vieira

Trash method implemented to close files

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk/utils@41174 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 6840aa16
......@@ -153,7 +153,12 @@ class OdfDocument(object):
data -- Content of the document
source_format -- Document Extension
"""
self._zipfile = ZipFile(StringIO(data))
data_file = StringIO(data)
try:
self._zipfile = ZipFile(data_file)
finally:
data_file.close()
self.source_format = source_format
# XXX - Maybe parsed_content should not be here, but on OOGranulate
self.parsed_content = etree.fromstring(self.getContentXml())
......@@ -168,3 +173,7 @@ class OdfDocument(object):
return self._zipfile.read(path)
except KeyError:
return ''
def trash(self):
"""Remove the file in memory."""
self._zipfile.close()
......@@ -89,3 +89,7 @@ class OOGranulate(object):
def getChapterItem(self, file, chapter_id):
"""Return the chapter in the form of (title, level)."""
raise NotImplementedError
def trash(self):
"""Remove the file in memory."""
self.document.trash()
......@@ -80,14 +80,16 @@ class Manager(object):
file = self.convertFile(file, source_format,
GRANULATABLE_FORMAT_LIST[0], zip=False)
from granulate.oogranulate import OOGranulate
document = OOGranulate(decodestring(file),
source_format)
grain = document.granulate(zip)
try:
document = OOGranulate(decodestring(file), source_format)
grain = document.granulate(zip)
if zip:
return encodestring(grain)
return map(encodestring, grain)
finally:
document.trash()
return None
def updateFileMetadata(self, file, source_format, metadata_dict):
"""Receives the string of document and a dict with metadatas. The metadata
......
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