rennat / pynliner

Python CSS-to-inline-styles conversion tool for HTML using BeautifulSoup and cssutils
http://pythonhosted.org/pynliner/
181 stars 93 forks source link

patch to hide cssutils error messages #3

Closed ananelson closed 13 years ago

ananelson commented 13 years ago

I've added a few lines of code in pynliner/init.py which let you specify a custom log for cssutils. This prevents confusing/annoying error messages like:

ERROR Property: Invalid value for "CSS Fonts Module Level 3 @font-face properties/CSS Level 2.1" property: italic [13:10: font-weight]

from being written to stderr. I've written this so the default behaviour is unchanged, but if you specify a log then this is passed to cssutils.

For example, here is how I use this:

p = Pynliner()
if log:
    p.log = log
else:
    sys.stderr.write("You may see some harmless error messages generated by cssutils...\n")
p.from_string(html)
html_with_css_inline = p.run()

Sorry for the 2 commits, I accidentally committed the .swp file first time around.

rennat commented 13 years ago

A solid improvement! I think the log assignment should be moved to the Pynliner constructor as a keyword argument that defaults to None for consistency. Then please add a test to show a usage example and I'll pull it in. Thanks for the patch!

ananelson commented 13 years ago

Log assignment moved to Pynliner constructor and usage example added to tests, let me know if you need any tweaks.

rennat commented 13 years ago

looks good to me, thanks!