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.4b1 $LastChangedRevision: 752 $

Date: $LastChangedDate: 2007-12-28 12:39:40 +0100 (Fr, 28 Dez 2007) $

Author: $LastChangedBy: cthedot $

Submodules | [hide private]
cssutils.codec: Python codec for CSS. cssutils.css: Document Object Model Level 2 CSS http://www.w3.org/TR/2000/PR-DOM-Level-2-Style-20000927/css.html cssutils.css.csscharsetrule: CSSCharsetRule implements DOM Level 2 CSS CSSCharsetRule. cssutils.css.csscomment: CSSComment is not defined in DOM Level 2 at all but a cssutils defined class only. cssutils.css.cssfontfacerule: CSSFontFaceRule implements DOM Level 2 CSS CSSFontFaceRule. cssutils.css.cssimportrule: CSSImportRule implements DOM Level 2 CSS CSSImportRule. cssutils.css.cssmediarule: CSSMediaRule implements DOM Level 2 CSS CSSMediaRule. cssutils.css.cssnamespacerule: CSSNamespaceRule currently implements http://www.w3.org/TR/2006/WD-css3-namespace-20060828/ cssutils.css.csspagerule: CSSPageRule implements DOM Level 2 CSS CSSPageRule. cssutils.css.cssproperties: CSS2Properties (partly!) implements DOM Level 2 CSS CSS2Properties used by CSSStyleDeclaration cssutils.css.cssrule: CSSRule implements DOM Level 2 CSS CSSRule. cssutils.css.cssrulelist: CSSRuleList implements DOM Level 2 CSS CSSRuleList. cssutils.css.cssstyledeclaration: CSSStyleDeclaration implements DOM Level 2 CSS CSSStyleDeclaration and inherits CSS2Properties cssutils.css.cssstylerule: CSSStyleRule implements DOM Level 2 CSS CSSStyleRule. cssutils.css.cssstylesheet: CSSStyleSheet implements DOM Level 2 CSS CSSStyleSheet. cssutils.css.cssunknownrule: CSSUnknownRule implements DOM Level 2 CSS CSSUnknownRule. cssutils.css.cssvalue: CSSValue related classes cssutils.css.property: Property is a single CSS property in a CSSStyleDeclaration cssutils.css.selector: Selector is a single Selector of a CSSStyleRule SelectorList. cssutils.css.selectorlist: SelectorList is a list of CSS Selector objects. cssutils.css2productions: productions for CSS 2.1 cssutils.css3productions: productions for CSS 3 cssutils.cssproductions: productions for cssutils based on a mix of CSS 2.1 and CSS 3 Syntax productions cssutils.errorhandler: cssutils ErrorHandler cssutils.parse': a validating CSSParser cssutils.scripts cssutils.scripts.csscapture: Retrieve all CSS stylesheets including embedded for a given URL. cssutils.scripts.csscombine: resolves imports in a given CSS proxy sheet cssutils.scripts.cssparse: utility scripts installed as Python scripts cssutils.serialize: serializer classes for CSS classes cssutils.stylesheets: Document Object Model Level 2 Style Sheets http://www.w3.org/TR/2000/PR-DOM-Level-2-Style-20000927/stylesheets.html cssutils.stylesheets.medialist: MediaList implements DOM Level 2 Style Sheets MediaList. cssutils.stylesheets.mediaquery: MediaQuery, see http://www.w3.org/TR/css3-mediaqueries/ cssutils.stylesheets.stylesheet: StyleSheet implements DOM Level 2 Style Sheets StyleSheet. cssutils.stylesheets.stylesheetlist: StyleSheetList implements DOM Level 2 Style Sheets StyleSheetList. cssutils.tests: cssutils unittests cssutils.tests.basetest: base class for all tests cssutils.tests.encutils: tests for encutils.py cssutils.tests.test_codec: testcases for cssutils.codec cssutils.tests.test_csscharsetrule: testcases for cssutils.css.CSSCharsetRule cssutils.tests.test_csscomment: testcases for cssutils.css.CSSComment cssutils.tests.test_cssfontfacerule: testcases for cssutils.css.CSSFontFaceRule cssutils.tests.test_cssimportrule: testcases for cssutils.css.CSSImportRule cssutils.tests.test_cssmediarule: testcases for cssutils.css.CSSMediaRule cssutils.tests.test_cssnamespacerule: testcases for cssutils.css.CSSImportRule cssutils.tests.test_csspagerule: testcases for cssutils.css.CSSPageRule cssutils.tests.test_cssproperties: Testcases for cssutils.css.cssproperties. cssutils.tests.test_cssrule: testcases for cssutils.css.CSSRule cssutils.tests.test_cssrulelist: testcases for cssutils.css.CSSRuleList cssutils.tests.test_cssstyledeclaration: Testcases for cssutils.css.cssstyledelaration.CSSStyleDeclaration. cssutils.tests.test_cssstylerule: testcases for cssutils.css.CSSStyleRuleTestCase cssutils.tests.test_cssstylesheet: tests for css.CSSStyleSheet cssutils.tests.test_cssunknownrule: testcases for cssutils.css.CSSUnkownRule cssutils.tests.test_cssutils: testcases for cssutils.css.CSSCharsetRule cssutils.tests.test_cssutilsimport: testcase for cssutils imports cssutils.tests.test_cssvalue: Testcases for cssutils.css.CSSValue and CSSPrimitiveValue. cssutils.tests.test_domimplementation: testcases for cssutils.css.DOMImplementation cssutils.tests.test_medialist: testcases for cssutils.stylesheets.MediaList cssutils.tests.test_mediaquery: testcases for cssutils.stylesheets.MediaList cssutils.tests.test_parse: tests for parsing which does not raise Exceptions normally cssutils.tests.test_property: Testcases for cssutils.css.property._Property. cssutils.tests.test_selector: Testcases for cssutils.css.selector.Selector. cssutils.tests.test_selectorlist: Testcases for cssutils.css.selectorlist.SelectorList. cssutils.tests.test_serialize: testcases for cssutils.CSSSerializer cssutils.tests.test_tokenize2: testcases for new cssutils.tokenize.Tokenizer cssutils.tests.test_util: testcases for cssutils.util cssutils.tokenize2: New CSS Tokenizer (a generator) cssutils.util: base classes for css and stylesheets packages

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