Again me: Validate OPF and offset.
I found the issue that bothered me.
bk.get_opf() -- is not perfect.
Why?
Result of bk.get_opf() is not current state of file .opf. This is state "what will the .opf file look like after saving" + missing two spaces before
<metadata and
</metadata> + missing four spaces before each
<dc:… and
<meta ….
These missing spaces prevented me from calculating the offsets accurately.
Code:
opf_data = bk.get_opf()
opf_data = re.sub("<metadata"," <metadata",opf_data)
opf_data = re.sub("<meta "," <meta ",opf_data)
opf_data = re.sub("<dc:"," <dc:",opf_data)
opf_data = re.sub("</metadata"," </metadata",opf_data)