<commit_before>from __future__ import unicode_literals

import argparse
import itertools
import os
import re
import shutil

from collections import defaultdict, namedtuple
from contextlib import contextmanager

from babelapi.data_type import (
    Float32,
    Float64,
    Int32,
    Int64,
    UInt32,
    UInt64,
    Void,
    is_binary_type,
    is_boolean_type,
    is_composite_type,
    is_float_type,
    is_integer_type,
    is_list_type,
    is_nullable_type,
    is_numeric_type,
    is_primitive_type,
    is_string_type,
    is_struct_type,
    is_tag_ref,
    is_timestamp_type,
    is_union_type,
    is_void_type,
)
from babelapi.generator import CodeGenerator

cmdline_desc = """\
Generate .NET source files for given babel spec.
"""

_cmdline_parser = argparse.ArgumentParser(description=cmdline_desc)

def memo_one(fn):
    """
    Memoize a single argument instance method.
    """
    cache = {}
    def wrapper(self, arg):
        value = cache.get(arg)
        if value is not None:
            return value
        value = fn(self, arg)
        cache[arg] = value
        return value
    return wrapper

ConstructorArg = namedtuple('ConstructorArg', ('type', 'name', 'arg', 'doc'))


class _CSharpGenerator(CodeGenerator):
    _CAMEL_CASE_RE = re.compile('((?<=[a-z0-9])[A-Z]|(?!^)[A-Z](?=[a-z]))')
    _CSHARP_KEYWORDS = frozenset({
        'abstract', 'add', 'alias', 'as', 'ascending', 'async', 'await',
        'base', 'bool', 'break', 'byte', 'case', 'catch', 'char', 'checked',
        'class', 'const', 'continue', 'decimal', 'default', 'delegate',
        'descending', 'do', 'double', 'dynamic', 'else', 'enum', 'event',
        'explicit', 'extern', 'false', 'finally', 'fixed', 'float', 'for',
        'foreach', 'from', 'get', 'global', 'goto', 'group', 'if', 'implicit',
        'in', 'int', 'interface', 'internal', 'into', 'is', 'join', 'let',
        'lock', 'long', 'namespace', 'new', 'null', 'object', 'operator',
        'orderby', 'out', 'override', 'params', 'partial', 'private',
        'protected', 'public', 'readonly', 'ref', 'remove', 'return', 'sbyte',
        'sealed', 'select', 'set', 'short', 'sizeof', 'stackalloc', 'static',
        'string', 'struct', 'switch', 'this', 'throw', 'true', 'try', 'typeof',
        'uint', 'ulong', 'unchecked', 'unsafe', 'ushort', 'using', 'value',
        'var', 'virtual', 'void', 'volatile', 'where', 'while', 'yield',
    })

    cmdline_parser = _cmdline_parser

    def __init__(self, namespace_name, app_name, *args, **kwargs):
        '''
        Initializes a new instance of CSharpGenerator.
        Args:
            namespace_name: The namespace name for all generated files.
            app_name: The app name which will be used as prefix for all client classes.

            *args:
            **kwargs:

        Returns:

        '''
        super(_CSharpGenerator, self).__init__(*args, **kwargs)
        self._prefixes = []
        self._prefix = ''
        self._name_list = []
        self._prevent_collisions = set()
        self._generated_files = []
        self._tag_context = None

        self._namespace_name = namespace_name
        self._app_name = app_name

    def generate(self, api):        
        for namespace in api.namespaces.itervalues():
            self._compute_related_types(namespace)
            self._generate_namespace(namespace)
<commit_msg>Remove arg parser from base generator.<commit_after>from __future__ import unicode_literals

import itertools
import os
import re
import shutil

from collections import defaultdict, namedtuple
from contextlib import contextmanager

from babelapi.data_type import (
    Float32,
    Float64,
    Int32,
    Int64,
    UInt32,
    UInt64,
    Void,
    is_binary_type,
    is_boolean_type,
    is_composite_type,
    is_float_type,
    is_integer_type,
    is_list_type,
    is_nullable_type,
    is_numeric_type,
    is_primitive_type,
    is_string_type,
    is_struct_type,
    is_tag_ref,
    is_timestamp_type,
    is_union_type,
    is_void_type,
)
from babelapi.generator import CodeGenerator

def memo_one(fn):
    """
    Memoize a single argument instance method.
    """
    cache = {}
    def wrapper(self, arg):
        value = cache.get(arg)
        if value is not None:
            return value
        value = fn(self, arg)
        cache[arg] = value
        return value
    return wrapper

ConstructorArg = namedtuple('ConstructorArg', ('type', 'name', 'arg', 'doc'))

class _CSharpGenerator(CodeGenerator):
    _CAMEL_CASE_RE = re.compile('((?<=[a-z0-9])[A-Z]|(?!^)[A-Z](?=[a-z]))')
    _CSHARP_KEYWORDS = frozenset({
        'abstract', 'add', 'alias', 'as', 'ascending', 'async', 'await',
        'base', 'bool', 'break', 'byte', 'case', 'catch', 'char', 'checked',
        'class', 'const', 'continue', 'decimal', 'default', 'delegate',
        'descending', 'do', 'double', 'dynamic', 'else', 'enum', 'event',
        'explicit', 'extern', 'false', 'finally', 'fixed', 'float', 'for',
        'foreach', 'from', 'get', 'global', 'goto', 'group', 'if', 'implicit',
        'in', 'int', 'interface', 'internal', 'into', 'is', 'join', 'let',
        'lock', 'long', 'namespace', 'new', 'null', 'object', 'operator',
        'orderby', 'out', 'override', 'params', 'partial', 'private',
        'protected', 'public', 'readonly', 'ref', 'remove', 'return', 'sbyte',
        'sealed', 'select', 'set', 'short', 'sizeof', 'stackalloc', 'static',
        'string', 'struct', 'switch', 'this', 'throw', 'true', 'try', 'typeof',
        'uint', 'ulong', 'unchecked', 'unsafe', 'ushort', 'using', 'value',
        'var', 'virtual', 'void', 'volatile', 'where', 'while', 'yield',
    })

    def __init__(self, namespace_name, app_name, *args, **kwargs):
        '''
        Initializes a new instance of CSharpGenerator.
        Args:
            namespace_name: The namespace name for all generated files.
            app_name: The app name which will be used as prefix for all client classes.

            *args:
            **kwargs:

        Returns:

        '''
        super(_CSharpGenerator, self).__init__(*args, **kwargs)
        self._prefixes = []
        self._prefix = ''
        self._name_list = []
        self._prevent_collisions = set()
        self._generated_files = []
        self._tag_context = None

        self._namespace_name = namespace_name
        self._app_name = app_name

    def generate(self, api):        
        for namespace in api.namespaces.itervalues():
            self._compute_related_types(namespace)
            self._generate_namespace(namespace)

{'fraction_non_alphanumeric': 0.15465169221429656, 'fraction_numerical': 0.004249506753680376, 'mean_word_length': 2.9484721390053923, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, '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': '6771804', 'n_tokens_mistral': 2100, 'n_tokens_neox': 2055, 'n_words': 528}