def fix_errors(container, errors): # Fix parsing changed = False for name in { e.name for e in errors if getattr(e, 'is_parsing_error', False) }: try: root = container.parsed(name) except TypeError: continue container.dirty(name) if container.mime_map[name] in OEB_DOCS: for style in root.xpath('//*[local-name()="style"]'): if style.get( 'type', 'text/css' ) == 'text/css' and style.text and style.text.strip(): fix_style_tag(container, style) changed = True for err in errors: if err.INDIVIDUAL_FIX: if err(container) is not False: # Assume changed unless fixer explicitly says no change (this # is because sometimes I forget to return True, and it is # better to have a false positive than a false negative) changed = True return changed
def fix_errors(container, errors): # Fix parsing changed = False for name in {e.name for e in errors if getattr(e, 'is_parsing_error', False)}: root = container.parsed(name) container.dirty(name) if container.mime_map[name] in OEB_DOCS: for style in root.xpath('//*[local-name()="style"]'): if style.get('type', 'text/css') == 'text/css' and style.text and style.text.strip(): fix_style_tag(container, style) changed = True for err in errors: if err.INDIVIDUAL_FIX: if err(container) is not False: # Assume changed unless fixer explicitly says no change (this # is because sometimes I forget to return True, and it is # better to have a false positive than a false negative) changed = True return changed