MCPcopy Create free account
hub / github.com/Sigil-Ebook/Sigil / performPageMapUpdates

Function performPageMapUpdates

src/Resource_Files/python3lib/xmlprocessor.py:328–356  ·  view source on GitHub ↗
(data, newbkpath, oldbkpath, keylist, valuelist)

Source from the content-addressed store, hash-verified

326# As if they were meant only for OEBPS/content.opf and OEBPS/toc.ncx
327# So adjust them to be relative to the Misc directory where page-map.xml lives
328def performPageMapUpdates(data, newbkpath, oldbkpath, keylist, valuelist):
329 data = _remove_xml_header(data)
330 # lxml on a Mac does not seem to handle full unicode properly, so encode as utf-8
331 data = data.encode('utf-8')
332 # rebuild serialized lookup dictionary of xml_updates properly adjusted
333 updates = OrderedDict()
334 for i in range(0, len(keylist)):
335 updates[ keylist[i] ] = valuelist[i]
336 xml_empty_tags = ["page"]
337 xmlbuilder = LXMLTreeBuilderForXML(parser=None, empty_element_tags=xml_empty_tags)
338 soup = BeautifulSoup(data, features=None, from_encoding="utf-8", builder=xmlbuilder)
339 for tag in soup.find_all(["page"]):
340 for att in ["href"]:
341 if att in tag.attrs :
342 ref = tag[att]
343 if ref.find(":") == -1 :
344 parts = ref.split('#')
345 apath = urldecodepart(parts[0])
346 fragment = ""
347 if len(parts) > 1:
348 fragment = urldecodepart(parts[1])
349 oldtarget = buildBookPath(apath, startingDir(oldbkpath))
350 newtarget = updates.get(oldtarget, oldtarget)
351 attribute_value = urlencodepart(buildRelativePath(newbkpath, newtarget))
352 if fragment != "":
353 attribute_value = attribute_value + "#" + urlencodepart(fragment)
354 tag[att] = attribute_value
355 newdata = soup.decodexml(indent_level=0, formatter='minimal', indent_chars=" ")
356 return newdata
357
358
359def main():

Callers

nothing calls this directly

Calls 13

decodexmlMethod · 0.95
BeautifulSoupClass · 0.90
urldecodepartFunction · 0.90
buildBookPathFunction · 0.90
startingDirFunction · 0.90
urlencodepartFunction · 0.90
buildRelativePathFunction · 0.90
find_allMethod · 0.80
_remove_xml_headerFunction · 0.70
encodeMethod · 0.45
findMethod · 0.45

Tested by

no test coverage detected