Ejemplo n.º 1
0
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
Ejemplo n.º 2
0
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
Ejemplo n.º 3
0
 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)
Ejemplo n.º 4
0
 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)