How to use the cssutils.log 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 / script.py View on Github external
`path` or `url` or `cssText` + `href`
            path or URL to a CSSStyleSheet or a cssText of a sheet which imports
            other sheets which are then combined into one sheet.
            `cssText` normally needs `href` to be able to resolve relative
            imports.
        `sourceencoding` = 'utf-8'
            explicit encoding of the source proxysheet
        `targetencoding`
            encoding of the combined stylesheet
        `minify` = True
            defines if the combined sheet should be minified, in this case
            comments are not parsed at all!
        `resolveVariables` = True
            defines if variables in combined sheet should be resolved
    """
    cssutils.log.info(u'Combining files from %r' % url, 
                      neverraise=True)
    if sourceencoding is not None:
        cssutils.log.info(u'Using source encoding %r' % sourceencoding,
                          neverraise=True)
        
    parser = cssutils.CSSParser(parseComments=not minify)
        
    if path and not cssText:
        src = parser.parseFile(path, encoding=sourceencoding)
    elif url:
        src = parser.parseUrl(url, encoding=sourceencoding)
    elif cssText:
        src = parser.parseString(cssText, href=href, encoding=sourceencoding)
    else:
        sys.exit('Path or URL must be given')
github mike820324 / microProxy / microproxy / viewer / formatter.py View on Github external
import json
from pygments import highlight
from pygments.lexers import get_lexer_by_name
from pygments.formatters import Terminal256Formatter

from gviewer import Text
from gviewer.util import pygmentize

try:
    from urllib import parse as urlparse
except ImportError:
    import urlparse

from microproxy.viewer.utils import ungzip

cssutils.log.setLevel(logging.CRITICAL)


def colorize(lexer_name, raw_text):  # pragma: no cover
    lexer = get_lexer_by_name(lexer_name, stripall=True)
    formatter = Terminal256Formatter()
    return highlight(raw_text, lexer, formatter)


class BaseFormatter(object):  # pragma: no cover
    def match(self, headers, content_type):
        return False

    def format_body(self, body):
        raise NotImplementedError

    def format_tui(self, body):
github palexu / send2kindle / calibre / ebooks / oeb / base.py View on Github external
def rewrite_links(root, link_repl_func, resolve_base_href=False):
    '''
    Rewrite all the links in the document.  For each link
    ``link_repl_func(link)`` will be called, and the return value
    will replace the old link.

    Note that links may not be absolute (unless you first called
    ``make_links_absolute()``), and may be internal (e.g.,
    ``'#anchor'``).  They can also be values like
    ``'mailto:email'`` or ``'javascript:expr'``.

    If the ``link_repl_func`` returns None, the attribute or
    tag text will be removed completely.
    '''
    from cssutils import replaceUrls, log, CSSParser
    log.setLevel(logging.WARN)
    log.raiseExceptions = False

    if resolve_base_href:
        resolve_base_href(root)
    for el, attrib, link, pos in iterlinks(root, find_links_in_css=False):
        new_link = link_repl_func(link.strip())
        if new_link == link:
            continue
        if new_link is None:
            # Remove the attribute or element content
            if attrib is None:
                el.text = ''
            else:
                del el.attrib[attrib]
            continue
        if attrib is None:
github Aristotle-Metadata-Enterprises / wcag-zoo / wcag_zoo / utils.py View on Github external
from __future__ import print_function
from lxml import etree
import click
import os
import sys
from io import BytesIO
import logging
from premailer import Premailer
from premailer.premailer import _cache_parse_css_string

# From Premailer
import cssutils
import re
cssutils.log.setLevel(logging.CRITICAL)
_element_selector_regex = re.compile(r'(^|\s)\w')
FILTER_PSEUDOSELECTORS = [':last-child', ':first-child', ':nth-child', ":focus"]


class Premoler(Premailer):
    def __init__(self, *args, **kwargs):
        self.media_rules = kwargs.pop('media_rules', [])
        super().__init__(*args, **kwargs)

    # We have to override this because an absolute path is from root, not the curent dir.
    def _load_external(self, url):
        """loads an external stylesheet from a remote url or local path
        """
        import codecs
        from premailer.premailer import ExternalNotFoundError, urljoin
        if url.startswith('//'):
github johnfraney / django-bootstrap-customizer / bootstrap_customizer / utils.py View on Github external
import cssutils
import logging
import os
import sass
from django.conf import settings
from django.contrib.staticfiles import finders
from django.template.loader import render_to_string


# Disable cssutils logging
cssutils.log.setLevel(logging.FATAL)
# Configure cssutils parsers to output minified CSS
cssutils.ser.prefs.useMinified()


def convert_fields_to_scss_variables(theme):
    """
    Converts the relevant fields from the supplied theme into a
    SCSS-compatible dict, e.g. {'$primary': '#007BFF'}
    """
    scss_fields = [f.name for f in theme._meta.fields if f.name not in theme.NON_SASS_FIELDS]
    scss_dict = dict()
    for f in scss_fields:
        scss_variable_name = '$' + f.replace('_', '-')
        scss_value = getattr(theme, f)
        # Make boolean values SCSS-friendly
        if type(scss_value) is bool:
github nueverest / blowdrycss / blowdrycss / blowdry.py View on Github external
- Generate Markdown documentation files.
    - Generate HTML documentation files. (This location is important since it allows encoded css to be included
      in the documentation files.)
    - Generate reStructuredText documentation files.

    :return: None

    """
    validate_output_file_name_setting()
    validate_output_extension_setting()

    if settings.logging_enabled:
        log.enable()

    if settings.hide_css_errors:
        cssutils.log.setLevel(logging.CRITICAL)

    # Generate Markdown documentation files.
    if settings.markdown_docs:
        markdown_file = GenericFile(                                        # Document forbidden clashing aliases.
            file_directory=settings.markdown_directory,
            file_name='clashing_aliases',
            extension='.md'
        )
        markdown_file.write(str(clashing_alias_markdown))
        markdown_file = GenericFile(                                        # Document allowed property aliases.
            file_directory=settings.markdown_directory,
            file_name='property_aliases',
            extension='.md'
        )
        markdown_file.write(str(property_alias_markdown))
