View Single Post
Old 06-12-2012, 02:18 PM   #4
kiwidude
Calibre Plugins Developer
kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.
 
Posts: 4,654
Karma: 2162064
Join Date: Oct 2010
Location: Australia
Device: Kindle Oasis
For an example of a regex replacement, just look at the _remove_drm_meta_tags() or _remove_embedded_fonts() functions in BookModifier. When you work with my container there are two key options when you ask the container for a file:

container.get_raw(name) - gives you the file data as a raw text string. So if you are intending to use regex to parse that text, this is the one you want.

container.get_parsed_etree(name) - gives you the data as an etree object to allow you to perform xpath based lookups and replacements on xml/xhtml files.

If you make changes to that data, then call container.set(name, obj) which will update all its internal caches etc. So if you were to ask for that same object again using either of the functions above you will be working with the latest modified version. Then at the very end of the process in container.write() all the updated cached data is physically written into the files before rezipping.
kiwidude is offline   Reply With Quote