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

Source Code for Package cssutils

 1  #!/usr/bin/env python 
 2  """ 
 3  cssutils - CSS Cascading Style Sheets library for Python 
 4   
 5      Copyright (C) 2004-2007 Christof Hoeke 
 6   
 7      This library is free software; you can redistribute it and/or 
 8      modify it under the terms of the GNU Lesser General Public 
 9      License as published by the Free Software Foundation; either 
10      version 2.1 of the License, or (at your option) any later version. 
11   
12      This library is distributed in the hope that it will be useful, 
13      but WITHOUT ANY WARRANTY; without even the implied warranty of 
14      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
15      Lesser General Public License for more details. 
16   
17      You should have received a copy of the GNU Lesser General Public 
18      License along with this library; if not, write to the Free Software 
19      Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 
20   
21  A Python package to parse and build CSS Cascading Style Sheets. Partly 
22  implements the DOM Level 2 Stylesheets and DOM Level 2 CSS interfaces. 
23   
24  Please visit http://cthedot.de/cssutils/ for full details and updates. 
25   
26  Tested with Python 2.5 on Windows XP. 
27   
28   
29  This package is optimized for usage of ``from cssutils import *`` which 
30  import subpackages ``css`` and ``stylesheets``, the CSSParser and 
31  CSSSerializer classes only. 
32   
33  Usage may be:: 
34   
35      >>> from cssutils import * 
36      >>> parser = CSSParser() 
37      >>> sheet = parser.parseString(u'a { color: red}') 
38      >>> print sheet.cssText 
39   
40  """ 
41  __all__ = ['css', 'stylesheets', 
42             'CSSParser', 'CSSSerializer'] 
43  __docformat__ = 'restructuredtext' 
44  __author__ = '$LastChangedBy: doerwalter $' 
45  __date__ = '$LastChangedDate: 2007-08-06 18:33:45 +0200 (Mo, 06 Aug 2007) $' 
46  __version__ = '0.9.2b1 $LastChangedRevision: 177 $' 
47   
48  # log, internal use only TODO: make configurable 
49  # must be 1st import! 
50  import errorhandler 
51  log = errorhandler.ErrorHandler() 
52   
53  import util 
54   
55  # import subpackages and main classes 
56  import css 
57  import stylesheets 
58  from parse import CSSParser 
59  from serialize import CSSSerializer 
60  # serializer: configure cssutils.ser or set a custom serializer 
61  ser = CSSSerializer() 
62   
63  # parser helper functions 
64 -def parse(filename, encoding=None, href=None, media=None):
65 """ 66 reads file with given filename in given encoding (if given) 67 and returns CSSStyleSheet object 68 """ 69 parser = CSSParser() 70 return parser.parse(filename, encoding)
71
72 -def parseString(cssText, href=None, media=None):
73 """ 74 parses given string and returns CSSStyleSheet object 75 """ 76 parser = CSSParser() 77 return parser.parseString(cssText, href=href, media=media)
78 79 # set "ser", default serializer
80 -def setSerializer(serializer):
81 """ 82 sets the global serializer used by all class in cssutils 83 """ 84 global ser 85 ser = serializer
86 87 88 if __name__ == '__main__': 89 print __doc__ 90