github hsoft / pdfmasher / ebooks / oeb / base.py View on Github external
def rewrite_links(root, link_repl_func, resolve_base_href=False):
    '''
    Rewrite all the links in the document.  For each link
    ``link_repl_func(link)`` will be called, and the return value
    will replace the old link.

    Note that links may not be absolute (unless you first called
    ``make_links_absolute()``), and may be internal (e.g.,
    ``'#anchor'``).  They can also be values like
    ``'mailto:email'`` or ``'javascript:expr'``.

    If the ``link_repl_func`` returns None, the attribute or
    tag text will be removed completely.
    '''
    from cssutils import parseString, parseStyle, replaceUrls, log
    log.setLevel(logging.WARN)

    if resolve_base_href:
        resolve_base_href(root)
    for el, attrib, link, pos in iterlinks(root, find_links_in_css=False):
        new_link = link_repl_func(link.strip())
        if new_link == link:
            continue
        if new_link is None:
            # Remove the attribute or element content
            if attrib is None:
                el.text = ''
            else:
                del el.attrib[attrib]
            continue
        if attrib is None:
            new = el.text[:pos] + new_link + el.text[pos+len(link):]
github rennat / pynliner / pynliner / __init__.py View on Github external
def __init__(self, log=None, allow_conditional_comments=False,
                 preserve_entities=True):
        self.log = log
        cssutils.log.enabled = False if log is None else True
        self.extra_style_strings = []
        self.allow_conditional_comments = allow_conditional_comments
        self.preserve_entities = preserve_entities
        self.root_url = None
        self.relative_url = None
        self._substitutions = None
github mozilla / spade / vendor / cssutils / prodparser.py View on Github external
def __init__(self, clear=True):
        self.types = cssutils.cssproductions.CSSProductions
        self._log = cssutils.log
        if clear:
            tokenizer.clear()
github kovidgoyal / calibre / src / cssutils / parse.py View on Github external
def __parseSetting(self, parse):
        """during parse exceptions may be handled differently depending on
        init parameter ``raiseExceptions``
        """
        if parse:
            cssutils.log.raiseExceptions = self.__parseRaising
        else:
            cssutils.log.raiseExceptions = self.__globalRaising