<commit_before>"""Jinja2 implementations of the Djedi template tags."""

import hashlib
import textwrap

import cio

from djedi.templatetags.djedi_tags import render_node

from jinja2 import Markup, nodes
from jinja2.ext import Extension
from jinja2.lexer import Token

__all__ = ['NodeExtension', 'node']
__version__ = '2.0.3'
__author__ = '<NAME> <<EMAIL>>'
__authors__ = ['<NAME>', '<NAME>', '<NAME>',
               '<NAME>']


DJEDI_TAG = 'node'
DJEDI_BLOCK_TAG = 'blocknode'
DJEDI_INIT_TAG = '__djedi__init__'
DJEDI_NODE_STORAGE = '__djedi_nodes__'


class Builtin(object):
    def __init__(self, name):
        self.name = name

    def __repr__(self):
        return self.name


# Fields used by nodes.If().
IF_NODE_FIELDS = {
    'test': nodes.Not(
        nodes.Call(
            nodes.Const(Builtin('isinstance')),
            [
                nodes.Name(DJEDI_NODE_STORAGE, 'load'),
                nodes.Const(Builtin('dict')),
            ], [], None, None
        )
    ),
    'body': [
        nodes.Assign(
            nodes.Name(DJEDI_NODE_STORAGE, 'store'),
            nodes.Dict([])
        ),
    ],
}

# Construct the Jinja2 AST equivalent of:
#
#   if not isinstance(DJEDI_NODE_STORAGE, dict):
#       DJEDI_NODE_STORAGE = {}
#
if nodes.If.fields == ('test', 'body', 'elif_', 'else_'):
    # Jinja 2.10 added the "elif" field to If()
    DJEDI_NODE_STORAGE_NODE = (
        nodes.If(
            IF_NODE_FIELDS['test'],  # test
            IF_NODE_FIELDS['body'],  # body
            [],  # elif
            [],  # else
        )
    )
else:
    # nodes.If.fields is assumed to be ('test', 'body', 'else')
    DJEDI_NODE_STORAGE_NODE = (
        nodes.If(
            IF_NODE_FIELDS['test'],  # test
            IF_NODE_FIELDS['BODY'],  # body
            []  # else
        )
    )


class NodeExtension(Extension):
    tags = set([DJEDI_INIT_TAG, DJEDI_TAG, DJEDI_BLOCK_TAG])
<commit_msg>Fix lowercase body in node if fields<commit_after>"""Jinja2 implementations of the Djedi template tags."""

import hashlib
import textwrap

import cio

from djedi.templatetags.djedi_tags import render_node

from jinja2 import Markup, nodes
from jinja2.ext import Extension
from jinja2.lexer import Token

__all__ = ['NodeExtension', 'node']
__version__ = '2.0.3'
__author__ = '<NAME> <<EMAIL>>'
__authors__ = ['<NAME>', '<NAME>', '<NAME>',
               '<NAME>']


DJEDI_TAG = 'node'
DJEDI_BLOCK_TAG = 'blocknode'
DJEDI_INIT_TAG = '__djedi__init__'
DJEDI_NODE_STORAGE = '__djedi_nodes__'


class Builtin(object):
    def __init__(self, name):
        self.name = name

    def __repr__(self):
        return self.name


# Fields used by nodes.If().
IF_NODE_FIELDS = {
    'test': nodes.Not(
        nodes.Call(
            nodes.Const(Builtin('isinstance')),
            [
                nodes.Name(DJEDI_NODE_STORAGE, 'load'),
                nodes.Const(Builtin('dict')),
            ], [], None, None
        )
    ),
    'body': [
        nodes.Assign(
            nodes.Name(DJEDI_NODE_STORAGE, 'store'),
            nodes.Dict([])
        ),
    ],
}

# Construct the Jinja2 AST equivalent of:
#
#   if not isinstance(DJEDI_NODE_STORAGE, dict):
#       DJEDI_NODE_STORAGE = {}
#
if nodes.If.fields == ('test', 'body', 'elif_', 'else_'):
    # Jinja 2.10 added the "elif" field to If()
    DJEDI_NODE_STORAGE_NODE = (
        nodes.If(
            IF_NODE_FIELDS['test'],  # test
            IF_NODE_FIELDS['body'],  # body
            [],  # elif
            [],  # else
        )
    )
else:
    # nodes.If.fields is assumed to be ('test', 'body', 'else')
    DJEDI_NODE_STORAGE_NODE = (
        nodes.If(
            IF_NODE_FIELDS['test'],  # test
            IF_NODE_FIELDS['body'],  # body
            []  # else
        )
    )


class NodeExtension(Extension):
    tags = set([DJEDI_INIT_TAG, DJEDI_TAG, DJEDI_BLOCK_TAG])

{'fraction_non_alphanumeric': 0.13599792369582145, 'fraction_numerical': 0.0057098364910459385, 'mean_word_length': 2.3896218117854002, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '294292', 'n_tokens_mistral': 1400, 'n_tokens_neox': 1352, 'n_words': 278}