- **API CHANGE**: ``parse()`` is *DEPRECATED*, use ``parseFile()`` instead. I know this should not happen in a release already in beta but better now than later and currently both ways are still possible.
- **FEATURE**: CSSStyleDeclatation objects may be used like dictionaries now. The value during setting a property may be a single value string or a tuple of ``(value, priority)``::
>>> style = css.CSSStyleDeclaration()
>>> style['color'] = 'red'
>>> style.getProperties()
[cssutils.css.Property(name='color', value=u'red', priority=u'')]
>>> del style['color']
>>> style['unknown'] = ('value', 'important')
INFO Property: No CSS2 Property: 'unknown'.
>>> style.getProperties()
[cssutils.css.Property(name='unknown', value=u'value', priority=u'impor
tant')]
>>> del style['never-set'] does not raise KeyError but returns u'' like removeProperty()
>>>
- **FEATURE**: While reading an imported styleSheet all relevant encoding parameters (HTTP headers, BOM/charset, etc) are used now as defined in http://www.w3.org/TR/CSS21/syndata.html#charset
Additionally a given parameter ``encoding`` for ``parseString``, ``parseFile`` and ``parseUrl`` functions/methods **overrides** any detected encoding of read sheet like HTTP information or charset rules. Useful if e.g. HTTP information is not set properly. The given ``encoding`` is used for **all** imported sheets of the parsed one too! This is a cssutils only addition to the rules defined at http://www.w3.org/TR/CSS21/syndata.html#charset.
- **FEATURE**: A custom URL fetcher may be used during parsing via ``CSSParser.setFetcher(fetcher)`` (or as an init parameter). The so customized parser is reusable (as all parsers are). The fetcher is called when an ``import`` rule is found and the referenced stylesheet is about to be retrieved.
The function gets a single parameter
``url``
the URL to read
and MUST return ``(encoding, content)`` where ``encoding`` normally is the HTTP charset given via a Content-Type header (which may simply omit the charset though) and ``content`` being the (byte) string content. The Mimetype of the fetched ``url`` should be ``text/css`` but this has to be checked by the fetcher itself (the default fetcher emits an ERROR (from 0.9.5 before a WARNING) if encountering a different mimetype).
The content is then decoded by cssutils using all encoding related data available.
Example::
def fetcher(url):
return 'ascii', '/*test*/'
parser = cssutils.CSSParser(fetcher=fetcher)
parser.parse...
To omit parsing of imported sheets just define a fetcher like ``lambda url: None`` (A single None is sufficient but returning ``(None, None)`` is more explicit).
You might also want to define an encoding for each imported sheet with a fetcher which returns a (normally HTTP content-type header) encoding depending on each URL.
- **FEATURE**: Added option ``-s --string`` to cssparse script which expects a CSS string to be parsed.
- **FEATURE/BUGFIX**: Parsing of CSSStyleDeclarations is improved. Invalid ``/color: red;color: green`` is now correctly parsed as ``color: green`` now. At the same time the until now parsed but invalid ``$color: red`` (an IE hack) is not parse anymore but correctly dismissed!
Unknown rules in CSSStyleDeclaration are parsed now. So e.g ``x; color: red;`` which is syntactically valid is kept completely.
- **BUGFIX**: ``parseUrl`` does return ``None`` if an error occurs during reading the given URL. Until now an empty stylesheet was returned.
- **BUGFIX**: Fixed parsing of values like ``background: url(x.gif)0 0;`` (missing space but still valid).
- BUGFIX: Serializing CSSUnknownRules is slightly improved, blocks are correctly indentet now.
- **LICENSE**: cssutils is licensed under the **LGPL v3** now (before LGPL v2.1). This should not be a problem I guess but please be aware. So the former mix of LGPL 2.1 and 3 is resolved to a single LGPL 3 license for both cssutils and the included encutils.
- INTERNAL: Moved tests out of cssutils main package into a tests package parallel to cssutils.