How to use the diazo.utils.pkg_xsl function in diazo

To help you get started, we’ve selected a few diazo 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 plone / diazo / lib / diazo / compiler.py View on Github external
def set_parser(stylesheet, parser, compiler_parser=None):
    file_obj = pkg_resources.resource_filename('diazo', 'dummy.html')
    with open(file_obj) as file_handler:
        dummy_doc = etree.parse(
            file_handler,
            parser=parser,
        )
    name = 'file:///__diazo__'
    resolver = CustomResolver({name: stylesheet})
    if compiler_parser is None:
        compiler_parser = etree.XMLParser()
    compiler_parser.resolvers.add(resolver)
    identity = pkg_xsl('identity.xsl', compiler_parser)
    output_doc = identity(dummy_doc, docurl="'{name}'".format(name=name))
    compiler_parser.resolvers.remove(resolver)
    return output_doc
github plone / diazo / lib / diazo / runtrace.py View on Github external
#!/usr/bin/env python
import logging

from diazo.rules import process_rules
from diazo.utils import pkg_xsl

from lxml import etree
from xml.etree import ElementTree

logger = logging.getLogger('diazo')

_runtrace_to_html = pkg_xsl('runtrace_to_html.xsl')

def log_to_xml_string(error_log):
    return """
%s
    """ % "".join(l.message for l
                               in error_log
                               if l.message.startswith('
github plone / diazo / lib / diazo / rules.py View on Github external
CONDITIONAL_SRC = re.compile(
    r"""(?P<[^>]*?(src|href)=(?P['"]?))"""
    r"""(?P[^ \t\n\r\f\v>]+)(?P(?P=quote)[^>]*?>)""",
    re.IGNORECASE,
)
SRCSET = re.compile(r'(?P^\s*|\s*,\s*)(?P[^\s]*)')


update_transform = pkg_xsl('update-namespace.xsl')
normalize_rules = pkg_xsl('normalize-rules.xsl')
include = pkg_xsl('include.xsl')
apply_conditions = pkg_xsl('apply-conditions.xsl')
merge_conditions = pkg_xsl('merge-conditions.xsl')
annotate_themes = pkg_xsl('annotate-themes.xsl')
annotate_rules = pkg_xsl('annotate-rules.xsl')
apply_rules = pkg_xsl('apply-rules.xsl')
fixup_themes = pkg_xsl('fixup-themes.xsl')


def anchor_safe_urljoin(base, url):
    """Join the base with the url only when the url doesn't start with '#'"""
    if url.startswith('#'):
        return url
    else:
        return urljoin(base, url)


def add_identifiers(rules_doc):
    """Add identifiers to the rules for debugging"""
    for index, elem in enumerate(
        rules_doc.xpath(
            '//diazo:rules | //diazo:rules/diazo:*'
github plone / diazo / lib / diazo / rules.py View on Github external
usage = __doc__

IMPORT_STYLESHEET = re.compile(
    r"""(?P@import[ \t]+(?Purl\([ \t]?)?(?P['"]?))"""
    r"""(?P\S+)(?P(?P=quote)(?(paren)\)))""",
    re.IGNORECASE,
)
CONDITIONAL_SRC = re.compile(
    r"""(?P<[^>]*?(src|href)=(?P['"]?))"""
    r"""(?P[^ \t\n\r\f\v>]+)(?P(?P=quote)[^>]*?>)""",
    re.IGNORECASE,
)
SRCSET = re.compile(r'(?P^\s*|\s*,\s*)(?P[^\s]*)')


update_transform = pkg_xsl('update-namespace.xsl')
normalize_rules = pkg_xsl('normalize-rules.xsl')
include = pkg_xsl('include.xsl')
apply_conditions = pkg_xsl('apply-conditions.xsl')
merge_conditions = pkg_xsl('merge-conditions.xsl')
annotate_themes = pkg_xsl('annotate-themes.xsl')
annotate_rules = pkg_xsl('annotate-rules.xsl')
apply_rules = pkg_xsl('apply-rules.xsl')
fixup_themes = pkg_xsl('fixup-themes.xsl')


def anchor_safe_urljoin(base, url):
    """Join the base with the url only when the url doesn't start with '#'"""
    if url.startswith('#'):
        return url
    else:
        return urljoin(base, url)
github plone / diazo / lib / diazo / rules.py View on Github external
IMPORT_STYLESHEET = re.compile(
    r"""(?P@import[ \t]+(?Purl\([ \t]?)?(?P['"]?))"""
    r"""(?P\S+)(?P(?P=quote)(?(paren)\)))""",
    re.IGNORECASE,
)
CONDITIONAL_SRC = re.compile(
    r"""(?P<[^>]*?(src|href)=(?P['"]?))"""
    r"""(?P[^ \t\n\r\f\v>]+)(?P(?P=quote)[^>]*?>)""",
    re.IGNORECASE,
)
SRCSET = re.compile(r'(?P^\s*|\s*,\s*)(?P[^\s]*)')


update_transform = pkg_xsl('update-namespace.xsl')
normalize_rules = pkg_xsl('normalize-rules.xsl')
include = pkg_xsl('include.xsl')
apply_conditions = pkg_xsl('apply-conditions.xsl')
merge_conditions = pkg_xsl('merge-conditions.xsl')
annotate_themes = pkg_xsl('annotate-themes.xsl')
annotate_rules = pkg_xsl('annotate-rules.xsl')
apply_rules = pkg_xsl('apply-rules.xsl')
fixup_themes = pkg_xsl('fixup-themes.xsl')


def anchor_safe_urljoin(base, url):
    """Join the base with the url only when the url doesn't start with '#'"""
    if url.startswith('#'):
        return url
    else:
        return urljoin(base, url)
github plone / diazo / lib / diazo / rules.py View on Github external
r"""(?P@import[ \t]+(?Purl\([ \t]?)?(?P['"]?))"""
    r"""(?P\S+)(?P(?P=quote)(?(paren)\)))""",
    re.IGNORECASE,
)
CONDITIONAL_SRC = re.compile(
    r"""(?P<[^>]*?(src|href)=(?P['"]?))"""
    r"""(?P[^ \t\n\r\f\v>]+)(?P(?P=quote)[^>]*?>)""",
    re.IGNORECASE,
)
SRCSET = re.compile(r'(?P^\s*|\s*,\s*)(?P[^\s]*)')


update_transform = pkg_xsl('update-namespace.xsl')
normalize_rules = pkg_xsl('normalize-rules.xsl')
include = pkg_xsl('include.xsl')
apply_conditions = pkg_xsl('apply-conditions.xsl')
merge_conditions = pkg_xsl('merge-conditions.xsl')
annotate_themes = pkg_xsl('annotate-themes.xsl')
annotate_rules = pkg_xsl('annotate-rules.xsl')
apply_rules = pkg_xsl('apply-rules.xsl')
fixup_themes = pkg_xsl('fixup-themes.xsl')


def anchor_safe_urljoin(base, url):
    """Join the base with the url only when the url doesn't start with '#'"""
    if url.startswith('#'):
        return url
    else:
        return urljoin(base, url)


def add_identifiers(rules_doc):
github plone / diazo / lib / diazo / compiler.py View on Github external
known_params_url = 'file:///__diazo_known_params__'
    emit_stylesheet_resolver = CustomResolver({
        known_params_url: etree.tostring(known_params),
    })
    emit_stylesheet_parser = etree.XMLParser()
    emit_stylesheet_parser.resolvers.add(emit_stylesheet_resolver)

    # Set up parameters
    params = {}
    if indent is not None:
        params['indent'] = indent and "'yes'" or "'no'"
    params['known_params_url'] = quote_param(known_params_url)
    params['runtrace'] = '1' if runtrace else '0'

    # Run the final stage compiler
    emit_stylesheet = pkg_xsl(
        'emit-stylesheet.xsl',
        parser=emit_stylesheet_parser,
    )
    compiled_doc = emit_stylesheet(rules_doc, **params)
    compiled_doc = set_parser(
        etree.tostring(compiled_doc),
        parser,
        compiler_parser,
    )

    return compiled_doc