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
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Monitor
Service Desk
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
jvoisin
mat2
Commits
b832a594
Commit
b832a594
authored
6 years ago
by
Julien (jvoisin) Voisin
Browse files
Options
Downloads
Patches
Plain Diff
Refactor lightweight mode implementation
parent
6ce88b8b
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
libmat2/abstract.py
+1
-7
1 addition, 7 deletions
libmat2/abstract.py
libmat2/pdf.py
+7
-2
7 additions, 2 deletions
libmat2/pdf.py
mat2
+1
-2
1 addition, 2 deletions
mat2
tests/test_libmat2.py
+4
-2
4 additions, 2 deletions
tests/test_libmat2.py
with
13 additions
and
13 deletions
libmat2/abstract.py
+
1
−
7
View file @
b832a594
...
...
@@ -19,6 +19,7 @@ class AbstractParser(abc.ABC):
self
.
filename
=
filename
fname
,
extension
=
os
.
path
.
splitext
(
filename
)
self
.
output_filename
=
fname
+
'
.cleaned
'
+
extension
self
.
lightweight_cleaning
=
False
@abc.abstractmethod
def
get_meta
(
self
)
->
Dict
[
str
,
str
]:
...
...
@@ -27,10 +28,3 @@ class AbstractParser(abc.ABC):
@abc.abstractmethod
def
remove_all
(
self
)
->
bool
:
pass
# pragma: no cover
def
remove_all_lightweight
(
self
)
->
bool
:
"""
This method removes _SOME_ metadata.
It might be useful to implement it for fileformats that do
not support non-destructive cleaning.
"""
return
self
.
remove_all
()
This diff is collapsed.
Click to expand it.
libmat2/pdf.py
+
7
−
2
View file @
b832a594
...
...
@@ -37,7 +37,12 @@ class PDFParser(abstract.AbstractParser):
except
GLib
.
GError
:
# Invalid PDF
raise
ValueError
def
remove_all_lightweight
(
self
):
def
remove_all
(
self
)
->
bool
:
if
self
.
lightweight_cleaning
is
True
:
return
self
.
__remove_all_lightweight
()
return
self
.
__remove_all_thorough
()
def
__remove_all_lightweight
(
self
)
->
bool
:
"""
Load the document into Poppler, render pages on a new PDFSurface.
"""
...
...
@@ -64,7 +69,7 @@ class PDFParser(abstract.AbstractParser):
return
True
def
remove_all
(
self
)
:
def
__
remove_all
_thorough
(
self
)
->
bool
:
"""
Load the document into Poppler, render pages on PNG,
and shove those PNG into a new PDF.
...
...
This diff is collapsed.
Click to expand it.
mat2
+
1
−
2
View file @
b832a594
...
...
@@ -94,8 +94,7 @@ def clean_meta(filename: str, is_lightweight: bool, policy: UnknownMemberPolicy)
print
(
"
[-] %s
'
s format (%s) is not supported
"
%
(
filename
,
mtype
))
return
False
p
.
unknown_member_policy
=
policy
if
is_lightweight
:
return
p
.
remove_all_lightweight
()
p
.
lightweight_cleaning
=
is_lightweight
return
p
.
remove_all
()
...
...
This diff is collapsed.
Click to expand it.
tests/test_libmat2.py
+
4
−
2
View file @
b832a594
...
...
@@ -190,7 +190,8 @@ class TestLightWeightCleaning(unittest.TestCase):
meta
=
p
.
get_meta
()
self
.
assertEqual
(
meta
[
'
producer
'
],
'
pdfTeX-1.40.14
'
)
ret
=
p
.
remove_all_lightweight
()
p
.
lightweight_cleaning
=
True
ret
=
p
.
remove_all
()
self
.
assertTrue
(
ret
)
p
=
pdf
.
PDFParser
(
'
./tests/data/clean.cleaned.pdf
'
)
...
...
@@ -207,7 +208,8 @@ class TestLightWeightCleaning(unittest.TestCase):
meta
=
p
.
get_meta
()
self
.
assertEqual
(
meta
[
'
Comment
'
],
'
This is a comment, be careful!
'
)
ret
=
p
.
remove_all_lightweight
()
p
.
lightweight_cleaning
=
True
ret
=
p
.
remove_all
()
self
.
assertTrue
(
ret
)
p
=
images
.
PNGParser
(
'
./tests/data/clean.cleaned.png
'
)
...
...
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