How to use the diazo.utils.namespaces 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 / rules.py View on Github external
def update_namespace(rules_doc):
    """Convert old namespace to new namespace in place
    """
    update = False
    for ns in (namespaces['old1'], namespaces['old2']):
        if rules_doc.xpath("//*[namespace-uri()='{ns:s}']".format(ns=ns)):
            logger.warning(
                'The %s namespace is deprecated, use %s instead.',
                ns,
                namespaces['diazo'],
            )
            update = True
    for ns in (namespaces['oldcss1'], namespaces['oldcss2']):
        if rules_doc.xpath("//@*[namespace-uri()='{ns:s}']".format(ns=ns)):
            logger.warning(
                'The %s namespace is deprecated, use %s instead.',
                ns,
                namespaces['css'],
            )
            update = True
    if update:
github plone / diazo / lib / diazo / rules.py View on Github external
def expand_themes(
    rules_doc,
    parser=None,
    absolute_prefix=None,
    read_network=False,
):
    """Expand  nodes with the theme html.
    """
    if absolute_prefix is None:
        absolute_prefix = ''
    base = rules_doc.docinfo.URL
    if parser is None:
        parser = etree.HTMLParser()
    for element in rules_doc.xpath(
        '//diazo:theme[@href]',
        namespaces=namespaces,
    ):
        url = urljoin(base, element.get('href'))
        if not read_network and \
                url.startswith(('ftp://', 'ftps://', 'http://', 'https://')):
            raise ValueError(
                "Supplied theme '{url}', but network access denied.".format(
                    url=url,
                ),
            )
        elif read_network and \
                url.startswith(('ftp://', 'ftps://', 'http://', 'https://')):
            theme = urlopen(url)
        else:
            theme = url
        theme_doc = etree.parse(theme, parser=parser, base_url=url)
        expand_theme(element, theme_doc, absolute_prefix)