Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
erp5
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Labels
Merge Requests
139
Merge Requests
139
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Jobs
Commits
Open sidebar
nexedi
erp5
Commits
56b4bd7d
Commit
56b4bd7d
authored
Mar 09, 2024
by
Jérome Perrin
Committed by
Arnaud Fontaine
Jul 04, 2024
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
XMLExportImport: close files to fix ResourceWarning
parent
245ed5b2
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
28 additions
and
24 deletions
+28
-24
product/ERP5/Tool/TrashTool.py
product/ERP5/Tool/TrashTool.py
+2
-0
product/ERP5Type/XMLExportImport/__init__.py
product/ERP5Type/XMLExportImport/__init__.py
+26
-24
No files found.
product/ERP5/Tool/TrashTool.py
View file @
56b4bd7d
...
...
@@ -132,6 +132,8 @@ class TrashTool(BaseTool):
LOG
(
"Trash Tool backupObject"
,
WARNING
,
"Can't backup object %s"
%
object_path
)
return
{}
finally
:
copy
.
close
()
subobjects_dict
=
{}
...
...
product/ERP5Type/XMLExportImport/__init__.py
View file @
56b4bd7d
...
...
@@ -411,30 +411,32 @@ def save_record(parser, tag, data):
import
xml.parsers.expat
def
importXML
(
jar
,
file
,
clue
=
''
):
if
type
(
file
)
is
str
:
file
=
open
(
file
,
'rb'
)
outfile
=
TemporaryFile
()
data
=
file
.
read
()
F
=
ppml
.
xmlPickler
()
F
.
end_handlers
[
'record'
]
=
save_record
F
.
end_handlers
[
'ZopeData'
]
=
save_zopedata
F
.
start_handlers
[
'ZopeData'
]
=
start_zopedata
F
.
binary
=
1
F
.
file
=
outfile
# <patch>
# Our BTs XML files don't declare encoding but have accented chars in them
# So we have to declare an encoding but not use unicode, so the unpickler
# can deal with the utf-8 strings directly
p
=
xml
.
parsers
.
expat
.
ParserCreate
(
'utf-8'
)
if
six
.
PY2
:
p
.
returns_unicode
=
False
# </patch>
p
.
CharacterDataHandler
=
F
.
handle_data
p
.
StartElementHandler
=
F
.
unknown_starttag
p
.
EndElementHandler
=
F
.
unknown_endtag
r
=
p
.
Parse
(
data
)
outfile
.
seek
(
0
)
return
jar
.
importFile
(
outfile
,
clue
)
if
isinstance
(
file
,
str
):
with
open
(
file
,
'rb'
)
as
f
:
data
=
f
.
read
()
else
:
data
=
file
.
read
()
with
TemporaryFile
()
as
outfile
:
F
=
ppml
.
xmlPickler
()
F
.
end_handlers
[
'record'
]
=
save_record
F
.
end_handlers
[
'ZopeData'
]
=
save_zopedata
F
.
start_handlers
[
'ZopeData'
]
=
start_zopedata
F
.
binary
=
1
F
.
file
=
outfile
# <patch>
# Our BTs XML files don't declare encoding but have accented chars in them
# So we have to declare an encoding but not use unicode, so the unpickler
# can deal with the utf-8 strings directly
p
=
xml
.
parsers
.
expat
.
ParserCreate
(
'utf-8'
)
if
six
.
PY2
:
p
.
returns_unicode
=
False
# </patch>
p
.
CharacterDataHandler
=
F
.
handle_data
p
.
StartElementHandler
=
F
.
unknown_starttag
p
.
EndElementHandler
=
F
.
unknown_endtag
r
=
p
.
Parse
(
data
)
outfile
.
seek
(
0
)
return
jar
.
importFile
(
outfile
,
clue
)
customImporters
=
{
magic
:
importXML
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment