How to use the weasyprint.logger.LOGGER.error 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 / View on Github external
        # Attachments from document links like  or <a> can only be URLs.
        # They're passed in as tuples
        if isinstance(attachment, tuple):
            url, description = attachment
            attachment = Attachment(
                url=url, url_fetcher=url_fetcher, description=description)
        elif not isinstance(attachment, Attachment):
            attachment = Attachment(guess=attachment, url_fetcher=url_fetcher)

        with attachment.source as (source_type, source, url, _):
            if isinstance(source, bytes):
                source = io.BytesIO(source)
            file_stream_id = _write_compressed_file_object(pdf, source)
    except URLFetchingError as exc:
        LOGGER.error('Failed to load attachment: %s', exc)
        return None

    # TODO: Use the result object from a URL fetch operation to provide more
    # details on the possible filename
    filename = _get_filename_from_result(url, None)

    return pdf.write_new_object(pdf_format(
        '&lt;&lt; /Type /Filespec /F () /UF {0!P} /EF &lt;&lt; /F {1} 0 R &gt;&gt; '
        '/Desc {2!P}\n&gt;&gt;',
        attachment.description or ''))
github Kozea / WeasyPrint / weasyprint / View on Github external
base_url=base_url, url_fetcher=url_fetcher,
            **{type_: guess})
        with result as result:
            yield result
    elif filename is not None:
        if isinstance(filename, Path):
            filename = str(filename)
        if base_url is None:
            base_url = path2url(filename)
        with open(filename, 'rb') as file_obj:
            yield 'file_obj', file_obj, base_url, None
    elif url is not None:
        with fetch(url_fetcher, url) as result:
            if check_css_mime_type and result['mime_type'] != 'text/css':
                    'Unsupported stylesheet type %s for %s',
                    result['mime_type'], result['redirected_url'])
                yield 'string', '', base_url, None
                proto_encoding = result.get('encoding')
                if base_url is None:
                    base_url = result.get('redirected_url', url)
                if 'string' in result:
                    yield 'string', result['string'], base_url, proto_encoding
                    yield (
                        'file_obj', result['file_obj'], base_url,
    elif file_obj is not None:
        if base_url is None:
            # filesystem file-like objects have a 'name' attribute.
github Kozea / WeasyPrint / weasyprint / View on Github external
style.font_variant_position, style.font_variant_caps,
        style.font_variant_numeric, style.font_variant_alternates,
        style.font_variant_east_asian, style.font_feature_settings)
    if features:
        features = ','.join(
            ('%s %i' % (key, value)) for key, value in features.items())

        # TODO: attributes should be freed.
        # In the meantime, keep a cache to avoid leaking too many of them.
        attr = PANGO_ATTR_FONT_FEATURES_CACHE.get(features)
        if attr is None:
                attr = pango.pango_attr_font_features_new(
            except AttributeError:
                    'OpenType features are not available with Pango &lt; 1.38')
                PANGO_ATTR_FONT_FEATURES_CACHE[features] = attr
        if attr is not None:
            attr_list = pango.pango_attr_list_new()
            pango.pango_attr_list_insert(attr_list, attr)
            pango.pango_layout_set_attributes(layout.layout, attr_list)

    # Tabs width
    if style.tab_size != 8:  # Default Pango value is 8

    return layout
github Kozea / WeasyPrint / weasyprint / View on Github external
raise ImageLoadingError(
                            'Could not load GDK-Pixbuf. PNG and SVG are '
                            'the only image formats available.')
                        image = SVGImage(string, url, url_fetcher)
                    except BaseException:
                            surface, format_name = (
                        except pixbuf.ImageLoadingError as exception:
                            raise ImageLoadingError(str(exception))
                        if format_name == 'jpeg':
                            surface.set_mime_data('image/jpeg', string)
                        image = RasterImage(surface)
    except (URLFetchingError, ImageLoadingError) as exc:
        LOGGER.error('Failed to load image at "%s" (%s)', url, exc)
        image = None
    cache[url] = image
    return image
github Kozea / WeasyPrint / weasyprint / View on Github external
def url_join(base_url, url, allow_relative, context, context_args):
    """Like urllib.urljoin, but warn if base_url is required but missing."""
    if url_is_absolute(url):
        return iri_to_uri(url)
    elif base_url:
        return iri_to_uri(urljoin(base_url, url))
    elif allow_relative:
        return iri_to_uri(url)
        LOGGER.error('Relative URI reference without a base URI: ' + context,
        return None
github Kozea / WeasyPrint / weasyprint / css / View on Github external
url_fetcher=url_fetcher, media_type=device_media_type,
                font_config=font_config, page_rules=page_rules)
            yield css
        elif element.tag == 'link' and element.get('href'):
            if not element_has_link_type(element, 'stylesheet') or \
                    element_has_link_type(element, 'alternate'):
            href = get_url_attribute(element, 'href', base_url)
            if href is not None:
                    yield CSS(
                        url=href, url_fetcher=url_fetcher,
                        _check_mime_type=True, media_type=device_media_type,
                        font_config=font_config, page_rules=page_rules)
                except URLFetchingError as exc:
                        'Failed to load stylesheet at %s : %s', href, exc)