ANN: cssutils v0.53

c. csad7@t-online.de
Sun, 18 Apr 2004 18:18:26 +0200


what is it
----------
   A Python package to parse and build CSS Cascading Style Sheets. 
Partly implement the DOM Level 2 CSS interfaces. Additional some 
cssutils only convenience and (hopefully) more pythonic methods are 
integrated.

   Thanks to Cory Dodt for helpful suggestions and some code patches and 
to David Mertz for his book ”Text Processing in Python“ and the included
statemachine.py which is used for cssutils

   Cssutils are far from being perfect or even complete, if you find 
bugs or have suggestions or problems please contact me.


changes in this release
-----------------------
   new cssunknownrule.UnknownRule (moved out of module cssrule)
   parser now creates Unknown At-Rules in the resulting StyleSheet. they
   are no longer just dumped and reported in the parser log.


license
-------
   cssutils is published under the LGPL.


download
--------

   download cssutils v0.53 - 040418 from http://cthedot.de/cssutils/

   Needs Python 2.3. Uses xml.dom.DOMException and subclasses so may 
need PyXML. Tested with Python 2.3.3 on Windows XP with PyXML 0.8.3 
installed.


examples
--------
parse a CSSStyleSheet
   Normally a CSS parser should ignore errors in a CSS stylesheet. So 
the default instantiation of CSSParser (parameter raiseExceptions=False) 
does not raise

any exceptions but writes all errors in a parsed CSS to a log file now. 
You might provide your own log with parameter log=YOURLOG.
This example does not use the log but would stop on the first error.

	from cssutils.cssparser import CSSParser
	p = CSSParser(raiseExceptions=True)
	try:
	    css = p.parseString('body { color :red }')
		#  or p.parse('filename.css')
	except xml.dom.DOMException, e:
	    print e
	css.pprint()            # prettyprinter s.b.

outputs

	body {
	    color: red;
	    }


build a new CSSStyleSheet
   Not all interfaces of DOM Level 2 CSS are implemented yet. But they 
will be provided in future versions of the cssbuilder module.
The following is a simple example how to build a CSSStyleSheet object.

	from cssutils.cssbuilder import *
	# init CSSStylesheet
	css = StyleSheet()
	
	# build a rule
	r = StyleRule()
	r.addSelector('body')
	r.addSelector('b') # a second one
	d = StyleDeclaration()
	d.setProperty('color', 'red') # old addProperty is DEPRECATED
	r.setStyleDeclaration(d)
	
	# build @media Rule
	mr = MediaRule(' print,   tv ')
	d = StyleDeclaration()
	d.setProperty('color', '#000')
	r = StyleRule('body', d)
	mr.addRule(r)
	
	# compose stylesheet
	css.addComment('basic styles')
	css.addComment('styles for print or tv')
	css.addRule(mr)
	css.insertRule(r, 1)
	
	# output
	css.pprint(2)

outputs

	/* basic styles */
	body, b {
	  color: red;
	  }
	/* styles for print or tv */
	@media print, tv {
	  body {
	    color: #000;
	    }
	}


christof hoeke http://cthedot.de

<P><A HREF="http://cthedot.de/cssutils/">cssutils 0.53</A> - a CSS 
Cascading Style Sheets library for Python (18-Apr-04)