ANN: cssutils 0.9.3a1

Christof Hoeke cthedot at
Wed Sep 5 13:47:40 CEST 2007

what is it
A CSS Cascading Style Sheets library for Python.

Partly implements the DOM Level 2 Style Stylesheets and CSS interfaces. 
An implementation of the WD CSS Module: Namespaces which has no official 
DOM yet is included since v0.9.1.

changes since 0.9.2b4
for full details see the relevant README file

Lots of thanks to Walter Dörwald who had quite an influence on this 
release (thinking, helping, coding).

from the README:
     - FEATURE: Implemented css.CSSValue, css.CSSPrimitiveValue and 

         Not yet implemented are:
             - css.CSSPrimitiveValue.getCounterValue and css. Counter
             - css.CSSPrimitiveValue.getRGBColorValue and css.RGBColor
             - css.CSSPrimitiveValue.getRectValue and css.Rect

         + FEATURE: css.CSSValueList is iterable so may be used in a for 
         + FEATURE: CSSValue has property ``cssValueTypeString`` which 
is the name of the relevant ``cssValueType``, e.g. "CSS_PRIMITIVE_TYPE". 
Mainly useful for debugging.
         + FEATURE: CSSPrimitiveValue has property 
``primitiveTypeString`` which is the name of the relevant 
``primitiveType``, e.g. "CSS_PX". Mainly useful for debugging.
         + CSSValue has an init Parameter ``_propertyname`` to set a 
context property for validation. If none is set the value is always 
invalid. **THIS MAY CHANGE!**

     - FEATURE (**experimental**): CSSStyleDeclaration is iterable now. 
The iterator returns *all* properties set in this style as objects with 
properties ``name``, ``cssValue`` and ``priority``. Calling 
CSSStyleDeclaration.item(index) on the other hand simply returns a 
property name and also only the normalized name (once). Example::

             sheet = cssutils.parseString('a { color: red; c\olor: blue; 
left: 0 !important }')
             for rule in sheet.cssRules:
                 style =
                 for property in style:
                     name =
                     cssValue = property.cssValue
                     priority = property.priority
                     print name, '=', cssValue.cssText, priority

                 # prints:
                 # color = red
                 # c\olor = blue
                 # left = 0 !important

                 for i in range(0, style.length):
                     name = style.item(i)
                     cssValue = style.getPropertyCSSValue(name)
                     priority = style.getPropertyPriority(name)
                     print name, '=', cssValue.cssText , priority

                 # prints:
                 # color = blue
                 # left = 0 !important

     - FEATURE (**experimental**): added 
``CSSStyleSheet.replaceUrls(replacer)`` which may be used to adjust all 
"url()" values in a style sheet (currently in CSSStyleDeclaration and 

     - FEATURE: added ``CSSStyleDeclaration.getCssText(separator=None)`` 
which returns serialized property cssText, each property separated by 
given ``separator`` which may e.g. be u'' to be able to use cssText 
directly in an HTML style attribute. ";" is always part of each property 
(except the last one) and can **not** be set with separator!

     - FEATURE: ``href`` and ``media`` arguments can now be passed to 
``parse()`` and ``parseString()`` functions and methods. This sets the 
appropriate attributes on the generated stylesheet objects.

     - FEATURE: CSSMediaRule has an init parameter ``mediaText`` 
synchronous to CSSImportRule now

     - FEATURE: The ``MediaList`` constructor can now be passed a list 
of media types.

     - FEATURE: ``CSSRule`` and subclasses have a property 
``typeString`` which is the name of the relevant ``type``, e.g. 
``STYLE_RULE``. Mainly useful for debugging.

     - FEATURE: ``cssutils.serialize.Preferences`` has a new option 
``lineSeparator`` that is used as linefeed character(s). May also be set 
to ``u''`` for ``CSSStyleDeclareation.cssText'`` to be directly usable 
in e.g. HTML style attributes

     + API CHANGE (internal): renamed serializers method 
``do_stylesheet`` to ``do_CSSStyleSheet``

     - BUGFIX (issue #9): Parsing of empty ``url()`` values has been fixed
     - BUGFIX: Handling of linenumbers in the serializer has been fixed.
     - BUGFIX (minor): removed debug output in CSSStyleDeclaration

     + CHANGE (experimental!): CSSStyleDeclaration.getPropertyCSSValue() 
for shorthand properties like e.g. ``background`` should return None. 
cssutils returns a CSSValueList in these cases now. Use with care as 
this may change later

     + CHANGE: CSSValue default cssText is now ``u""`` and not 
``u"inherit"`` anymore

     + CHANGE: ``css.CSSStyleDeclaration.cssText`` indents its property 
not anymore.

     + CHANGE: ``cssutils.serialize.CSSSerializer`` has been refactored 
internally to support the lineSeparator option.

     + CHANGE: The Selector and SameNamePropertyList (which might be 
renamed as it is experimental) class are now available from cssutils.css 

     + CHANGE: Tokenizer strips HTML comment tokens CDO and CDC from 
tokenlist now.

     + CHANGE: Added __repr__ and __str__ methods to most classes. 
__str__ reports e.g. ``<cssutils.css.CSSImportRule object href=None at 
0xaaa870>``, __repr__  e.g. ``cssutils.css.CSSImportRule(href=None, 
mediaText=u'all')`` which is a valid contructor  for the object in most 
cases (which might not be complete for all init parameter for all 
classes like in this case though). The following details are included:

         - CSSStyleSheet shows the title and href
         - CSSCharsetRule shows the encoding
         - CSSCharsetRule shows the cssText (not in __str__ though)
         - CSSImportRule shows the href and the MediaList mediaText
         - CSSMediaRule shows the MediaList mediaText
         - CSSNameSpaceRule shows the prefix and uri
         - CSSPageRule shows the selectorText
         - CSSStyleRule shows the selectorText
         - CSSUnknownRule shows nothing special
         - CSSStyleDeclaration shows the number of properties set for 
__str__ but an empty CSSStyleDeclaration constructor for __repr__ as 
showing cssText might be way too much
         - SameNamePropertyList shows the name
         - CSSValue, CSSPrimitiveValue show the actual value for 
__repr__, some details for __str__
         - CSSValueList shows an __repr__ which is **not** possible to 
``eval()`` and some details for __str__
         - _Property shows infos but should be used directly for now anyway!
         - Selector the selectorText

         - MediaList shows the mediaText

cssutils is published under the LGPL.

for download options for cssutils 0.9.3a1 - 070905 see

cssutils needs
* Python 2.4 or higher (tested with Python 2.5 on Windows XP only)

bug reports, comments, etc are very much appreciated, (please use


More information about the Python-announce-list mailing list