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
Model registry
Monitor
Service Desk
Analyze
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
jvoisin
mat2
Commits
626669f9
Commit
626669f9
authored
4 years ago
by
Julien (jvoisin) Voisin
Browse files
Options
Downloads
Patches
Plain Diff
Add some typing to epub.py
parent
497f5f71
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
libmat2/epub.py
+5
-4
5 additions, 4 deletions
libmat2/epub.py
with
5 additions
and
4 deletions
libmat2/epub.py
+
5
−
4
View file @
626669f9
...
...
@@ -2,6 +2,7 @@ import logging
import
re
import
uuid
import
xml.etree.ElementTree
as
ET
# type: ignore
from
typing
import
Dict
,
Any
from
.
import
archive
,
office
...
...
@@ -38,7 +39,7 @@ class EPUBParser(archive.ZipParser):
except
(
TypeError
,
UnicodeDecodeError
):
return
{
file_path
:
'
harmful content
'
,
}
def
_specific_cleanup
(
self
,
full_path
:
str
):
def
_specific_cleanup
(
self
,
full_path
:
str
)
->
bool
:
if
full_path
.
endswith
(
'
hmh.opf
'
)
or
full_path
.
endswith
(
'
content.opf
'
):
return
self
.
__handle_contentopf
(
full_path
)
elif
full_path
.
endswith
(
'
OEBPS/toc.ncx
'
):
...
...
@@ -47,7 +48,7 @@ class EPUBParser(archive.ZipParser):
return
self
.
__handle_ops_xml
(
full_path
)
return
True
def
__handle_ops_xml
(
self
,
full_path
:
str
):
def
__handle_ops_xml
(
self
,
full_path
:
str
)
->
bool
:
try
:
tree
,
namespace
=
office
.
_parse_xml
(
full_path
)
except
ET
.
ParseError
:
# pragma: nocover
...
...
@@ -63,7 +64,7 @@ class EPUBParser(archive.ZipParser):
return
True
def
__handle_tocncx
(
self
,
full_path
:
str
):
def
__handle_tocncx
(
self
,
full_path
:
str
)
->
bool
:
try
:
tree
,
namespace
=
office
.
_parse_xml
(
full_path
)
except
ET
.
ParseError
:
# pragma: nocover
...
...
@@ -79,7 +80,7 @@ class EPUBParser(archive.ZipParser):
short_empty_elements
=
False
)
return
True
def
__handle_contentopf
(
self
,
full_path
:
str
):
def
__handle_contentopf
(
self
,
full_path
:
str
)
->
bool
:
try
:
tree
,
namespace
=
office
.
_parse_xml
(
full_path
)
except
ET
.
ParseError
:
...
...
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