Skip to content

Commit

Permalink
rewrite some loop logic for smaller nesting
Browse files Browse the repository at this point in the history
Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
  • Loading branch information
zyga committed Jul 16, 2014
1 parent 7768d81 commit f808a18
Showing 1 changed file with 27 additions and 24 deletions.
51 changes: 27 additions & 24 deletions sphinxarg/ext.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,30 +11,33 @@ def map_nested_definitions(nested_content):
# build definition dictionary
definitions = {}
for item in nested_content:
if isinstance(item, nodes.definition_list):
for subitem in item:
if isinstance(subitem, nodes.definition_list_item):
if len(subitem.children) > 0:
classifier = '@after'
idx = subitem.first_child_matching_class(nodes.classifier)
if not idx is None:
ci = subitem[idx]
if len(ci.children) > 0:
classifier = ci.children[0].astext()

if not classifier is None and not classifier in ('@replace', '@before', '@after'):
raise Exception('Unknown classifier: %s' % classifier)

idx = subitem.first_child_matching_class(nodes.term)
if not idx is None:
ch = subitem[idx]
if len(ch.children) > 0:
term = ch.children[0].astext()
idx = subitem.first_child_matching_class(nodes.definition)
if not idx is None:
def_node = subitem[idx]
def_node.attributes['classifier'] = classifier
definitions[term] = def_node
if not isinstance(item, nodes.definition_list):
continue
for subitem in item:
if not isinstance(subitem, nodes.definition_list_item):
continue
if not len(subitem.children) > 0:
continue
classifier = '@after'
idx = subitem.first_child_matching_class(nodes.classifier)
if not idx is None:
ci = subitem[idx]
if len(ci.children) > 0:
classifier = ci.children[0].astext()

if not classifier is None and not classifier in ('@replace', '@before', '@after'):
raise Exception('Unknown classifier: %s' % classifier)

idx = subitem.first_child_matching_class(nodes.term)
if not idx is None:
ch = subitem[idx]
if len(ch.children) > 0:
term = ch.children[0].astext()
idx = subitem.first_child_matching_class(nodes.definition)
if not idx is None:
def_node = subitem[idx]
def_node.attributes['classifier'] = classifier
definitions[term] = def_node
return definitions


Expand Down

0 comments on commit f808a18

Please sign in to comment.