How to use the cssutils.util function in cssutils

To help you get started, we’ve selected a few cssutils examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github palexu / send2kindle / cssutils / stylesheets / medialist.py View on Github external
"""MediaList implements DOM Level 2 Style Sheets MediaList.

TODO:
    - delete: maybe if deleting from all, replace *all* with all others?
    - is unknown media an exception?
"""
__all__ = ['MediaList']
__docformat__ = 'restructuredtext'
__version__ = '$Id$'

from cssutils.css import csscomment
from mediaquery import MediaQuery
import cssutils
import xml.dom

class MediaList(cssutils.util.Base, cssutils.util.ListSeq):
    """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 :class:`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 :class:`MediaQuery`::

         [,  ]*
    """
    def __init__(self, mediaText=None, parentRule=None, readonly=False):
github kovidgoyal / calibre / src / cssutils / css / property.py View on Github external
"""Property is a single CSS property in a CSSStyleDeclaration."""
__all__ = ['Property']
__docformat__ = 'restructuredtext'
__version__ = '$Id: property.py 1811 2009-07-29 13:11:15Z cthedot $'

from cssutils.helper import Deprecated
from cssvalue import CSSValue
import cssutils
import xml.dom

class Property(cssutils.util.Base):
    """A CSS property in a StyleDeclaration of a CSSStyleRule (cssutils).

    Format::

        property = name
          : IDENT S*
          ;

        expr = value
          : term [ operator term ]*
          ;
        term
          : unary_operator?
            [ NUMBER S* | PERCENTAGE S* | LENGTH S* | EMS S* | EXS S* | ANGLE S* |
              TIME S* | FREQ S* | function ]
          | STRING S* | IDENT S* | URI S* | hexcolor
github palexu / send2kindle / cssutils / css / cssvariablesdeclaration.py View on Github external
"""CSSVariablesDeclaration
http://disruptive-innovations.com/zoo/cssvariables/#mozTocId496530
"""
__all__ = ['CSSVariablesDeclaration']
__docformat__ = 'restructuredtext'
__version__ = '$Id: cssstyledeclaration.py 1819 2009-08-01 20:52:43Z cthedot $'

from cssutils.prodparser import *
from cssutils.helper import normalize
from value import PropertyValue
import cssutils
import itertools
import xml.dom

class CSSVariablesDeclaration(cssutils.util._NewBase):
    """The CSSVariablesDeclaration interface represents a single block of
    variable declarations. 
    """
    def __init__(self, cssText=u'', parentRule=None, readonly=False):
        """
        :param cssText:
            Shortcut, sets CSSVariablesDeclaration.cssText
        :param parentRule:
            The CSS rule that contains this declaration block or
            None if this CSSVariablesDeclaration is not attached to a CSSRule.
        :param readonly:
            defaults to False
            
        Format::
        
            variableset
github palexu / send2kindle / cssutils / script.py View on Github external
def _createStyleSheet(self, href=None,
                          media=None,
                          parentStyleSheet=None,
                          title=u'',
                          cssText=None,
                          encoding=None):
        """
        Return CSSStyleSheet read from href or if cssText is given use that.

        encoding
            used if inline style found, same as self.docencoding
        """
        if cssText is None:
            encoding, enctype, cssText = cssutils.util._readUrl(href, parentEncoding=self.docencoding)
            encoding = None # already decoded???

        sheet = self._cssparser.parseString(cssText, href=href, media=media, title=title,
                                            encoding=encoding)

        if not sheet:
            return None

        else:
            self._log.info(u'    %s\n' % sheet)
            self._nonparsed[sheet] = cssText
            return sheet
github tito / pymt / pymt / lib / cssutils / css / cssstyledeclaration.py View on Github external
- simplify unit pairs/triples/quadruples
      2px 2px 2px 2px -> 2px for border/padding...
    - normalize compound properties like:
      background: no-repeat left url()  #fff
      -> background: #fff url() no-repeat left
"""
__all__ = ['CSSStyleDeclaration', 'Property']
__docformat__ = 'restructuredtext'
__version__ = '$Id: cssstyledeclaration.py 1658 2009-02-07 18:24:40Z cthedot $'

from cssproperties import CSS2Properties
from property import Property
import cssutils
import xml.dom

class CSSStyleDeclaration(CSS2Properties, cssutils.util.Base2):
    """The CSSStyleDeclaration class represents a single CSS declaration
    block. This class may be used to determine the style properties
    currently set in a block or to set style properties explicitly
    within the block.

    While an implementation may not recognize all CSS properties within
    a CSS declaration block, it is expected to provide access to all
    specified properties in the style sheet through the
    CSSStyleDeclaration interface.
    Furthermore, implementations that support a specific level of CSS
    should correctly handle CSS shorthand properties for that level. For
    a further discussion of shorthand properties, see the CSS2Properties
    interface.

    Additionally the CSS2Properties interface is implemented.
