(data, newbkpath, oldbkpath, keylist, valuelist)
| 261 | |
| 262 | |
| 263 | def performOPFSourceUpdates(data, newbkpath, oldbkpath, keylist, valuelist): |
| 264 | data = _remove_xml_header(data) |
| 265 | # lxml on a Mac does not seem to handle full unicode properly, so encode as utf-8 |
| 266 | data = data.encode('utf-8') |
| 267 | # rebuild serialized lookup dictionary |
| 268 | updates = OrderedDict() |
| 269 | for i in range(0, len(keylist)): |
| 270 | updates[ keylist[i] ] = valuelist[i] |
| 271 | xmlbuilder = LXMLTreeBuilderForXML(parser=None, empty_element_tags=ebook_xml_empty_tags) |
| 272 | soup = BeautifulSoup(data, features=None, from_encoding="utf-8", builder=xmlbuilder) |
| 273 | for tag in soup.find_all(["link","item","reference","site"]): |
| 274 | if "href" in tag.attrs : |
| 275 | href = tag["href"] |
| 276 | if href.find(":") == -1 : |
| 277 | parts = href.split('#') |
| 278 | apath = urldecodepart(parts[0]) |
| 279 | fragment = "" |
| 280 | if len(parts) > 1: |
| 281 | fragment = urldecodepart(parts[1]) |
| 282 | oldtarget = buildBookPath(apath, startingDir(oldbkpath)) |
| 283 | newtarget = updates.get(oldtarget, oldtarget) |
| 284 | attribute_value = urlencodepart(buildRelativePath(newbkpath, newtarget)) |
| 285 | if fragment != "": |
| 286 | attribute_value = attribute_value + "#" + urlencodepart(fragment) |
| 287 | tag["href"] = attribute_value |
| 288 | newdata = soup.decodexml(indent_level=0, formatter='minimal', indent_chars=" ") |
| 289 | return newdata |
| 290 | |
| 291 | |
| 292 | # Note xml_updates has paths relative to the OEBPS folder as base |
nothing calls this directly
no test coverage detected