Skip to content

Commit

Permalink
Merge pull request docopt#21 from ffunenga/fix-pep8-docopt-c
Browse files Browse the repository at this point in the history
Fixes pep8 warnings in docopt_c.py
  • Loading branch information
kblomqvist committed Jun 28, 2013
2 parents 09f39cd + 18b4905 commit e475b31
Showing 1 changed file with 9 additions and 14 deletions.
23 changes: 9 additions & 14 deletions docopt_c.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def parse_leafs(pattern):
while queue:
level, node = queue.pop(-1) # depth-first search
if hasattr(node, 'children'):
children = [((level+1), child) for child in node.children]
children = [((level + 1), child) for child in node.children]
children.reverse()
queue.extend(children)
else:
Expand Down Expand Up @@ -142,15 +142,11 @@ def parse_leafs(pattern):
sys.exit(e)

doc = args['<docopt>']
usage_sections = docopt.parse_section('usage:', doc)

if len(usage_sections) == 0:
raise docopt.DocoptLanguageError(
'"usage:" (case-insensitive) not found.')
if len(usage_sections) > 1:
raise docopt.DocoptLanguageError(
'More than one "usage:" (case-insensitive).')
usage = usage_sections[0]
usage = docopt.parse_section('usage:', doc)
s = ['More than one ', '"usage:" (case-insensitive)', ' not found.']
usage = {0: s[1:], 1: usage[0] if usage else None}.get(len(usage), s[:2])
if isinstance(usage, list):
raise docopt.DocoptLanguageError(''.join(usage))

options = docopt.parse_defaults(doc)
pattern = docopt.parse_pattern(docopt.formal_usage(usage), options)
Expand Down Expand Up @@ -180,11 +176,10 @@ def parse_leafs(pattern):
t_elems_cmds = ('\n ' + t_elems_cmds) if t_elems_cmds != '' else ''
t_elems_args = ',\n '.join([c_argument(arg) for arg in (arguments)])
t_elems_args = ('\n ' + t_elems_args) if t_elems_args != '' else ''
t_elems_opts = ',\n '.join([c_option(o) for o in (flags+options)])
t_elems_opts = ',\n '.join([c_option(o) for o in (flags + options)])
t_elems_opts = ('\n ' + t_elems_opts) if t_elems_opts != '' else ''
t_elems_n = ', '.join([str(len(lst))
for lst in [commands, arguments, (flags+options)]])

t_elems_n = ', '.join([str(len(l))
for l in [commands, arguments, (flags + options)]])
t_if_command = ' else '.join(c_if_command(command) for command in commands)
t_if_command = ('\n ' + t_if_command) if t_if_command != '' else ''
t_if_argument = ' else '.join(c_if_argument(arg) for arg in arguments)
Expand Down

0 comments on commit e475b31

Please sign in to comment.