How to use the chameleon.core.config 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 / codegen.py View on Github external
"""

        if isinstance(node.value, ast.Name) and \
           (node.value.id.startswith('_') or node.value.id in SYMBOLS):
            return ASTTransformer.visit_Attribute(self, node)

        ## This should be spellable as
        ##         return ast.Call(
        ##             ast.Name(config.SYMBOLS.lookup_attr, ast.Load()),
        ##             [self.visit(node.value), ast.Str(node.attr)],
        ##             [], None, None)
        ## .. except Python 2.5 doesn't allow it.

        call = ast.Call()
        name = ast.Name()
        name.id = config.SYMBOLS.lookup_attr
        name.ctx = ast.Load()
        call.func = name
        string = ast.Str()
        string.s = node.attr
        args = [self.visit(node.value), string]
        call.args = args
        call.keywords = []
        call.starargs = None
        call.kwargs = None
        return call
github malthe / chameleon / src / chameleon / zpt / language.py View on Github external
def dynamic_attributes(self):
            attributes = []

            tal_attributes = utils.get_attributes_from_namespace(
                self.element, config.TAL_NS)
            metal_attributes = utils.get_attributes_from_namespace(
                self.element, config.METAL_NS)
            meta_attributes = utils.get_attributes_from_namespace(
                self.element, config.META_NS)
            i18n_attributes = utils.get_attributes_from_namespace(
                self.element, config.I18N_NS)

            internal = tuple(itertools.chain(
                tal_attributes, metal_attributes, meta_attributes, i18n_attributes))

            if self._interpolation_enabled:
                attributes.extend(self.interpolated_attributes(internal))

            if self.element.tal_attributes is not None:
                attributes.extend(self.element.tal_attributes)
github malthe / chameleon / src / chameleon / zpt / language.py View on Github external
from chameleon.core import types
from chameleon.core import utils

import expressions

class ZopePageTemplateElement(translation.Element):
    """Zope Page Template element.

    Implements the ZPT subset of the attribute template language.
    """

    strip_text = False

    class node(translation.Node):
        symbols = translation.Node.symbols(
            macros=config.TRANSIENT_SYMBOL)

        content_symbol = '_content'

        ns_omit = (
            "http://xml.zope.org/namespaces/meta",
            "http://xml.zope.org/namespaces/tal",
            "http://xml.zope.org/namespaces/metal",
            "http://xml.zope.org/namespaces/i18n")

        @property
        def _interpolation_enabled(self):
            return self.element.meta_interpolation in config.TRUEVALS + ('',)

        @property
        def _interpolation_escape(self):
            return self.element.meta_interpolation_escaping in config.TRUEVALS + ('',)
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 / genshi / language.py View on Github external
def _interpolation_enabled(self):
            return self.element.meta_interpolation in config.TRUEVALS + ('',)
github malthe / chameleon / src / chameleon / genshi / language.py View on Github external
element_mapping = {
        config.XHTML_NS: {None: XHTMLElement},
        config.META_NS: {None: MetaElement},
        config.XI_NS: {'include': XiIncludeElement},
        config.PY_NS: {'if': PyIfElement,
                       'for': PyForElement,
                       'def': PyDefElement,
                       'with': PyWithElement,
                       'match': PyMatchElement}}

    fallback = XHTMLElement

class TextParser(Parser):
    element_mapping = {
        config.XHTML_NS: {None: TextElement},
        }
github malthe / chameleon / src / chameleon / genshi / language.py View on Github external
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 = {
        config.XHTML_NS: {None: XHTMLElement},
        config.META_NS: {None: MetaElement},
        config.XI_NS: {'include': XiIncludeElement},
        config.PY_NS: {'if': PyIfElement,
                       'for': PyForElement,
                       'def': PyDefElement,
                       'with': PyWithElement,
                       'match': PyMatchElement}}

    fallback = XHTMLElement

class TextParser(Parser):
    element_mapping = {
        config.XHTML_NS: {None: TextElement},
        }
github malthe / chameleon / src / chameleon / genshi / language.py View on Github external
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 = {
        config.XHTML_NS: {None: XHTMLElement},
        config.META_NS: {None: MetaElement},
        config.XI_NS: {'include': XiIncludeElement},
        config.PY_NS: {'if': PyIfElement,
                       'for': PyForElement,
                       'def': PyDefElement,
                       'with': PyWithElement,
                       'match': PyMatchElement}}

    fallback = XHTMLElement

class TextParser(Parser):
    element_mapping = {
        config.XHTML_NS: {None: TextElement},
        }
github malthe / chameleon / src / chameleon / genshi / language.py View on Github external
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 = {
        config.XHTML_NS: {None: XHTMLElement},
        config.META_NS: {None: MetaElement},
        config.XI_NS: {'include': XiIncludeElement},
        config.PY_NS: {'if': PyIfElement,
                       'for': PyForElement,
                       'def': PyDefElement,
                       'with': PyWithElement,
                       'match': PyMatchElement}}

    fallback = XHTMLElement

class TextParser(Parser):
    element_mapping = {
        config.XHTML_NS: {None: TextElement},
        }
github malthe / chameleon / src / chameleon / zpt / language.py View on Github external
metal_extend = utils.attribute(
        ('extend-macro', utils.metal_attr('extend-macro')), lambda p: p.tales)
    metal_fillslot = utils.attribute(
        ('fill-slot', utils.metal_attr('fill-slot')))
    metal_defineslot = utils.attribute(
        ('define-slot', utils.metal_attr('define-slot')))

class TextElement(XHTMLElement):
    meta_interpolation_escaping = False

class Parser(etree.Parser):
    """Zope Page Template parser."""
    
    element_mapping = {
        config.XHTML_NS: {None: XHTMLElement},
        config.META_NS: {None: MetaElement},
        config.TAL_NS: {None: TALElement},
        config.METAL_NS: {None: METALElement}}

    fallback = XHTMLElement
    
    default_expression = 'python'

    def __init__(self, default_expression=None):
        if default_expression is not None:
            self.default_expression = default_expression

    def parse(self, body):
        tree = super(Parser, self).parse(body)
        tree.getroot().meta_translator = self.default_expression
        return tree