(data, newbkpath, oldbkpath, keylist, valuelist)
| 293 | # As if they were meant only for OEBPS/content.opf and OEBPS/toc.ncx |
| 294 | # So adjust them to be relative to the Misc directory where .smil files live in Sigil |
| 295 | def performSMILUpdates(data, newbkpath, oldbkpath, keylist, valuelist): |
| 296 | data = _remove_xml_header(data) |
| 297 | # lxml on a Mac does not seem to handle full unicode properly, so encode as utf-8 |
| 298 | data = data.encode('utf-8') |
| 299 | # rebuild serialized lookup dictionary of xml_updates, properly adjusted |
| 300 | updates = OrderedDict() |
| 301 | for i in range(0, len(keylist)): |
| 302 | updates[ keylist[i] ] = valuelist[i] |
| 303 | xml_empty_tags = ["text", "audio"] |
| 304 | xmlbuilder = LXMLTreeBuilderForXML(parser=None, empty_element_tags=xml_empty_tags) |
| 305 | soup = BeautifulSoup(data, features=None, from_encoding="utf-8", builder=xmlbuilder) |
| 306 | for tag in soup.find_all(["body","seq","text","audio","smil","par"]): |
| 307 | for att in ["src", "epub:textref"]: |
| 308 | if att in tag.attrs : |
| 309 | ref = tag[att] |
| 310 | if ref.find(":") == -1 : |
| 311 | parts = ref.split('#') |
| 312 | apath = urldecodepart(parts[0]) |
| 313 | fragment = "" |
| 314 | if len(parts) > 1: |
| 315 | fragment = urldecodepart(parts[1]) |
| 316 | oldtarget = buildBookPath(apath, startingDir(oldbkpath)) |
| 317 | newtarget = updates.get(oldtarget, oldtarget) |
| 318 | attribute_value = urlencodepart(buildRelativePath(newbkpath, newtarget)) |
| 319 | if fragment != "": |
| 320 | attribute_value = attribute_value + "#" + urlencodepart(fragment) |
| 321 | tag[att] = attribute_value |
| 322 | newdata = soup.decodexml(indent_level=0, formatter='minimal', indent_chars=" ") |
| 323 | return newdata |
| 324 | |
| 325 | # Note xml_updates has urls/iris relative to the OEBPS folder as base |
| 326 | # As if they were meant only for OEBPS/content.opf and OEBPS/toc.ncx |
nothing calls this directly
no test coverage detected