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
138
Merge Requests
138
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
3751a82b
Commit
3751a82b
authored
Mar 09, 2024
by
Jérome Perrin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
XMLExportImport: close files to fix ResourceWarning
parent
701e3d89
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
30 additions
and
25 deletions
+30
-25
product/ERP5/Tool/TrashTool.py
product/ERP5/Tool/TrashTool.py
+2
-0
product/ERP5/tests/utils.py
product/ERP5/tests/utils.py
+2
-1
product/ERP5Type/XMLExportImport/__init__.py
product/ERP5Type/XMLExportImport/__init__.py
+26
-24
No files found.
product/ERP5/Tool/TrashTool.py
View file @
3751a82b
...
@@ -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
=
{}
...
...
product/ERP5/tests/utils.py
View file @
3751a82b
...
@@ -186,4 +186,5 @@ class BusinessTemplateInfoDir(BusinessTemplateInfoBase):
...
@@ -186,4 +186,5 @@ class BusinessTemplateInfoDir(BusinessTemplateInfoBase):
return
fileinfo
return
fileinfo
def
readFileInfo
(
self
,
fileinfo
):
def
readFileInfo
(
self
,
fileinfo
):
return
open
(
fileinfo
).
read
()
with
open
(
fileinfo
)
as
f
:
return
f
.
read
()
product/ERP5Type/XMLExportImport/__init__.py
View file @
3751a82b
...
@@ -411,30 +411,32 @@ def save_record(parser, tag, data):
...
@@ -411,30 +411,32 @@ 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
:
F
=
ppml
.
xmlPickler
()
data
=
file
.
read
()
F
.
end_handlers
[
'record'
]
=
save_record
with
TemporaryFile
()
as
outfile
:
F
.
end_handlers
[
'ZopeData'
]
=
save_zopedata
F
=
ppml
.
xmlPickler
()
F
.
start_handlers
[
'ZopeData'
]
=
start_zopedata
F
.
end_handlers
[
'record'
]
=
save_record
F
.
binary
=
1
F
.
end_handlers
[
'ZopeData'
]
=
save_zopedata
F
.
file
=
outfile
F
.
start_handlers
[
'ZopeData'
]
=
start_zopedata
# <patch>
F
.
binary
=
1
# Our BTs XML files don't declare encoding but have accented chars in them
F
.
file
=
outfile
# So we have to declare an encoding but not use unicode, so the unpickler
# <patch>
# can deal with the utf-8 strings directly
# Our BTs XML files don't declare encoding but have accented chars in them
p
=
xml
.
parsers
.
expat
.
ParserCreate
(
'utf-8'
)
# So we have to declare an encoding but not use unicode, so the unpickler
if
six
.
PY2
:
# can deal with the utf-8 strings directly
p
.
returns_unicode
=
False
p
=
xml
.
parsers
.
expat
.
ParserCreate
(
'utf-8'
)
# </patch>
if
six
.
PY2
:
p
.
CharacterDataHandler
=
F
.
handle_data
p
.
returns_unicode
=
False
p
.
StartElementHandler
=
F
.
unknown_starttag
# </patch>
p
.
EndElementHandler
=
F
.
unknown_endtag
p
.
CharacterDataHandler
=
F
.
handle_data
r
=
p
.
Parse
(
data
)
p
.
StartElementHandler
=
F
.
unknown_starttag
outfile
.
seek
(
0
)
p
.
EndElementHandler
=
F
.
unknown_endtag
return
jar
.
importFile
(
outfile
,
clue
)
r
=
p
.
Parse
(
data
)
outfile
.
seek
(
0
)
return
jar
.
importFile
(
outfile
,
clue
)
customImporters
=
{
customImporters
=
{
magic
:
importXML
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