How to use the chameleon.core.utils function in Chameleon

To help you get started, we’ve selected a few Chameleon 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 malthe / chameleon / src / chameleon / core / clauses.py View on Github external
stream.ensure_unicode(temp)
                stream.outdent()

                # escape expression
                stream.escape(temp, escape_double_quote=True)

                # print attribute
                stream.out(types.value(
                    "' %s=\"'+%s+'\"'" % (
                    attribute, temp)))

                stream.outdent()
                assign.end(stream)
            else:
                # escape expression
                value = utils.escape(value, '"', 'ascii')

                # if there are dynamic expressions, we only want to write
                # out static attributes if they're not in the dynamic
                # expression dictionary
                if self.expression:
                    stream.write("if '%s' not in %s:" % (
                        attribute, stream.symbols.tmp))
                    stream.indent()

                stream.out(' %s="%s"' % (attribute, value))

                if self.expression:
                    stream.outdent()

        stream.restore()
        stream.restore()
github malthe / chameleon / src / chameleon / genshi / language.py View on Github external
class PyElement(XHTMLElement):
    strip_text = True
    py_strip = utils.attribute("strip", lambda p: p.expression, u"")

class PyIfElement(PyElement):
    py_if = utils.attribute("test", lambda p: p.expression)

class PyForElement(PyElement):
    py_for = utils.attribute("each", lambda p: p.definition)

class PyWithElement(PyElement):
    py_with = utils.attribute(
        "vars", lambda p: expressions.translator.definitions)

class PyDefElement(PyElement):
    py_def = utils.attribute("function", lambda p: p.method)

class PyMatchElement(PyElement):
    py_match = utils.attribute("path")
    py_once = utils.attribute("once", default="false")

class XiIncludeElement(XHTMLElement):
    xi_href = utils.attribute("href")
    xi_parse = utils.attribute("parse", default="xml")

class TextElement(XHTMLElement):
    meta_interpolation_escaping = False

class Parser(etree.Parser):
    """The parser implementation for Genshi templates."""

    element_mapping = {
github malthe / chameleon / src / chameleon / genshi / language.py View on Github external
py_with = utils.attribute(utils.py_attr('with'),
        lambda p: expressions.translator.definitions)
    py_choose = utils.attribute(
        utils.py_attr('choose'), lambda p: p.expression)
    py_when = utils.attribute(
        utils.py_attr('when'), lambda p: p.expression)
    py_otherwise = utils.attribute(
        utils.py_attr('otherwise'), lambda p: p.expression)
    py_match = utils.attribute(
        utils.py_attr('match'))
    py_once = utils.attribute(
        utils.py_attr('once'), default='false')
    py_def = utils.attribute(
        utils.py_attr('def'), lambda p: p.method)
    py_attrs = utils.attribute(
        utils.py_attr('attrs'), lambda p: p.expression)
    py_content = utils.attribute(
        utils.py_attr('content'), lambda p: p.output)
    py_replace = utils.attribute(
        utils.py_attr('replace'), lambda p: p.output)
    py_strip = utils.attribute(
        utils.py_attr('strip'), lambda p: p.expression)
    meta_translator = etree.Annotation(
        utils.meta_attr('translator'))
    meta_interpolation = utils.attribute(
        utils.meta_attr('interpolation'), default='true', recursive=True)
    meta_interpolation_escaping = utils.attribute(
        utils.meta_attr('interpolation-escaping'), default='true', recursive=True)
    i18n_translate = utils.attribute(
        utils.i18n_attr('translate'))
    i18n_attributes = utils.attribute(
        utils.i18n_attr('attributes'), lambda p: p.mapping)
github malthe / chameleon / src / chameleon / genshi / language.py View on Github external
def get_elements_with_attribute_unless_in_between(element, ns, name, discard):
    elements = []

    discarded = utils.elements_with_attribute(element, ns, discard)
    subelements = utils.elements_with_attribute(element, ns, name)

    for subelement in subelements:
        parent = subelement.getparent()
        while parent is not None:
            if parent in discarded:
                break
            parent = parent.getparent()
        else:
            elements.append(subelement)

    return elements
github malthe / chameleon / src / chameleon / core / clauses.py View on Github external
def _maybe_validate(self, stream):
        # validate XML if enabled
        if config.VALIDATION:
            try:
                _et = utils.import_elementtree()
            except ImportError:
                raise ImportError(
                    "ElementTree (required when XML validation is enabled).")

            stream.symbol_mapping[stream.symbols.validate] = utils.validate
            stream.write("%(validate)s(%(tmp)s)" % stream.symbols.as_dict())
github malthe / chameleon / src / chameleon / core / clauses.py View on Github external
def _maybe_validate(self, stream):
        # validate XML if enabled
        if config.VALIDATION:
            try:
                _et = utils.import_elementtree()
            except ImportError:
                raise ImportError(
                    "ElementTree (required when XML validation is enabled).")

            stream.symbol_mapping[stream.symbols.validate] = utils.validate
            stream.write("%(validate)s(%(tmp)s)" % stream.symbols.as_dict())