Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cannot import name 'sanitizer' #277

Closed
erikzenker opened this issue Jul 15, 2016 · 5 comments
Closed

cannot import name 'sanitizer' #277

erikzenker opened this issue Jul 15, 2016 · 5 comments

Comments

@erikzenker
Copy link

I want install the django cms which uses the sanitizer of the html5lib,
but I get the error shown above in the title.

when I just import the sanitizer from html5lib:

from html5lib import sanitizer

I get the following error:

Traceback (most recent call last):
  File "test.py", line 1, in <module>
    from html5lib import sanitizer
ImportError: cannot import name 'sanitizer'

I installed html5lib from pip:

pip install html5lib

Is the sanitizer module not available anymore ?

@stefanfoulis
Copy link

@erikzenker It looks like it has been removed (or moved). Quickfix is to use a slightly older version of the package where sanitizer is still there:

pip install html5lib<0.99999999

ot: what is it with those weird version numbers anyway? You know you could also make it 0.10 .

@gsnedders
Copy link
Member

That's #72 and #110. The sanitizer now exists only as a filter for the treewalkers, rather than something touching the tokenizer in odd ways that was likely broken.

Our state of terrible documentation probably doesn't help here, and the changelog entry is rather useless in hindsight. The common-case is something like:

from html5lib import parse, serialize

def clean(s):
    d = parse(s)
    return serialize(s, sanitize=True)

(0.10 is less than 0.9999999, so no, that option's long gone.)

@macolo
Copy link

macolo commented Jul 18, 2016

You could make it 1.0 though. Counting the 9s makes me dizzy.

@DanielTate
Copy link

This is still not working.... Are there any real solutions to this?

@vhquang
Copy link

vhquang commented Mar 15, 2023

As a2917e9, sanitizer is moved into filters. So to import (as of version 1.1), you would do:

from html5lib.filters import sanitizer

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants