Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
jvoisin
mat2
Commits
626669f9
Commit
626669f9
authored
Mar 07, 2021
by
jvoisin
Browse files
Add some typing to epub.py
parent
497f5f71
Changes
1
Hide whitespace changes
Inline
Side-by-side
libmat2/epub.py
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
:
...
...
Write
Preview
Supports
Markdown
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