Skip to content

Commit

Permalink
Remove extra prints and add documentation for regex formatter
Browse files Browse the repository at this point in the history
  • Loading branch information
djhoese committed Sep 27, 2018
1 parent 31c4761 commit 78b387c
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions trollsift/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,18 @@ def convert_field(self, value, conversion):


class RegexFormatter(string.Formatter):
"""String formatter that converts a format string to a regular expression.
>>> regex_formatter = RegexFormatter()
>>> regex_str = regex_formatter.format('{field_one:5d}_{field_two}')
Can also be used to extract values from a string given the format spec
for that string:
>>> regex_formatter.extract_values('{field_one:5d}_{field_two}', '12345_sometext')
{'field_one': '12345', 'field_two': 'sometext'}
"""

# special string to mark a parameter not being specified
UNPROVIDED_VALUE = '<trollsift unprovided value>'
Expand Down Expand Up @@ -510,9 +522,7 @@ def is_one2one(fmt):
return False

# run data forward once and back to data
print(fmt, data)
stri = compose(fmt, data)
print(fmt, stri)
data2 = parse(fmt, stri)
# check if data2 equal to original data
if len(data) != len(data2):
Expand Down

0 comments on commit 78b387c

Please sign in to comment.