Package cssutils :: Module parse' :: Class CSSParser |
[hide private]
[frames] | no frames]

# Class CSSParser

source code

    object --+
             |
            CSSParser

parses a CSS StyleSheet string or file and returns a DOM Level 2 CSS StyleSheet object

Usage:

    parser = CSSParser()
    sheet = p.parse('test1.css', 'ascii')

    print sheet.cssText

Instance Methods | [hide private]
__init__(self, log=None, loglevel=None, raiseExceptions=False) logging object | source code
parseString(self, cssText, encoding=None, href=None, media=None, title=None) Return parsed CSSStyleSheet from given string cssText. | source code
parse(self, filename, encoding=None, href=None, media=None, title=None) Retrieve and return a CSSStyleSheet from given filename. | source code
parseUrl(self, href, encoding=None, media=None, title=None) Retrieve and return a CSSStyleSheet from given href (a URL). | source code
Inherited from `object`: `__delattr__`, `__getattribute__`, `__hash__`, `__new__`, `__reduce__`, `__reduce_ex__`, `__repr__`, `__setattr__`, `__str__`

Properties | [hide private]
Inherited from `object`: `__class__`

Method Details | [hide private]

### __init__(self, log=None, loglevel=None, raiseExceptions=False) (Constructor) | source code
log logging object loglevel logging loglevel raiseExceptions if log should simple log (default) or raise errors Overrides: object.__init__

### parseString(self, cssText, encoding=None, href=None, media=None, title=None) | source code
Return parsed CSSStyleSheet from given string cssText. cssText CSS string to parse encoding encoding of the CSS string. if `None` the encoding will be read from a @charset rule. If there is none, the parser will fall back to UTF-8. If cssText is a unicode string encoding will be ignored. href The href attribute to assign to the parsed style sheet. Used to resolve other urls in the parsed sheet like @import hrefs media The media attribute to assign to the parsed style sheet (may be a MediaList, list or a string) title The title attribute to assign to the parsed style sheet

### parse(self, filename, encoding=None, href=None, media=None, title=None) | source code
Retrieve and return a CSSStyleSheet from given filename. filename of the CSS file to parse, if no `href` is given filename is converted to a (file:) URL and set as `href` of resulting stylesheet. If href is given it is set as `sheet.href`. Either way `sheet.href` is used to resolve e.g. stylesheet imports via @import rules. encoding of the CSS file, `None` defaults to encoding detection from BOM or an @charset rule. `encoding` is used for the sheet at `filename` (and may override a file internal encoding) but not any imported sheets where the file internal encoding is detected. for other parameters see `parseString`

### parseUrl(self, href, encoding=None, media=None, title=None) | source code
Retrieve and return a CSSStyleSheet from given href (a URL). href URL of the CSS file to parse, will also be set as `href` of resulting stylesheet encoding if given overrides detected HTTP or file internal encoding for sheet at `href` but not any imported sheets where the encoding if always detected via HTTP or from the file. for other parameters see `parseString`