How to use the varname.namedtuple function in varname

To help you get started, we’ve selected a few varname 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 pwwang / liquidpy / liquid / tags / tag_for.py View on Github external
"""Tag for

{% for   %}
...
{% endfor %}
"""
from varname import namedtuple
from ..tagmgr import register_tag
from ..tag import Tag
from ..tagfrag import try_render

ForLoop = namedtuple( # pylint: disable=invalid-name
    ['first', 'index', 'index0', 'last',
     'length', 'rindex', 'rindex0']
)

@register_tag
class TagFor(Tag):
    """Class for for tag"""

    SYNTAX = r"""
    inner_tag: tag_for
    !tag_for: $tagnames VAR "in" atom for_args*
    ?for_args: for_limit_arg | for_offset_arg | for_reversed_arg
    for_limit_arg: "limit" ":" (int|var)
    for_offset_arg: "offset" ":" (int|var)
    for_reversed_arg: "reversed"
    """
github pwwang / liquidpy / liquid / common / tags / cycle.py View on Github external
"""Tag cycle

{% for   %}
...
    {% cycle "one", "two", "three" %}
...
{% endfor %}
"""
from varname import namedtuple
from lark import v_args
from ...tagmgr import register_tag
from ..tagparser import Tag, TagTransformer
from ..tagfrag import TagFrag, TagFragConst

CycleObject = namedtuple( # pylint: disable=invalid-name
    ['group', 'args', 'at']
)

class TagFragCycle(TagFrag):

    def render(self, local_envs, global_envs):
        group, args = self.data
        group = group.render(local_envs, global_envs)
        args = [arg.render(local_envs, global_envs) for arg in args]
        return CycleObject(group, args, at=[0])


@v_args(inline=True)
class TransformerCycle(TagTransformer):
    """Transformer for fragment parsing cycle tag"""
    atom = TagTransformer.tags__atom
github pwwang / liquidpy / liquid / common / tags / tablerow.py View on Github external
{{ product.title }}
{% endtablerow %}

"""
import importlib
from varname import namedtuple
from lark import v_args
from ...tagmgr import register_tag
from ..tagparser import Tag, TagTransformer
from ..tagfrag import TagFrag, TagFragConst

# tagfor module, we cannot do: from . import for
# since for is a keyword
tagfor = importlib.import_module('.for', package=__package__)

TablerowObject = namedtuple( # pylint: disable=invalid-name
    ['itername', 'obj', 'limit', 'offset', 'cols']
)

class TagFragTablerow(TagFrag):

    def render(self, local_envs, global_envs):
        itername, expr, args = self.data
        obj = expr.render(local_envs, global_envs)
        args = dict(args)

        limit = args.get('limit', None)
        if limit:
            limit = limit.render(local_envs, global_envs)

        offset = args.get('offset', None)
        if offset:
github pwwang / liquidpy / liquid / common / parser.py View on Github external
from functools import partial
from collections import deque, OrderedDict
from varname import namedtuple
from diot import Diot
from lark import v_args, Lark, Transformer as LarkTransformer
from lark.exceptions import VisitError as LarkVisitError
# load all shared tags
from . import tags # pylint: disable=unused-import
from ..tagmgr import get_tag
from ..config import LIQUID_LOG_INDENT
from ..exceptions import (
    TagUnclosed, EndTagUnexpected,
    TagWrongPosition
)

TagContext = namedtuple(['template_name', # pylint: disable=invalid-name
                         'context_getter',
                         'line',
                         'column',
                         'logger'])

@v_args(inline=True)
class Transformer(LarkTransformer):
    """Transformer class to transform the trees/tokens

    Attributes:
        _stacks (deque): The stack used to handle the relationships between
            tags
        _direct_tags (list): The direct tags of the ROOT tag
    """

    def __init__(self, config, template_info):
github pwwang / liquidpy / liquid / tags / tag_tablerow.py View on Github external
"""Tag tabrow


{% tablerow product in collection.products %}
  {{ product.title }}
{% endtablerow %}
<table></table>
"""
from varname import namedtuple
from ..tagmgr import register_tag
from ..tag import Tag
from ..tagfrag import try_render

ForLoop = namedtuple( # pylint: disable=invalid-name
    ['first', 'index', 'index0', 'last',
     'length', 'rindex', 'rindex0']
)

@register_tag
class TagTablerow(Tag):
    """Class for tablerow tag"""

    SYNTAX = r"""
    inner_tag: tag_tablerow
    !tag_tablerow: $tagnames VAR "in" atom tablerow_args*
    ?tablerow_args: tablerow_limit_arg | tablerow_offset_arg | tablerow_cols_arg
    tablerow_limit_arg: "limit" ":" (int|var)
    tablerow_offset_arg: "offset" ":" (int|var)
    tablerow_cols_arg: "cols" ":" (int|var)
    """

varname

Dark magics about variable names in python.

MIT
Latest version published 2 months ago

Package Health Score

71 / 100
Full package analysis

Popular varname functions

Similar packages