Skip to content

Commit

Permalink
Make sure the context manager teardown is done even if there an excep…
Browse files Browse the repository at this point in the history
…tion.
  • Loading branch information
Michael Howitz committed Feb 1, 2017
1 parent 215ffa1 commit 497a9ba
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/AccessControl/SimpleObjectPolicies.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,10 @@ def override_containers(type_, assertions):
"""Temporarily override the container assertions."""
orig_container = Containers(type_, _marker)
ContainerAssertions[type_] = assertions
yield
if orig_container is _marker:
del ContainerAssertions[type_]
else:
ContainerAssertions[type_] = orig_container
try:
yield
finally:
if orig_container is _marker:
del ContainerAssertions[type_]
else:
ContainerAssertions[type_] = orig_container

0 comments on commit 497a9ba

Please sign in to comment.