root/livinglogic.python.xist/src/ll/xist/scripts/ @ 4436:b3c3ebbdfa3c

Revision 4436:b3c3ebbdfa3c, 2.6 KB (checked in by Walter Doerwald <walter@…>, 8 years ago)

Remove defaults argument from tld2xsc. Add proper docstring to tld2xsc.

[2522]1#! /usr/bin/env python
[2903]2# -*- coding: utf-8 -*-
[4422]4## Copyright 1999-2011 by LivingLogic AG, Bayreuth/Germany
5## Copyright 1999-2011 by Walter Dörwald
7## All Rights Reserved
[3263]9## See ll/ for the license
[4436]13``tld2xsc`` is a script that converts a JSP Tag Library Descriptor XML file
14into a skeleton XIST namespace module. The tld file is read from stdin and
15the namespace module is printed to stdout.
[4436]17``tld2xsc`` supports the following options:
[4436]19    ``-s``, ``--shareattrs`` : ``none``, ``dupes``, ``all``
20        Should attributes be shared among the elements? ``none`` means that each
21        element will have its own standalone :class:`Attrs` class directly derived
22        from :class:`ll.xist.Elements.Attrs`. For ``dupes`` each attribute that is
23        used by more than one element will be moved into its own :class:`Attrs`
24        class. For ``all`` this will be done for all attributes.
26    ``-m``, ``--model`` : ``no``, ``simple``, ``fullall``, ``fullonce``
27        Add model information to the namespace. ``no`` doesn't add any model
28        information. ``simple`` only adds ``model = False`` or ``model = True``
29        (i.e. only the information whether the element must be empty or not).
30        ``fullall`` adds a :mod:`ll.xist.sims` model object to each element class.
31        ``fullonce`` adds full model information to, but reuses model objects for
32        elements which have the same model.
[3180]35__docformat__ = "reStructuredText"
[4113]38import sys, argparse
[4289]40from ll import misc, url
[4052]41from ll.xist import xsc, xfind, parse
[2522]42from ll.xist.ns import tld
[3180]45__docformat__ = "reStructuredText"
[4295]48def makexnd(stream, encoding=None, shareattrs="dupes", model="simple"):
[4289]49    # :var:`stream` can be a stream, an :class:`URL` or a string
50    node = parse.tree(stream, parse.Expat(), parse.NS(tld), parse.Node())
52    # get and convert the taglib object
[4289]53    xnd = node.walknodes(tld.taglib)[0].asxnd(model=model)
55    if shareattrs=="dupes":
[2996]56        xnd.shareattrs(False)
[2522]57    elif shareattrs=="all":
[2996]58        xnd.shareattrs(True)
59    return xnd
[3031]62def main(args=None):
[4113]63    p = argparse.ArgumentParser(description="Convert JSP Tag Library Descriptor XML file (on stdin) to XIST namespace (on stdout)")
[4292]64    p.add_argument("-s", "--shareattrs", dest="shareattrs", help="Should identical attributes be shared among elements? (default %(default)s)", choices=("none", "dupes", "all"), default="dupes")
65    p.add_argument("-m", "--model", dest="model", help="Add sims information to the namespace (default %(default)s)", choices=("none", "simple", "fullall", "fullonce"), default="simple")
[4113]67    args = p.parse_args(args)
[4436]68    print makexnd(sys.stdin, args.shareattrs, model=args.model)
71if __name__ == "__main__":
72    sys.exit(main())
Note: See TracBrowser for help on using the browser.