(data, newbkpath, oldbkpath, keylist, valuelist)
| 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 |
| 328 | def 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 | |
| 359 | def main(): |
nothing calls this directly
no test coverage detected