Package cssutils
[hide private]
[frames] | no frames]

Package cssutils

source code

cssutils - CSS Cascading Style Sheets library for Python

Copyright (C) 2004-2007 Christof Hoeke

This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

A Python package to parse and build CSS Cascading Style Sheets.

Based upon and partly implements the following specifications (DOM only, not any rendering facilities):

DOM Level 2 Style CSS
DOM for package css
DOM Level 2 Style Stylesheets
DOM for package stylesheets
CSSOM
A few details (mainly the NamespaceRule DOM) is taken from here. Plan is to move implementation to the stuff defined here which is newer but still no REC so might change in the future
CSS 2.1
Rules and properties are defined here
CSS 2.1 Errata
A few erratas, mainly the definition of CHARSET_SYM tokens
MediaQueries
MediaQueries are part of stylesheets.MediaList since v0.9.4, used in @import and @media rules.
Namespaces
Added in v0.9.1 and updated to definition in CSSOM in v0.9.4
Selectors
The selector syntax defined here (and not in CSS 2.1) should be parsable with cssutils (should mind though ;) )

Please visit http://cthedot.de/cssutils/ for full details and updates.

Tested with Python 2.5 on Windows XP.

This library is optimized for usage of from cssutils import * which import subpackages css and stylesheets, CSSParser and CSSSerializer classes only.

Usage may be:

>>> from cssutils import *
>>> parser = CSSParser()
>>> sheet = parser.parseString(u'a { color: red}')
>>> print sheet.cssText



Version: 0.9.4a3 $LastChangedRevision: 643 $

Date: $LastChangedDate: 2007-11-04 17:54:54 +0100 (So, 04 Nov 2007) $

Author: $LastChangedBy: cthedot $

Submodules [hide private]

Classes [hide private]
  CSSParser
parses a CSS StyleSheet string or file and returns a DOM Level 2 CSS StyleSheet object
  CSSSerializer
Methods to serialize a CSSStylesheet and its parts
  DOMImplementationCSS
This interface allows the DOM user to create a CSSStyleSheet outside the context of a document.
Functions [hide private]
 
parse(filename, encoding=None, href=None, media=None)
reads file with given filename in given encoding (if given) and returns CSSStyleSheet object
source code
 
parseString(cssText, href=None, media=None)
parses given string and returns CSSStyleSheet object
source code
 
setSerializer(serializer)
sets the global serializer used by all class in cssutils
source code
Variables [hide private]
  ser = CSSSerializer()

Imports: cssutils.codec, cssutils.cssproductions, cssutils.errorhandler, cssutils.serialize, cssutils.tokenize2, cssutils.util, xml