Skip to content

Commit

Permalink
Fix an issue in Rule classes (iterate on changing iterable)
Browse files Browse the repository at this point in the history
  • Loading branch information
Toilal committed Oct 24, 2015
1 parent 6a95ad6 commit 94dbc33
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions rebulk/rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ class RemoveMatchRule(Rule): # pylint: disable=abstract-method
"""
def then(self, matches, when_response, context):
if is_iterable(when_response):
when_response = list(when_response)
for match in when_response:
matches.remove(match)
else:
Expand All @@ -89,6 +90,7 @@ class AppendMatchRule(Rule): # pylint: disable=abstract-method
"""
def then(self, matches, when_response, context):
if is_iterable(when_response):
when_response = list(when_response)
for match in when_response:
matches.append(match)
else:
Expand All @@ -102,11 +104,13 @@ class AppendRemoveMatchRule(Rule): # pylint: disable=abstract-method
def then(self, matches, when_response, context):
to_append, to_remove = when_response
if is_iterable(to_append):
to_append = list(to_append)
for match in to_append:
matches.append(match)
else:
matches.append(to_append)
if is_iterable(to_remove):
to_remove = list(to_remove)
for match in to_remove:
matches.remove(match)
else:
Expand Down

0 comments on commit 94dbc33

Please sign in to comment.