How to use the chameleon.core.utils.py_attr 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 / genshi / language.py View on Github external
attrib = self.attrib
        if name in attrib:
            value = attrib[name]
            del attrib[name]
            return value
        return default

    xi_href = None
    xi_parse = None
    py_once = "false"

class XHTMLElement(GenshiElement):
    """XHTML namespace element."""

    py_if = utils.attribute(
        utils.py_attr('if'), lambda p: p.expression)
    py_for = utils.attribute(
        utils.py_attr('for'), lambda p: p.definition)
    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)
github malthe / chameleon / src / chameleon / genshi / language.py View on Github external
def _add_define(self, variable, expression):
        name = utils.py_attr('with')
        define = "%s=%s; " % (variable, expression)

        if name in self.attrib:
            self.attrib[name] += define
        else:
            self.attrib[name] = define
github malthe / chameleon / src / chameleon / genshi / language.py View on Github external
xi_parse = None
    py_once = "false"

class XHTMLElement(GenshiElement):
    """XHTML namespace element."""

    py_if = utils.attribute(
        utils.py_attr('if'), lambda p: p.expression)
    py_for = utils.attribute(
        utils.py_attr('for'), lambda p: p.definition)
    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)
github malthe / chameleon / src / chameleon / genshi / language.py View on Github external
for element in elements:
                expression = element._pull_attribute(utils.py_attr('when'))
                variable = stream.new_var()
                variables.append(variable)

                # add definition to ancestor
                self._add_define(variable, expression)

                # add condition to element
                if choose_expression:
                    expression = "%s == %s" % (
                        choose_variable, variable)
                else:
                    expression = "%s" % variable

                element.attrib[utils.py_attr('if')] = expression

            # process any "py:otherwise"-controllers
            elements = get_elements_with_attribute_unless_in_between(
                self, config.PY_NS, "otherwise", "choose")

            for element in elements:
                if choose_expression:
                    expression = "%s not in %s" % (
                        choose_variable, repr(tuple(variables)))
                else:
                    expression = "not(%s)" % " or ".join(variables)

                element.attrib[utils.py_attr('if')] = expression
github malthe / chameleon / src / chameleon / genshi / language.py View on Github external
py_for = utils.attribute(
        utils.py_attr('for'), lambda p: p.definition)
    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'))
github malthe / chameleon / src / chameleon / genshi / language.py View on Github external
stream = self.stream
        choose_expression = self._pull_attribute(utils.py_attr('choose'))
        if choose_expression is not None:
            choose_variable = stream.new_var()
            
            if choose_expression:
                self._add_define(choose_variable, choose_expression)
                
            # select all elements that have the "py:when" controller,
            # unless a "py:choose" expression sits in-between
            elements = get_elements_with_attribute_unless_in_between(
                self, config.PY_NS, "when", "choose")

            variables = []
            for element in elements:
                expression = element._pull_attribute(utils.py_attr('when'))
                variable = stream.new_var()
                variables.append(variable)

                # add definition to ancestor
                self._add_define(variable, expression)

                # add condition to element
                if choose_expression:
                    expression = "%s == %s" % (
                        choose_variable, variable)
                else:
                    expression = "%s" % variable

                element.attrib[utils.py_attr('if')] = expression

            # process any "py:otherwise"-controllers
github malthe / chameleon / src / chameleon / genshi / language.py View on Github external
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)
    i18n_domain = utils.attribute(
        utils.i18n_attr('domain'))
    i18n_name = utils.attribute(
        utils.i18n_attr('name'))

class MetaElement(XHTMLElement, translation.MetaElement):
github malthe / chameleon / src / chameleon / genshi / language.py View on Github external
del attrib[name]
            return value
        return default

    xi_href = None
    xi_parse = None
    py_once = "false"

class XHTMLElement(GenshiElement):
    """XHTML namespace element."""

    py_if = utils.attribute(
        utils.py_attr('if'), lambda p: p.expression)
    py_for = utils.attribute(
        utils.py_attr('for'), lambda p: p.definition)
    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(