<commit_before>Rollback
========

Simple mechanism for rolling back multiple operations in a predictable way,
either as a context manager or a standalone instance. By default, errors are
re-raised, but an explicit mode or call *must* be supplied to trigger a
rollback.  Valid modes are:

* `onError`  Boolean when `True` will roll back if an error is raised
* `onSuccess` Boolean when `True` will roll back if an error is _not_ raised

Both modes can be set to `True` to always rollback. A rollback can also be
triggered manually by calling `doRollback`. Errors can be supressed by
setting `raiseError` to `False`.  

If a rollback is triggered, each step is called in a last in, first out
order (LIFO).  That is, the most recently added step is called first,
the first step if called last.

## Compatibility

Rollback was tested with the following versions of Python
* 2.6.9
* 2.7.13
* 3.3.6
* 3.4.6
* 3.5.3
* 3.6.1

## Installation

```
python setup.py install
```

## Example usage

```python
from __future__ import print_function

from rollback import Rollback

# *always* rollback after exiting block, letting any error be re-raised
with Rollback(onError=True, onSuccess=True) as rollback:
  print('do a1')
  rollback.addStep(print, 'undo a1')
  print('do a2')
  rollback.addStep(print, 'undo a2')

# rollback *only* if *no* error is raised, letting any error be re-raised
with Rollback(onSuccess=True) as rollback:
  print('do b1')
  rollback.addStep(print, 'undo b1')
  print('do b2')
  rollback.addStep(print, 'undo b2')

# rollback manually<commit_msg>clarify usage<commit_after>Rollback
========

A simple Pythonic mechanism for rolling back multiple operations in a
predictable way, either as a context manager or a standalone instance.
By default, errors are re-raised, but an explicit mode or call *must*
be supplied to trigger a rollback. Valid modes are:

* `onError`  Boolean when `True` will roll back if an error is raised
* `onSuccess` Boolean when `True` will roll back if an error is _not_ raised

Both modes can be set to `True` to always rollback. A rollback can also be
triggered manually by calling `doRollback`. Errors can be supressed by
setting `raiseError` to `False`.  

If a rollback is triggered, each step is called in a last in, first out
order (LIFO).  That is, the most recently added step is called first,
the first step if called last.

### Compatibility

Rollback was tested with the following versions of Python
* 2.6.9
* 2.7.13
* 3.3.6
* 3.4.6
* 3.5.3
* 3.6.1

### Installation

```
python setup.py install
```

### Example usage

```python
from __future__ import print_function

from rollback import Rollback

# *always* rollback after exiting block, letting any error be re-raised
with Rollback(onError=True, onSuccess=True) as rollback:
  print('do a1')
  rollback.addStep(print, 'undo a1')
  print('do a2')
  rollback.addStep(print, 'undo a2')

# rollback *only* if *no* error is raised, letting any error be re-raised
with Rollback(onSuccess=True) as rollback:
  print('do b1')
  rollback.addStep(print, 'undo b1')
  print('do b2')
  rollback.addStep(print, 'undo b2')

# rollback manually
{'fraction_non_alphanumeric': 0.09409888357256778, 'fraction_numerical': 0.01722488038277512, 'mean_word_length': 4.36068376068376, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3884376', 'n_tokens_mistral': 1015, 'n_tokens_neox': 981, 'n_words': 428}