css – CSS related functions

This module contains functions related to the handling of CSS.

ll.xist.css.replaceurls(stylesheet, replacer)[source]

Replace all URLs appearing in the CSSStyleSheet stylesheet. For each URL the function replacer will be called and the URL will be replaced with the result.

ll.xist.css.geturls(stylesheet)[source]

Return a list of all URLs appearing in the CSSStyleSheet stylesheet.

ll.xist.css.iterrules(node, base=None, media=None, title=None)[source]

Return an iterator for all CSS rules defined in the HTML tree node. This will parse the CSS defined in any html.style or html.link element (and recursively in those stylesheets imported via the @import rule). The rules will be returned as CSSStyleRule objects from the cssutils package (so this requires cssutils).

The base argument will be used as the base URL for parsing the stylesheet references in the tree (so None means the URLs will be used exactly as they appear in the tree). All URLs in the style properties will be resolved.

If media is given, only rules that apply to this media type will be produced.

title can be used to specify which stylesheet group should be used. If title is None only the persistent and preferred stylesheets will be used. If title is a string only the persistent stylesheets and alternate stylesheets with that style name will be used.

For a description of “persistent”, “preferred” and “alternate” stylesheets see <http://www.w3.org/TR/2002/WD-xhtml2-20020805/mod-styleSheet.html#sec_20.1.2.>

ll.xist.css.applystylesheets(node, base=None, media=None, title=None)[source]

applystylesheets() modifies the XIST tree node by removing all CSS (from html.link and html.style elements and their @imported stylesheets) and putting the resulting style properties into the style attribute of every affected element instead.

For the meaning of base, media and title see iterrules().

class ll.xist.css.CSSWeightedSelector[source]

Bases: ll.xist.xfind.Selector

Base class for all CSS pseudo-class selectors.

class ll.xist.css.CSSHasAttributeSelector(attributename)[source]

Bases: ll.xist.css.CSSWeightedSelector

A CSSHasAttributeSelector selector selects all element nodes that have an attribute with the specified XML name.

__init__(attributename)[source]

Initialize self. See help(type(self)) for accurate signature.

__contains__(path)[source]

Return whether path (which is a list of XIST nodes from the root of the tree to the node in question) matches the selector.

__str__()[source]

Return str(self).

class ll.xist.css.CSSAttributeListSelector(attributename, attributevalue)[source]

Bases: ll.xist.css.CSSWeightedSelector

A CSSAttributeListSelector selector selects all element nodes where an attribute with the specified XML name has the specified word among the white space-separated list of words in the attribute value.

__init__(attributename, attributevalue)[source]

Initialize self. See help(type(self)) for accurate signature.

__contains__(path)[source]

Return whether path (which is a list of XIST nodes from the root of the tree to the node in question) matches the selector.

__str__()[source]

Return str(self).

class ll.xist.css.CSSAttributeLangSelector(attributename, attributevalue)[source]

Bases: ll.xist.css.CSSWeightedSelector

A CSSAttributeLangSelector selector selects all element nodes where an attribute with the specified XML name either is exactly the specified value or starts with the specified value followed by "-".

__init__(attributename, attributevalue)[source]

Initialize self. See help(type(self)) for accurate signature.

__contains__(path)[source]

Return whether path (which is a list of XIST nodes from the root of the tree to the node in question) matches the selector.

__str__()[source]

Return str(self).

class ll.xist.css.CSSFirstChildSelector[source]

Bases: ll.xist.css.CSSWeightedSelector

A CSSFirstChildSelector selector selects all element nodes that are the first child of its parent.

__contains__(path)[source]

Return whether path (which is a list of XIST nodes from the root of the tree to the node in question) matches the selector.

__str__()[source]

Return str(self).

class ll.xist.css.CSSLastChildSelector[source]

Bases: ll.xist.css.CSSWeightedSelector

A CSSLastChildSelector selector selects all element nodes that are the last child of its parent.

__contains__(path)[source]

