only do this sys.stderr replacing on CPython

This commit is contained in:
Benjamin Peterson 2011-03-06 17:14:30 -06:00
parent 81638f1351
commit d86e4c8673
1 changed files with 7 additions and 4 deletions

View File

@ -743,9 +743,11 @@ class WildcardPattern(BasePattern):
else:
# The reason for this is that hitting the recursion limit usually
# results in some ugly messages about how RuntimeErrors are being
# ignored.
save_stderr = sys.stderr
sys.stderr = StringIO()
# ignored. We only have to do this on CPython, though, because other
# implementations don't have this nasty bug in the first place.
if hasattr(sys, "getrefcount"):
save_stderr = sys.stderr
sys.stderr = StringIO()
try:
for count, r in self._recursive_matches(nodes, 0):
if self.name:
@ -759,7 +761,8 @@ class WildcardPattern(BasePattern):
r[self.name] = nodes[:count]
yield count, r
finally:
sys.stderr = save_stderr
if hasattr(sys, "getrefcount"):
sys.stderr = save_stderr
def _iterative_matches(self, nodes):
"""Helper to iteratively yield the matches."""