How to use the weasyprint.logger.LOGGER.warning function in weasyprint

To help you get started, we’ve selected a few weasyprint 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 Kozea / WeasyPrint / weasyprint / css / validation / descriptors.py View on Github external
tokens = remove_whitespace(descriptor.value)
        try:
            # Use list() to consume generators now and catch any error.
            if descriptor.name not in DESCRIPTORS:
                raise InvalidValues('descriptor not supported')

            function = DESCRIPTORS[descriptor.name]
            if function.wants_base_url:
                value = function(tokens, base_url)
            else:
                value = function(tokens)
            if value is None:
                raise InvalidValues
            result = ((descriptor.name, value),)
        except InvalidValues as exc:
            LOGGER.warning(
                'Ignored `%s:%s` at %i:%i, %s.',
                descriptor.name, tinycss2.serialize(descriptor.value),
                descriptor.source_line, descriptor.source_column,
                exc.args[0] if exc.args and exc.args[0] else 'invalid value')
            continue

        for long_name, value in result:
            yield long_name.replace('-', '_'), value
github Kozea / WeasyPrint / weasyprint / css / computed_values.py View on Github external
new_value = None
            else:
                prop = PROPERTIES[name.replace('_', '-')]
                if prop.wants_base_url:
                    new_value = prop(computed_value, base_url)
                else:
                    new_value = prop(computed_value)

            # See https://drafts.csswg.org/css-variables/#invalid-variables
            if new_value is None:
                try:
                    computed_value = ''.join(
                        token.serialize() for token in computed_value)
                except BaseException:
                    pass
                LOGGER.warning(
                    'Unsupported computed value `%s` set in variable `%s` '
                    'for property `%s`.', computed_value,
                    variable_name.replace('_', '-'), name.replace('_', '-'))
                if name in INHERITED and parent_style:
                    already_computed_value = True
                    value = parent_style[name]
                else:
                    already_computed_value = name not in INITIAL_NOT_COMPUTED
                    value = INITIAL_VALUES[name]
            else:
                value = new_value

        if function is not None and not already_computed_value:
            value = function(computer, name, value)
        # else: same as specified
github Kozea / WeasyPrint / weasyprint / html.py View on Github external
def parse_w3c_date(meta_name, string):
    """http://www.w3.org/TR/NOTE-datetime"""
    if W3C_DATE_RE.match(string):
        return string
    else:
        LOGGER.warning(
            'Invalid date in  %r', meta_name, string)
github Kozea / WeasyPrint / weasyprint / css / __init__.py View on Github external
base_url,
                        tinycss2.parse_declaration_list(margin_rule.content)))
                    if declarations:
                        selector_list = [(
                            specificity, '@' + margin_rule.lower_at_keyword,
                            page_type)]
                        page_rules.append(
                            (margin_rule, selector_list, declarations))

        elif rule.type == 'at-rule' and rule.lower_at_keyword == 'font-face':
            ignore_imports = True
            content = tinycss2.parse_declaration_list(rule.content)
            rule_descriptors = dict(preprocess_descriptors(base_url, content))
            for key in ('src', 'font_family'):
                if key not in rule_descriptors:
                    LOGGER.warning(
                        "Missing %s descriptor in '@font-face' rule at %s:%s",
                        key.replace('_', '-'),
                        rule.source_line, rule.source_column)
                    break
            else:
                if font_config is not None:
                    font_filename = font_config.add_font_face(
                        rule_descriptors, url_fetcher)
                    if font_filename:
                        fonts.append(font_filename)
github Kozea / WeasyPrint / weasyprint / formatting_structure / build.py View on Github external
counter_name, counter_values, missing_counters)
            counter_value = counter_values.get(counter_name, [0])[-1]
            texts.append(counters.format(counter_value, counter_style))
        elif type_ == 'counters()':
            counter_name, separator, counter_style = value
            if need_collect_missing:
                _collect_missing_counter(
                    counter_name, counter_values, missing_counters)
            texts.append(separator.join(
                counters.format(counter_value, counter_style)
                for counter_value in counter_values.get(counter_name, [0])))
        elif type_ == 'string()':
            if not in_page_context:
                # string() is currently only valid in @page context
                # See https://github.com/Kozea/WeasyPrint/issues/723
                LOGGER.warning(
                    '"string(%s)" is only allowed in page margins' %
                    (' '.join(value)))
                continue
            texts.append(context.get_string_set_for(page, *value) or '')
        elif type_ == 'target-counter()':
            anchor_token, counter_name, counter_style = value
            lookup_target = target_collector.lookup_target(
                anchor_token, parent_box, css_token, parse_again)
            if lookup_target.state == 'up-to-date':
                target_values = lookup_target.target_box.cached_counter_values
                if need_collect_missing:
                    _collect_missing_target_counter(
                        counter_name, target_values,
                        target_collector.anchor_name_from_token(anchor_token),
                        missing_target_counters)
                # Mixin target's cached page counters.
github Kozea / WeasyPrint / weasyprint / fonts.py View on Github external
os.close(fd)
                    self._filenames.append(conf_filename)
                    fontconfig.FcConfigParseAndLoad(
                        config, conf_filename.encode('ascii'), True)
                    font_added = fontconfig.FcConfigAppFontAddFile(
                        config, filename.encode('ascii'))
                    if font_added:
                        # TODO: We should mask local fonts with the same name
                        # too as explained in Behdad's blog entry.
                        # TODO: What about pango_fc_font_map_config_changed()
                        # as suggested in Behdad's blog entry?
                        # Though it seems to work without…
                        return filename
                    else:
                        LOGGER.debug('Failed to load font at "%s"', url)
            LOGGER.warning(
                'Font-face "%s" cannot be loaded',
                rule_descriptors['font_family'])