Passed
Pull Request — main (#155)
by Oliver
01:45
created

exception_hierarchy   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 4
eloc 24
dl 0
loc 36
rs 10
c 0
b 0
f 0

3 Functions

Rating   Name   Duplication   Size   Complexity  
A visit_exception_hierarchy_node() 0 3 1
A setup() 0 4 1
A depart_exception_hierarchy_node() 0 2 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A ExceptionHierarchyDirective.run() 0 5 1
1
from docutils.parsers.rst import Directive
2
from docutils.parsers.rst import states, directives
3
from docutils.parsers.rst.roles import set_classes
4
from docutils import nodes
5
from sphinx.locale import _
6
7
8
class exception_hierarchy(nodes.General, nodes.Element):
9
    pass
10
11
12
def visit_exception_hierarchy_node(self, node):
13
    self.starttag(
14
        node, 'div', CLASS='exception-hierarchy-content'
15
    )
16
17
18
def depart_exception_hierarchy_node(self, node):
19
    self.body.append('</div>\n')
20
21
22
class ExceptionHierarchyDirective(Directive):
23
    has_content = True
24
25
    def run(self):
26
        self.assert_has_content()
27
        node = exception_hierarchy('\n'.join(self.content))
28
        self.state.nested_parse(self.content, self.content_offset, node)
29
        return [node]
30
31
32
def setup(app):
33
    app.add_node(exception_hierarchy, html=(
34
        visit_exception_hierarchy_node, depart_exception_hierarchy_node))
35
    app.add_directive('exception_hierarchy', ExceptionHierarchyDirective)
36