1
2
3
4
5
6
7
8
9 """"""
10
11 __docformat__ = 'restructuredtext'
12
13
15 """Add and underline RsT string matching the length of the given string.
16 """
17 return text + '\n' + markup * len(text)
18
19
21 """Take care of empty and non existing doc strings."""
22 if text == None or not len(text):
23 return 'No documentation found. Sorry!'
24 else:
25
26
27
28
29
30
31 return text
32
33
35 """Generate enhanced doc strings."""
36 rst_lvlmarkup = ["=", "-", "_"]
37
38 docs = []
39 docs += [ handleDocString(lcl['__doc__']),
40 rstUnderline('Constructor information for `%s` class' % name,
41 rst_lvlmarkup[2]),
42 handleDocString(lcl['__init__'].__doc__) ]
43
44 if len(args):
45 docs.append(rstUnderline('\nDocumentation for base classes of `%s`' \
46 % name, rst_lvlmarkup[0]))
47 for i in args:
48 docs += [ rstUnderline('Documentation for class `%s`' % i.__name__,
49 rst_lvlmarkup[1]),
50 handleDocString(i.__doc__) ]
51
52 return '\n\n'.join(docs)
53
54
56 """Generate enhanced doc strings but given a class, not just a name.
57
58 It is to be used from a collector, it whenever class is already created
59 """
60 name = cls.__name__
61 lcl = cls.__dict__
62 rst_lvlmarkup = ["=", "-", "_"]
63
64 initdoc = None
65 if lcl.has_key('__init__'):
66 initdoc = lcl['__init__'].__doc__
67
68 if lcl.has_key('_paramsdoc'):
69 if initdoc is None:
70 initdoc = "Initialize instance of %s" % name
71
72
73 if not (":Parameters:" in initdoc):
74 initdoc += "\n\n:Parameters:\n"
75
76
77
78 nl_index = initdoc.index('\n', initdoc.index(':Parameters:')+1)
79
80 initdoc_therest = initdoc[nl_index+1:]
81 nspaces = len(initdoc_therest) - len(initdoc_therest.lstrip())
82 initdoc = initdoc[:nl_index+1] + '\n'.join(
83 [' '*nspaces + x for x in cls._paramsdoc.split('\n')]) + \
84 initdoc[nl_index:]
85
86 docs = []
87 docs += [ handleDocString(lcl['__doc__']),
88 rstUnderline('Constructor information for `%s` class' % name,
89 rst_lvlmarkup[2]),
90 handleDocString(initdoc) ]
91
92 if len(args):
93 docs.append(rstUnderline('\nDocumentation for base classes of `%s`' \
94 % name, rst_lvlmarkup[0]))
95 for i in args:
96 docs += [ rstUnderline('Documentation for class `%s`' % i.__name__,
97 rst_lvlmarkup[1]),
98 handleDocString(i.__doc__) ]
99
100 return '\n\n'.join(docs)
101