"Fossies" - the Fresh Open Source Software Archive 
Member "jansson-2.14/doc/ext/refcounting.py" (19 Nov 2020, 1863 Bytes) of package /linux/www/jansson-2.14.tar.bz2:
As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Python source code syntax highlighting (style:
standard) with prefixed line numbers.
Alternatively you can here
view or
download the uninterpreted source code file.
See also the latest
Fossies "Diffs" side-by-side code changes report for "refcounting.py":
2.13.1_vs_2.14.
1 """
2 refcounting
3 ~~~~~~~~~~~
4
5 Reference count annotations for C API functions. Has the same
6 result as the sphinx.ext.refcounting extension but works for all
7 functions regardless of the signature, and the reference counting
8 information is written inline with the documentation instead of a
9 separate file.
10
11 Adds a new directive "refcounting". The directive has no content
12 and one required positional parameter:: "new" or "borrow".
13
14 Example:
15
16 .. cfunction:: json_t *json_object(void)
17
18 .. refcounting:: new
19
20 <description of the json_object function>
21
22 :copyright: Copyright (c) 2009-2016 Petri Lehtinen <petri@digip.org>
23 :license: MIT, see LICENSE for details.
24 """
25
26 from docutils import nodes
27 from docutils.parsers.rst import Directive
28
29
30 def visit(self, node):
31 self.visit_emphasis(node)
32
33 def depart(self, node):
34 self.depart_emphasis(node)
35
36 def html_visit(self, node):
37 self.body.append(self.starttag(node, 'em', '', CLASS='refcount'))
38
39 def html_depart(self, node):
40 self.body.append('</em>')
41
42
43 class refcounting(nodes.emphasis):
44 pass
45
46 class refcounting_directive(Directive):
47 has_content = False
48 required_arguments = 1
49 optional_arguments = 0
50 final_argument_whitespace = False
51
52 def run(self):
53 if self.arguments[0] == 'borrow':
54 text = 'Return value: Borrowed reference.'
55 elif self.arguments[0] == 'new':
56 text = 'Return value: New reference.'
57 else:
58 raise Error('Valid arguments: new, borrow')
59
60 return [refcounting(text, text)]
61
62
63 def setup(app):
64 app.add_node(refcounting,
65 html=(html_visit, html_depart),
66 latex=(visit, depart),
67 text=(visit, depart),
68 man=(visit, depart))
69 app.add_directive('refcounting', refcounting_directive)