コード例 #1
0
ファイル: jsonparser.py プロジェクト: asobolev/python-odml
            elif v is not None:
                kargs[fmt.map(k)] = v
        return getattr(self, "create_%s" % fmt._name)(fmt, kargs, obj, objects)

    def create_odML(self, fmt, kargs, obj, children):
        obj = fmt.create(**kargs)
        for i in children:
            obj.append(i)
        return obj

    create_section = create_odML
    create_value = create_odML

    def create_property(self, fmt, kargs, obj, children):
        kargs['value'] = children
        return self.create_odML(fmt, kargs, obj, [])

class JSONReader(OdmlReader):
    def fromString(self, data):
        obj = json.loads(data)
        return self.to_odml(obj)

    def fromFile(self, infile):
        return self.fromString(infile.read())

if __name__=="__main__":
    import sys
    y = JSONReader().fromFile(sys.stdin)
    import dumper
    dumper.dumpDoc(y)
コード例 #2
0
ファイル: xmlparser.py プロジェクト: carloscanova/python-odml
                name = name_node.text
                root.remove(name_node)
                # delete the name_node so its value won't
                # be used to overwrite the already set name-attribute

        if name is None:
            self.error("Missing name element in <section>", root)

        return self.parse_tag(root, fmt, create=lambda **kargs: fmt.create(name))

    def parse_property(self, root, fmt):
        create = lambda children, args, **kargs: fmt.create(value=children, **args)
        return self.parse_tag(root, fmt, insert_children=False, create=create)

    def parse_value(self, root, fmt):
        create = lambda text, args, **kargs: fmt.create(text, **args)
        return self.parse_tag(root, fmt, create=create)

if __name__ == '__main__':
    from optparse import OptionParser
    import dumper

    parser = OptionParser()
    (options, args) = parser.parse_args()

    if len(args) < 1:
        parser.print_help()
    else:
        dumper.dumpDoc(load(args[0]))

コード例 #3
0
ファイル: jsonparser.py プロジェクト: asobolev/python-odml
        return getattr(self, "create_%s" % fmt._name)(fmt, kargs, obj, objects)

    def create_odML(self, fmt, kargs, obj, children):
        obj = fmt.create(**kargs)
        for i in children:
            obj.append(i)
        return obj

    create_section = create_odML
    create_value = create_odML

    def create_property(self, fmt, kargs, obj, children):
        kargs['value'] = children
        return self.create_odML(fmt, kargs, obj, [])


class JSONReader(OdmlReader):
    def fromString(self, data):
        obj = json.loads(data)
        return self.to_odml(obj)

    def fromFile(self, infile):
        return self.fromString(infile.read())


if __name__ == "__main__":
    import sys
    y = JSONReader().fromFile(sys.stdin)
    import dumper
    dumper.dumpDoc(y)
コード例 #4
0
                # be used to overwrite the already set name-attribute

        if name is None:
            self.error("Missing name element in <section>", root)

        return self.parse_tag(root,
                              fmt,
                              create=lambda **kargs: fmt.create(name))

    def parse_property(self, root, fmt):
        create = lambda children, args, **kargs: fmt.create(value=children,
                                                            **args)
        return self.parse_tag(root, fmt, insert_children=False, create=create)

    def parse_value(self, root, fmt):
        create = lambda text, args, **kargs: fmt.create(text, **args)
        return self.parse_tag(root, fmt, create=create)


if __name__ == '__main__':
    from optparse import OptionParser
    import dumper

    parser = OptionParser()
    (options, args) = parser.parse_args()

    if len(args) < 1:
        parser.print_help()
    else:
        dumper.dumpDoc(load(args[0]))