class Transformer(object): """ Transform xml trees using pythonic xist-like specifications. """ def __init__(self, source=silvaformat, target=htmlformat): """ provide a transformer from source to target (and possibly back). """ self.source_parser = ObjectParser(source) self.target_parser = ObjectParser(target) def to_target(self, sourceobj, context, compacting=True): context.begin_transform() node = self.source_parser.parse(sourceobj) if compacting: node = node.compact() result = node.convert(context=context) context.finish_transform() return result def to_source(self, targetobj, context, compacting=True, cleaner=None): context.begin_transform() node = self.target_parser.parse(targetobj) if compacting: node = node.compact() result = node.convert(context=context) if cleaner is not None: cleaner(result) context.finish_transform() return result
def __init__(self, source=silvaformat, target=htmlformat): """ provide a transformer from source to target (and possibly back). """ self.source_parser = ObjectParser(source) self.target_parser = ObjectParser(target)