ANN: cssutils v0.51 Released

chris csad7@yahoo.com
Mon, 12 Apr 2004 18:02:41 +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

kind request
   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
-----------------------
   there have been quite a few changes since the last release, for full 
details please see the changes.txt. But I think the API will be more 
stable from now on.

NEW
- implemented at least partly almost all DOM Level 2 CSS interfaces now
- complete rewrite of CSSParser including logging
	CSSParser writes all error messages to a log now.
	you can provide your own log.
	CSSParser might be configured just to log errors or to raise
	xml.dom.DOMExceptions when finding any bug
- most classes shifted to other submodules.
	please use the stable main modules
		cssutils.cssparser for parsing
		cssutils.cssbuilder for building
	only
- added unittests for most classes
- made a distribution package complete with setup.py

API CHANGES
- attribute style of class StyleRule made private (_style)
- REMOVED StyleRule.clearStyleDeclaration()
- REMOVED class Selector, integrated into rules now
- DEPRECATED StyleDeclaration.addProperty
- DEPRECATED cssrule.SimpleAtRule and empty now
   use subclasses of CSSRule (CharsetRule, ImportRule,
   FontFaceRule or PageRule) instead
- cssmediarule.MediaRule init parameter "medias" renamed to "media"
- Comment attribute "comment" renamed to "text"
- StyleSheet.getRules() returns a RuleList now


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


download
--------

   download cssutils v0.51 - 040412 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;
	    }
	}


thanks
christof hoeke http://cthedot.de


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