Return whether path (which is a list of XIST nodes from the root of the tree to the node in question) matches the selector.

__str__()[source]

Return str(self).

class ll.xist.css.CSSFirstOfTypeSelector[source]

Bases: ll.xist.css.CSSWeightedSelector

A CSSLastChildSelector selector selects all element nodes that are the first of its type among their siblings.

__contains__(path)[source]

Return whether path (which is a list of XIST nodes from the root of the tree to the node in question) matches the selector.

__str__()[source]

Return str(self).

class ll.xist.css.CSSLastOfTypeSelector[source]

Bases: ll.xist.css.CSSWeightedSelector

A CSSLastChildSelector selector selects all element nodes that are the last of its type among their siblings.

__contains__(path)[source]

Return whether path (which is a list of XIST nodes from the root of the tree to the node in question) matches the selector.

__str__()[source]

Return str(self).

class ll.xist.css.CSSOnlyChildSelector[source]

Bases: ll.xist.css.CSSWeightedSelector

A CSSOnlyChildSelector selector selects all element nodes that are the only element among its siblings.

__contains__(path)[source]

Return whether path (which is a list of XIST nodes from the root of the tree to the node in question) matches the selector.

__str__()[source]

Return str(self).

class ll.xist.css.CSSOnlyOfTypeSelector[source]

Bases: ll.xist.css.CSSWeightedSelector

A CSSOnlyOfTypeSelector selector selects all element nodes that are the only element of its type among its siblings.

__contains__(path)[source]

Return whether path (which is a list of XIST nodes from the root of the tree to the node in question) matches the selector.

__str__()[source]

Return str(self).

class ll.xist.css.CSSEmptySelector[source]

Bases: ll.xist.css.CSSWeightedSelector

A CSSEmptySelector selector selects all element nodes that are empty (i.e. they contain no elements or non-whitespace text).

__contains__(path)[source]

Return whether path (which is a list of XIST nodes from the root of the tree to the node in question) matches the selector.

__str__()[source]

Return str(self).

class ll.xist.css.CSSRootSelector[source]

Bases: ll.xist.css.CSSWeightedSelector

A CSSRootSelector selector selects the root element.

__contains__(path)[source]

Return whether path (which is a list of XIST nodes from the root of the tree to the node in question) matches the selector.

__str__()[source]

Return str(self).

class ll.xist.css.CSSLinkSelector[source]

Bases: ll.xist.css.CSSWeightedSelector

A CSSLinkSelector selector selects all HTML links.

__contains__(path)[source]

Return whether path (which is a list of XIST nodes from the root of the tree to the node in question) matches the selector.

__str__()[source]

Return str(self).

class ll.xist.css.CSSInvalidPseudoSelector[source]

Bases: ll.xist.css.CSSWeightedSelector

__contains__(path)[source]

Return whether path (which is a list of XIST nodes from the root of the tree to the node in question) matches the selector.

__str__()[source]

Return str(self).

class ll.xist.css.CSSHoverSelector[source]

Bases: ll.xist.css.CSSInvalidPseudoSelector

class ll.xist.css.CSSActiveSelector[source]

Bases: ll.xist.css.CSSInvalidPseudoSelector

class ll.xist.css.CSSVisitedSelector[source]

Bases: ll.xist.css.CSSInvalidPseudoSelector

class ll.xist.css.CSSFocusSelector[source]

Bases: ll.xist.css.CSSInvalidPseudoSelector

class ll.xist.css.CSSAfterSelector[source]

Bases: ll.xist.css.CSSInvalidPseudoSelector

class ll.xist.css.CSSBeforeSelector[source]

Bases: ll.xist.css.CSSInvalidPseudoSelector

class ll.xist.css.CSSFunctionSelector(value=None)[source]

Bases: ll.xist.css.CSSWeightedSelector

Base class of all CSS selectors that require an argument.

__init__(value=None)[source]

Initialize self. See help(type(self)) for accurate signature.

__str__()[source]

Return str(self).

