Commit 8d180d87 authored by Jérome Perrin's avatar Jérome Perrin Committed by Arnaud Fontaine

XMLExportImport: close files to fix ResourceWarning

parent 1f51e4c6
...@@ -132,6 +132,8 @@ class TrashTool(BaseTool): ...@@ -132,6 +132,8 @@ class TrashTool(BaseTool):
LOG("Trash Tool backupObject", WARNING, LOG("Trash Tool backupObject", WARNING,
"Can't backup object %s" % object_path) "Can't backup object %s" % object_path)
return {} return {}
finally:
copy.close()
subobjects_dict = {} subobjects_dict = {}
......
...@@ -411,10 +411,12 @@ def save_record(parser, tag, data): ...@@ -411,10 +411,12 @@ def save_record(parser, tag, data):
import xml.parsers.expat import xml.parsers.expat
def importXML(jar, file, clue=''): def importXML(jar, file, clue=''):
if type(file) is str: if isinstance(file, str):
file=open(file, 'rb') with open(file, 'rb') as f:
outfile=TemporaryFile() data = f.read()
data=file.read() else:
data = file.read()
with TemporaryFile() as outfile:
F=ppml.xmlPickler() F=ppml.xmlPickler()
F.end_handlers['record'] = save_record F.end_handlers['record'] = save_record
F.end_handlers['ZopeData'] = save_zopedata F.end_handlers['ZopeData'] = save_zopedata
...@@ -434,7 +436,7 @@ def importXML(jar, file, clue=''): ...@@ -434,7 +436,7 @@ def importXML(jar, file, clue=''):
p.EndElementHandler=F.unknown_endtag p.EndElementHandler=F.unknown_endtag
r=p.Parse(data) r=p.Parse(data)
outfile.seek(0) outfile.seek(0)
return jar.importFile(outfile,clue) return jar.importFile(outfile, clue)
customImporters = { customImporters = {
magic: importXML magic: importXML
......
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