refcounting.py (jansson-2.13.1.tar.bz2) | : | refcounting.py (jansson-2.14.tar.bz2) | ||
---|---|---|---|---|
skipping to change at line 27 | skipping to change at line 27 | |||
.. refcounting:: new | .. refcounting:: new | |||
<description of the json_object function> | <description of the json_object function> | |||
:copyright: Copyright (c) 2009-2016 Petri Lehtinen <petri@digip.org> | :copyright: Copyright (c) 2009-2016 Petri Lehtinen <petri@digip.org> | |||
:license: MIT, see LICENSE for details. | :license: MIT, see LICENSE for details. | |||
""" | """ | |||
from docutils import nodes | from docutils import nodes | |||
from docutils.parsers.rst import Directive | ||||
class refcounting(nodes.emphasis): pass | ||||
def visit(self, node): | def visit(self, node): | |||
self.visit_emphasis(node) | self.visit_emphasis(node) | |||
def depart(self, node): | def depart(self, node): | |||
self.depart_emphasis(node) | self.depart_emphasis(node) | |||
def html_visit(self, node): | def html_visit(self, node): | |||
self.body.append(self.starttag(node, 'em', '', CLASS='refcount')) | self.body.append(self.starttag(node, 'em', '', CLASS='refcount')) | |||
def html_depart(self, node): | def html_depart(self, node): | |||
self.body.append('</em>') | self.body.append('</em>') | |||
def refcounting_directive(name, arguments, options, content, lineno, | class refcounting(nodes.emphasis): | |||
content_offset, block_text, state, state_machine): | pass | |||
if arguments[0] == 'borrow': | ||||
text = 'Return value: Borrowed reference.' | class refcounting_directive(Directive): | |||
elif arguments[0] == 'new': | has_content = False | |||
text = 'Return value: New reference.' | required_arguments = 1 | |||
else: | optional_arguments = 0 | |||
raise Error('Valid arguments: new, borrow') | final_argument_whitespace = False | |||
def run(self): | ||||
if self.arguments[0] == 'borrow': | ||||
text = 'Return value: Borrowed reference.' | ||||
elif self.arguments[0] == 'new': | ||||
text = 'Return value: New reference.' | ||||
else: | ||||
raise Error('Valid arguments: new, borrow') | ||||
return [refcounting(text, text)] | return [refcounting(text, text)] | |||
def setup(app): | def setup(app): | |||
app.add_node(refcounting, | app.add_node(refcounting, | |||
html=(html_visit, html_depart), | html=(html_visit, html_depart), | |||
latex=(visit, depart), | latex=(visit, depart), | |||
text=(visit, depart), | text=(visit, depart), | |||
man=(visit, depart)) | man=(visit, depart)) | |||
app.add_directive('refcounting', refcounting_directive, 0, (1, 0, 0)) | app.add_directive('refcounting', refcounting_directive) | |||
End of changes. 4 change blocks. | ||||
11 lines changed or deleted | 18 lines changed or added |