Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
mat2
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
tails
mat2
Commits
9e7a4bd2
Commit
9e7a4bd2
authored
6 years ago
by
Julien (jvoisin) Voisin
Browse files
Options
Downloads
Patches
Plain Diff
Implement support in `get_meta` for deep meta in office-related files
parent
27beda35
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/office.py
+27
-4
27 additions, 4 deletions
src/office.py
with
27 additions
and
4 deletions
src/office.py
+
27
−
4
View file @
9e7a4bd2
...
...
@@ -4,6 +4,7 @@ import re
import
shutil
import
subprocess
import
tempfile
import
datetime
import
zipfile
from
.
import
abstract
,
parser_factory
...
...
@@ -16,6 +17,25 @@ class ArchiveBasedAbstractParser(abstract.AbstractParser):
zipinfo
.
date_time
=
(
1980
,
1
,
1
,
0
,
0
,
0
)
return
zipinfo
def
_get_zipinfo_meta
(
self
,
zipinfo
:
zipfile
.
ZipInfo
)
->
dict
:
metadata
=
{}
if
zipinfo
.
create_system
==
3
:
#metadata['create_system'] = 'Linux'
pass
elif
zipinfo
.
create_system
==
2
:
metadata
[
'
create_system
'
]
=
'
Windows
'
else
:
metadata
[
'
create_system
'
]
=
'
Weird
'
if
zipinfo
.
comment
:
metadata
[
'
comment
'
]
=
zipinfo
.
comment
if
zipinfo
.
date_time
!=
(
1980
,
1
,
1
,
0
,
0
,
0
):
metadata
[
'
comment
'
]
=
datetime
.
datetime
(
*
zipinfo
.
date_time
)
return
metadata
def
_clean_internal_file
(
self
,
item
:
zipfile
.
ZipInfo
,
temp_folder
:
str
,
zin
:
zipfile
.
ZipFile
,
zout
:
zipfile
.
ZipFile
):
zin
.
extract
(
member
=
item
,
path
=
temp_folder
)
tmp_parser
=
parser_factory
.
get_parser
(
os
.
path
.
join
(
temp_folder
,
item
.
filename
))
...
...
@@ -43,13 +63,15 @@ class MSOfficeParser(ArchiveBasedAbstractParser):
"""
metadata
=
{}
zipin
=
zipfile
.
ZipFile
(
self
.
filename
)
for
item
in
zipin
.
name
list
():
if
item
.
startswith
(
'
docProps/
'
)
and
item
.
endswith
(
'
.xml
'
):
for
item
in
zipin
.
info
list
():
if
item
.
filename
.
startswith
(
'
docProps/
'
)
and
item
.
filename
.
endswith
(
'
.xml
'
):
content
=
zipin
.
read
(
item
).
decode
(
'
utf-8
'
)
for
(
key
,
value
)
in
re
.
findall
(
r
"
<(.+)>(.+)</\1>
"
,
content
,
re
.
I
):
metadata
[
key
]
=
value
if
not
metadata
:
# better safe than sorry
metadata
[
item
]
=
'
harmful content
'
metadata
=
{
**
metadata
,
**
self
.
_get_zipinfo_meta
(
item
)}
zipin
.
close
()
return
metadata
...
...
@@ -95,13 +117,14 @@ class LibreOfficeParser(ArchiveBasedAbstractParser):
"""
metadata
=
{}
zipin
=
zipfile
.
ZipFile
(
self
.
filename
)
for
item
in
zipin
.
name
list
():
if
item
==
'
meta.xml
'
:
for
item
in
zipin
.
info
list
():
if
item
.
filename
==
'
meta.xml
'
:
content
=
zipin
.
read
(
item
).
decode
(
'
utf-8
'
)
for
(
key
,
value
)
in
re
.
findall
(
r
"
<((?:meta|dc|cp).+?)>(.+)</\1>
"
,
content
,
re
.
I
):
metadata
[
key
]
=
value
if
not
metadata
:
# better safe than sorry
metadata
[
item
]
=
'
harmful content
'
metadata
=
{
**
metadata
,
**
self
.
_get_zipinfo_meta
(
item
)}
zipin
.
close
()
return
metadata
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment