jsocol/bleach — Issue #58: A cleaning pipeline
Author: originell
Created: 2012-03-06 16:22:22+00:00
State: open

One thing that occured to me while working on the `BleachSanitizerMixin.sanitize_token` is that it's code is getting pretty long and kind of ugly, the more functionality one needs do add.

One possible way to counter this problem might be to implement a "pipeline". I've seen this concept first in [django-social-auth](https://github.com/omab/django-social-auth) which I'm also using in a project. To be more specific [this part of the README](https://github.com/omab/django-social-auth#id14) explains it pretty good. Personally I really love the concept. The code of the [default social auth pipeline is here](https://github.com/omab/django-social-auth/tree/master/social_auth/backends/pipeline)

So what I am proposing is something very much in the vain of social auth's pipeline:

1. Instead of having to tie into the (big) if condition, we iterate over an iterable with functions::

```python
PIPELINE = ('SkipAllowedElements', 'StripScripts',...)
```

2. While iterating, each function get's called and returns either a cleaned token which gets passed on to the next function in the iterable *or* `None` for skip. Note that maybe it might be more expressive to use Exceptions (like `SkipToken`) here.

This may also clean up a bit of the code I introduce with the `strip_script_content` fork (like doing `self.previous_token = token` right before every `return`)

So, basically this is me requesting for a comment on refactoring things a bit :D – Maybe the same kind of *pipeline-logic* could be used for #56