Package cssutils.stylesheets — cssutils 0.9.8 documentation

### Navigation

- index
- modules |
- next |
- previous |
- cssutils 0.9.8 documentation »

# 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=u'', 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.

  `alternate`

    Not used in cssutils yet.

  `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.

  `ownerNode`

    Not used in cssutils yet.

  `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.

  `seq`

    Internal readonly attribute, DO NOT USE!

  `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`

  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`.

  `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)

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

  Format:

      media_query: [[only | not]? <media_type> [ and <expression> ]*]
        | <expression> [ and <expression> ]*
      expression: ( <media_feature> [: <value>]? )
      media_type: all | braille | handheld | print |
        projection | speech | screen | tty | tv | embossed
      media_feature: width | min-width | max-width
        | height | min-height | max-height
        | device-width | min-device-width | max-device-width
        | device-height | min-device-height | max-device-height
        | device-aspect-ratio | min-device-aspect-ratio | max-device-aspect-ratio
        | color | min-color | max-color
        | color-index | min-color-index | max-color-index
        | monochrome | min-monochrome | max-monochrome
        | resolution | min-resolution | max-resolution
        | scan | grid

  `mediaText`

    The parsable textual representation of the media list.

  `mediaType`

    The media type of this MediaQuery (one of `MEDIA_TYPES`).

## `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”.

  Format from CSS2.1:

      medium [ COMMA S* medium ]*

  New format with `MediaQuery`:

      <media_query> [, <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 : | `NotFoundErr`: Raised if oldMedium is not in the list. `NoModificationAllowedErr`: Raised if this list is readonly.

  `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`.

  `length`

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

  `mediaText`

    The parsable textual representation of the media list.

  `parentRule`

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

### Navigation

- index
- modules |
- next |
- previous |
- cssutils 0.9.8 documentation »