def preprocess(self): """Unfortunately, the notice xml is often inaccurate. This function attempts to fix some of those (general) flaws. For specific issues, we tend to instead use the files in settings.LOCAL_XML_PATHS""" for plugin in plugins.instantiate_if_possible( 'eregs_ns.parser.preprocessors', method_name='transform'): plugin(self.xml) return self
def content_of_change(self, instruction_xml): """Instructions which create or modify a chunk of the CFR need to know not only which paragraphs are being modified, but the _content_ of those modifications. This method searches the XML around the instruction and attempts to derive a related Node""" is_editing = instruction_xml.tag in ('POST', 'PUT', 'INSERT', 'RESERVE') if not is_editing: return None for extension in instantiate_if_possible( 'eregs_ns.parser.amendment.content'): result = extension(instruction_xml) if result: key, fn = result if key is not None and key not in self.by_xml: self.by_xml[key] = Content(fn(), []) return self.by_xml.get(key)
def build_tree(reg_xml): logger.info("Build tree %s", reg_xml) preprocess_xml(reg_xml) reg_part = get_reg_part(reg_xml) title = get_title(reg_xml) tree = Node("", [], [reg_part], title) part = reg_xml.xpath('self::PART|.//PART')[0] matchers = list(plugins.instantiate_if_possible( 'eregs_ns.parser.xml_matchers.gpo_cfr.PART')) for xml_node in part.getchildren(): for plugin in matchers: if plugin.matches(tree, xml_node): plugin(tree, xml_node) return tree
def build_tree(reg_xml): preprocess_xml(reg_xml) reg_part = get_reg_part(reg_xml) title = get_title(reg_xml) tree = Node("", [], [reg_part], title) part = reg_xml.xpath('self::PART|.//PART')[0] matchers = list( plugins.instantiate_if_possible( 'eregs_ns.parser.xml_matchers.gpo_cfr.PART')) for xml_node in part.getchildren(): for plugin in matchers: if plugin.matches(tree, xml_node): plugin(tree, xml_node) return tree