Skip to content

Commit

Permalink
Merge pull request debops#4 from ypid/fixes/coding-style
Browse files Browse the repository at this point in the history
Fixed PEP8 coding style issues.
  • Loading branch information
htgoebel committed Jun 5, 2016
2 parents 84f9825 + 66d2f25 commit c9767eb
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
2 changes: 1 addition & 1 deletion bin/yaml2rst
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import yaml2rst
import argparse
import sys


def main(infilename, outfilename):
if infilename == '-':
infh = sys.stdin
Expand All @@ -51,4 +52,3 @@ parser.add_argument('outfilename', metavar='outfile',
help="rst-file to write (`-` for stdout)")
args = parser.parse_args()
main(**vars(args))

26 changes: 15 additions & 11 deletions yaml2rst.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,18 @@ def __init__(self, **keywordargs):

enum = Struct()
enum.formatinfo = {
'parens': Struct(prefix='(', suffix=')', start=1, end=-1),
'rparen': Struct(prefix='', suffix=')', start=0, end=-1),
'period': Struct(prefix='', suffix='.', start=0, end=-1)}
'parens': Struct(prefix='(', suffix=')', start=1, end=-1),
'rparen': Struct(prefix='', suffix=')', start=0, end=-1),
'period': Struct(prefix='', suffix='.', start=0, end=-1)}
enum.formats = enum.formatinfo.keys()
enum.sequences = ['arabic', 'loweralpha', 'upperalpha',
'lowerroman', 'upperroman'] # ORDERED!
'lowerroman', 'upperroman'] # ORDERED!
enum.sequencepats = {'arabic': '[0-9]+',
'loweralpha': '[a-z]',
'upperalpha': '[A-Z]',
'lowerroman': '[ivxlcdm]+',
'upperroman': '[IVXLCDM]+',}
'upperroman': '[IVXLCDM]+',
}

pats = {}
pats['nonalphanum7bit'] = '[!-/:-@[-`{-~]'
Expand All @@ -70,21 +71,23 @@ def __init__(self, **keywordargs):
pats['enum'], re.escape(enum.formatinfo[format].suffix))

patterns = {
'bullet': u'[-+*\u2022\u2023\u2043]( +|$)',
'enumerator': r'(%(parens)s|%(rparen)s|%(period)s)( +|$)' % pats,
}
'bullet': u'[-+*\u2022\u2023\u2043]( +|$)',
'enumerator': r'(%(parens)s|%(rparen)s|%(period)s)( +|$)' % pats,
}
for name, pat in patterns.items():
patterns[name] = re.compile(pat)
return patterns


PATTERNS = setup_patterns()


def get_indent(line):
stripped_line = line.lstrip()
indent = len(line) - len(stripped_line)
if (PATTERNS['bullet'].match(stripped_line) or
PATTERNS['enumerator'].match(stripped_line)):
PATTERNS['enumerator'].match(stripped_line)):

indent += len(stripped_line.split(None, 1)[0])+1
return indent

Expand All @@ -103,7 +106,7 @@ def convert(lines):
yield ''
line = last_text_line = line[2:]
yield line
last_indent = get_indent(line)* ' '
last_indent = get_indent(line) * ' '
state = STATE_TEXT
elif line == '---':
pass
Expand All @@ -117,9 +120,10 @@ def convert(lines):
yield last_indent + ' ' + line
state = STATE_YAML


def convert_text(yaml_text):
return '\n'.join(convert(yaml_text.splitlines()))


def convert_file(infilename, outfilename):
with open(infilename) as infh:
Expand Down

0 comments on commit c9767eb

Please sign in to comment.