Skip to content

Commit

Permalink
Ensure patterns can be separated by [,;|] characters
Browse files Browse the repository at this point in the history
  • Loading branch information
alisaifee committed Jan 1, 2017
1 parent 9b81240 commit e138869
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions limits/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@

from .limits import GRANULARITIES

SEPARATORS = re.compile(r"[,;|]{1}")
SINGLE_EXPR = re.compile(
r"\s*([0-9]+)\s*(/|\s*per\s*)\s*([0-9]+)*\s*(hour|minute|second|day|month|year)s?\s*",
re.IGNORECASE
)
EXPR = re.compile(
r"^{SINGLE}(:?;{SINGLE})*$".format(SINGLE=SINGLE_EXPR.pattern),
r"^{SINGLE}(:?{SEPARATORS}{SINGLE})*$".format(SINGLE=SINGLE_EXPR.pattern, SEPARATORS=SEPARATORS.pattern),
re.IGNORECASE
)

Expand Down Expand Up @@ -40,7 +41,7 @@ def parse_many(limit_string):
if not EXPR.match(limit_string):
raise ValueError("couldn't parse rate limit string '%s'" % limit_string)
limits = []
for limit in limit_string.split(';'):
for limit in SEPARATORS.split(limit_string):
amount, _, multiples, granularity_string = SINGLE_EXPR.match(limit).groups()
granularity = granularity_from_string(granularity_string)
limits.append(granularity(amount, multiples))
Expand Down

0 comments on commit e138869

Please sign in to comment.