Package cssutils.stylesheets#

Classes implementing Document Object Model Level 2 Style Sheets http://www.w3.org/TR/2000/PR-DOM-Level-2-Style-20000927/stylesheets.html

StyleSheet#

class cssutils.stylesheets.StyleSheet(type='text/css', href=None, media=None, title='', ownerNode=None, parentStyleSheet=None, alternate=False, disabled=None, validating=True)#

The StyleSheet interface is the abstract base interface for any type of style sheet. It represents a single style sheet associated with a structured document.

In HTML, the StyleSheet interface represents either an external style sheet, included via the HTML LINK element, or an inline STYLE element (also an @import stylesheet?).

In XML, this interface represents an external style sheet, included via a style sheet processing instruction.

property alternate#

Not used in cssutils yet.

property href#

If the style sheet is a linked style sheet, the value of this attribute is its location. For inline style sheets, the value of this attribute is None. See the href attribute definition for the LINK element in HTML 4.0, and the href pseudo-attribute for the XML style sheet processing instruction.

property ownerNode#

Not used in cssutils yet.

property parentStyleSheet#

For style sheet languages that support the concept of style sheet inclusion, this attribute represents the including style sheet, if one exists. If the style sheet is a top-level style sheet, or the style sheet language does not support inclusion, the value of this attribute is None.

property seq#

Internal readonly attribute, DO NOT USE!

property type#

This specifies the style sheet language for this style sheet. The style sheet language is specified as a content type (e.g. text/css). The content type is often specified in the ownerNode. Also see the type attribute definition for the LINK element in HTML 4.0, and the type pseudo-attribute for the XML style sheet processing instruction. For CSS this is always text/css.

StyleSheetList#

class cssutils.stylesheets.StyleSheetList(iterable=(), /)#

Interface StyleSheetList (introduced in DOM Level 2)

The StyleSheetList interface provides the abstraction of an ordered collection of StyleSheet objects.

The items in the StyleSheetList are accessible via an integral index, starting from 0.

This Python implementation is based on a standard Python list so e.g. allows examplelist[index] usage.

item(index)#

Used to retrieve a style sheet by ordinal index. If index is greater than or equal to the number of style sheets in the list, this returns None.

property length#

The number of StyleSheet objects in the list. The range of valid child stylesheet indices is 0 to length-1 inclusive.

MediaQuery#

class cssutils.stylesheets.MediaQuery(mediaText=None, readonly=False, _partof=False)#

A Media Query consists of one of MediaQuery.MEDIA_TYPES and one or more expressions involving media features.

Format:

media_query
 : [ONLY | NOT]? S* media_type S* [ AND S* expression ]*
 | expression [ AND S* expression ]*
 ;
media_type
 : IDENT
 ;
expression
 : '(' S* media_feature S* [ ':' S* expr ]? ')' S*
 ;
media_feature
 : IDENT
 ;
property mediaText#

The parsable textual representation of the media list.

property mediaType#

The media type of this MediaQuery (one of MEDIA_TYPES) but only if it is a simple MediaType!

property seq#

Internal readonly attribute, DO NOT USE!

MediaList#

class cssutils.stylesheets.MediaList(mediaText=None, parentRule=None, readonly=False)#

Provides the abstraction of an ordered collection of media, without defining or constraining how this collection is implemented.

A single media in the list is an instance of MediaQuery. An empty list is the same as a list that contains the medium “all”.

New format with MediaQuery:

: S* [media_query [ ',' S* media_query ]* ]?
append(newMedium)#

Same as appendMedium().

appendMedium(newMedium)#

Add the newMedium to the end of the list. If the newMedium is already used, it is first removed.

Parameters:

newMedium – a string or a MediaQuery

Returns:

Wellformedness of newMedium.

Exceptions:
  • InvalidCharacterErr: If the medium contains characters that are invalid in the underlying style language.

  • InvalidModificationErr: If mediaText is “all” and a new medium is tried to be added. Exception is “handheld” which is set in any case (Opera does handle “all, handheld” special, this special case might be removed in the future).

  • NoModificationAllowedErr: Raised if this list is readonly.

deleteMedium(oldMedium)#

Delete a medium from the list.

Parameters:

oldMedium – delete this medium from the list.

Exceptions:
item(index)#

Return the mediaType of the index’th element in the list. If index is greater than or equal to the number of media in the list, returns None.

property length#

The number of media in the list (DOM readonly).

property mediaText#

The parsable textual representation of the media list.

property parentRule#

The CSSRule (e.g. an @media or @import rule this list is part of or None

property seq#

Internal readonly attribute, DO NOT USE!