How to use the diazo.utils.CustomResolver 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
absolute_prefix=absolute_prefix,
        update=update,
        trace=trace,
        includemode=includemode,
        parser=parser,
        rules_parser=rules_parser,
        read_network=read_network,
    )

    # Build a document with all the  values to set the defaults
    # for every value passed in as xsl_params
    known_params = build_xsl_params_document(xsl_params)

    # Create a pseudo resolver for this
    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,
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