utilities — cssutils 0.9.8 documentation

### Navigation

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

# utilities

A few utility functions which may help when working with CSS stylesheets.

## `getUrls`

`cssutils.` `getUrls`(sheet)

  Retrieve all `url(urlstring)` values (in e.g. `cssutils.css.CSSImportRule` or `cssutils.css.CSSValue` objects of given sheet.

  Parameters: | sheet – `cssutils.css.CSSStyleSheet` object whose URLs are yielded

  This function is a generator. The generated URL values exclude `url(` and `)` and surrounding single or double quotes.

## `replaceUrls`

`cssutils.` `replaceUrls`(sheetOrStyle, replacer, ignoreImportRules=False)

  Replace all URLs in `cssutils.css.CSSImportRule` or `cssutils.css.CSSValue` objects of given sheetOrStyle.

  Parameters: | sheetOrStyle – a `cssutils.css.CSSStyleSheet` or a `cssutils.css.CSSStyleDeclaration` which is changed in place replacer – a function which is called with a single argument url which is the current value of each url() excluding `url(`, `)` and surrounding (single or double) quotes. ignoreImportRules – if `True` does not call replacer with URLs from @import rules.

## `resolveImports`

`cssutils.` `resolveImports`(sheet, target=None)

  Recurcively combine all rules in given sheet into a target sheet. @import rules which use media information are tried to be wrapped into @media rules so keeping the media information. This may not work in all instances (if e.g. an @import rule itself contains an @import rule with different media infos or if it contains rules which may not be used inside an @media block like @namespace rules.). In these cases the @import rule is kept as in the original sheet and a WARNING is issued.

  Parameters: | sheet – in this given `cssutils.css.CSSStyleSheet` all import rules are resolved and added to a resulting flat sheet. target – A `cssutils.css.CSSStyleSheet` object which will be the resulting flat sheet if given
  Returns: | given target or a new `cssutils.css.CSSStyleSheet` object

### Navigation

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