github kovidgoyal / calibre / src / cssutils / parse.py View on Github external
def parseUrl(self, href, encoding=None, media=None, title=None):
        """Retrieve content from URL `href` and parse it. Errors may be raised
        (e.g. URLError).
        
        :param href:
            URL of the CSS file to parse, will also be set as ``href`` of
            resulting stylesheet
        :param encoding:
            Value ``None`` defaults to encoding detection via HTTP, BOM or an
            @charset rule.
            A value overrides detected encoding for the sheet at ``href``
            including any imported sheets.
        :returns:
            :class:`~cssutils.css.CSSStyleSheet`.
        """
        encoding, enctype, text = cssutils.util._readUrl(href,
                                                         overrideEncoding=encoding)
        if enctype == 5:
            # do not used if defaulting to UTF-8
            encoding = None
            
        if text is not None:
            return self.parseString(text, encoding=encoding,
                                    href=href, media=media, title=title)
github palexu / send2kindle / cssutils / parse.py View on Github external
validate=None):
        """Retrieve content from URL `href` and parse it. Errors may be raised
        (e.g. URLError).

        :param href:
            URL of the CSS file to parse, will also be set as ``href`` of
            resulting stylesheet
        :param encoding:
            Value ``None`` defaults to encoding detection via HTTP, BOM or an
            @charset rule.
            A value overrides detected encoding for the sheet at ``href``
            including any imported sheets.
        :returns:
            :class:`~cssutils.css.CSSStyleSheet`.
        """
        encoding, enctype, text = cssutils.util._readUrl(href,
                                                         fetcher=self.__fetcher,
                                                         overrideEncoding=encoding)
        if enctype == 5:
            # do not use if defaulting to UTF-8
            encoding = None

        if text is not None:
            return self.parseString(text, encoding=encoding,
                                    href=href, media=media, title=title,
                                    validate=validate)
github mozilla / spade / vendor / cssutils / css / cssvalue.py View on Github external
"""
__all__ = ['CSSValue', 'CSSPrimitiveValue', 'CSSValueList', 'RGBColor',
           'CSSVariable']
__docformat__ = 'restructuredtext'
__version__ = '$Id$'

from cssutils.prodparser import *
import cssutils
import cssutils.helper
import math
import re
import xml.dom


class CSSValue(cssutils.util._NewBase):
    """The CSSValue interface represents a simple or a complex value.
    A CSSValue object only occurs in a context of a CSS property.
    """

    # The value is inherited and the cssText contains "inherit".
    CSS_INHERIT = 0
    # The value is a CSSPrimitiveValue.
    CSS_PRIMITIVE_VALUE = 1
    # The value is a CSSValueList.
    CSS_VALUE_LIST = 2
    # The value is a custom value.
    CSS_CUSTOM = 3
    # The value is a CSSVariable.
    CSS_VARIABLE = 4

    _typestrings = {0: 'CSS_INHERIT' ,
github kovidgoyal / calibre / src / cssutils / css / selectorlist.py View on Github external
Illegal example(s):

        For example, since the "&" is not a valid token in a CSS2 selector,
        a CSS2 user agent must ignore the whole second line, and not set
        the color of H3 to red:
"""
__all__ = ['SelectorList']
__docformat__ = 'restructuredtext'
__version__ = '$Id: selectorlist.py 1868 2009-10-17 19:36:54Z cthedot $'

from selector import Selector
import cssutils
import xml.dom

class SelectorList(cssutils.util.Base, cssutils.util.ListSeq):
    """A list of :class:`~cssutils.css.Selector` objects
    of a :class:`~cssutils.css.CSSStyleRule`."""
    def __init__(self, selectorText=None, parentRule=None,
                 readonly=False):
        """
        :Parameters:
            selectorText
                parsable list of Selectors
            parentRule
                the parent CSSRule if available
        """
        super(SelectorList, self).__init__()

        self._parentRule = parentRule

        if selectorText:
github tito / pymt / pymt / lib / cssutils / stylesheets / mediaquery.py View on Github external
"""Implements a DOM for MediaQuery, see
http://www.w3.org/TR/css3-mediaqueries/.

A cssutils implementation, not defined in official DOM.
"""
__all__ = ['MediaQuery']
__docformat__ = 'restructuredtext'
__version__ = '$Id: mediaquery.py 1638 2009-01-13 20:39:33Z cthedot $'

import cssutils
import re
import xml.dom

class MediaQuery(cssutils.util.Base):
    """
    A Media Query consists of one of :const:`MediaQuery.MEDIA_TYPES`
    and one or more expressions involving media features.

    Format::

        media_query: [[only | not]?  [ and  ]*]
          |  [ and  ]*
        expression: (  [: ]? )
        media_type: all | aural | braille | handheld | print |
          projection | 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