title: Maintaining a roll-backable flow of code in python without extreme identation
body: <p>I've encountered a situation where I'm working over a piece of code where I command changes on a remote object (that is one I can't duplicate to work over a clone), then ask the remote object for some operation in the new state and revert all the changes I made to it by a sequence of opposite commands.
  The problem is that if in the middle of all these changes I encounter an error, I want to be able to roll-back all the changes I made so far.</p>
  
  <p>The best fitting solution that came to my mind is the python try-finally workflow, but it's rather problematic when the sequence of commands is long:</p>
  
  <pre><code>try:
      # perform action
      try:
          # perform action
          try: 
              # ...
          finally:
              # unroll
      finally:
          # unroll
  finally:
      # unroll
  </code></pre>
  
  <p>This way, the more commands I need the deeper my indentation and nesting goes and the less my code is readable.
  I've considered some other solutions such as maintaining a stack where for every command I push a rollback action, but this could get rather complicated, and I dislike pushing bound methods into stacks.
  I've also considered incrementing a counter for every action I perform then in a single finally decide on the kind of rollback I want depending on the counter, but again, the maintainability of such code becomes a pain.</p>
  
  <p>Most hits I got on searches for "transactions" and "rollback" were DB related and didn't fit very well to a more generic kind of code...
  Anyone has a good idea as to how to systematically flatten this atrocity?</p>