class ll.xist.css.CSSNthChildSelector(value=None)[source]

Bases: ll.xist.css.CSSFunctionSelector

A CSSNthChildSelector selector selects all element nodes that are the n-th element among their siblings.

__contains__(path)[source]

Return whether path (which is a list of XIST nodes from the root of the tree to the node in question) matches the selector.

class ll.xist.css.CSSNthLastChildSelector(value=None)[source]

Bases: ll.xist.css.CSSFunctionSelector

A CSSNthLastChildSelector selector selects all element nodes that are the n-th last element among their siblings.

__contains__(path)[source]

Return whether path (which is a list of XIST nodes from the root of the tree to the node in question) matches the selector.

class ll.xist.css.CSSNthOfTypeSelector(value=None)[source]

Bases: ll.xist.css.CSSFunctionSelector

A CSSNthOfTypeSelector selector selects all element nodes that are the n-th of its type among their siblings.

__contains__(path)[source]

Return whether path (which is a list of XIST nodes from the root of the tree to the node in question) matches the selector.

class ll.xist.css.CSSNthLastOfTypeSelector(value=None)[source]

Bases: ll.xist.css.CSSFunctionSelector

A CSSNthOfTypeSelector selector selects all element nodes that are the n-th last of its type among their siblings.

__contains__(path)[source]

Return whether path (which is a list of XIST nodes from the root of the tree to the node in question) matches the selector.

class ll.xist.css.CSSTypeSelector(type=None, xmlns=None, *selectors)[source]

Bases: ll.xist.xfind.Selector

__init__(type=None, xmlns=None, *selectors)[source]

Initialize self. See help(type(self)) for accurate signature.

__contains__(path)[source]

Return whether path (which is a list of XIST nodes from the root of the tree to the node in question) matches the selector.

__str__()[source]

Return str(self).

class ll.xist.css.CSSAdjacentSiblingCombinator(left, right)[source]

Bases: ll.xist.xfind.BinaryCombinator

A CSSAdjacentSiblingCombinator works similar to an AdjacentSiblingCombinator except that only preceding elements are considered.

__contains__(path)[source]

Return whether path (which is a list of XIST nodes from the root of the tree to the node in question) matches the selector.

__str__()[source]

Return str(self).

class ll.xist.css.CSSGeneralSiblingCombinator(left, right)[source]

Bases: ll.xist.xfind.BinaryCombinator

A CSSGeneralSiblingCombinator works similar to an xfind.GeneralSiblingCombinator except that only preceding elements are considered.

__contains__(path)[source]

Return whether path (which is a list of XIST nodes from the root of the tree to the node in question) matches the selector.

__str__()[source]

Return str(self).

ll.xist.css.selector(selectors, prefixes=None)[source]

Create a xfind.Selector object that matches all nodes that match the specified CSS selector expression. selectors can be a string or a cssutils.css.selector.Selector object. prefixes may be a mapping mapping namespace prefixes to namespace names.

ll.xist.css.parsestring(data, base=None, encoding=None)[source]

Parse the string data into a cssutils stylesheet. base is the base URL for the parsing process, encoding can be used to force the parser to use the specified encoding.

ll.xist.css.parsestream(stream, base=None, encoding=None)[source]

Parse a cssutils stylesheet from the stream stream. base is the base URL for the parsing process, encoding can be used to force the parser to use the specified encoding.

ll.xist.css.parsefile(filename, base=None, encoding=None)[source]

Parse a cssutils stylesheet from the file named filename. base is the base URL for the parsing process (defaulting to the filename itself), encoding can be used to force the parser to use the specified encoding.

ll.xist.css.parseurl(name, base=None, encoding=None, *args, **kwargs)[source]

Parse a cssutils stylesheet from the URL name. base is the base URL for the parsing process (defaulting to the final URL of the response, i.e. including redirects), encoding can be used to force the parser to use the specified encoding. arg and kwargs are passed on to URL.openread(), so you can pass POST data and request headers.