<commit_before>@MACRO::Attributes
    [|@OR
    [|@VAL::object[|[@REP(,)[|'@VAL::name'|]|]]|]
    [|None|]|]

@MACRO::ParameterNames
    [|@REP::params[|, @VAL::name|]|]

@MACRO::ParameterValues
    [|@REP(,)::values[|@OPT[|@VAL::object@REP::fields[|['@VAL']|]|]|]|]

@MACRO::RootParameterNames
    [|@VAL::route[|@USE::ParameterNames|]|]

@MACRO::PathAsString
    [|"/@REP::values[|@OR[|@VAL::name|][|%s|]|]"|]

@MACRO::PathVariables
    [|[@REP(,)::values[|@OPT[|['@VAL::object'@REP::fields[|, '@VAL'|]]|]|]]|]

@MACRO::IsAtomicType
    [|@OR
    [|@VAL::bool[||]|]
    [|@VAL::int[||]|]
    [|@VAL::string[||]|]
    [|@VAL::opt[|@USE::IsAtomicType|]|]|]

@MACRO::UnsetVariables
    [|@OPT
    [|@VAL::object[|@REP
        [|@OR
        [|@VAL::type[|@USE::IsAtomicType|]
            self.data['@VAL::name'] = None|]
        [|@VAL::type[|@USE::UnsetVariables|]|]
        [||]|]|]|]|]

@MACRO::SetVariables
    [|@OPT
    [|@VAL::object[|@REP
        [|@OR
        [|@VAL::type[|@USE::IsAtomicType|]
            self.data['@VAL::name'] = data@USE::VarPath['@VAL::name']|]
        [|@DEFINE::VarPath[|@OPT[|@USE::VarPath|]['@VAL::name']|]@VAL::type[|@USE::SetVariables|]|]
        [||]|]|]|]|]

@MACRO::VariableGetterSetter
    [|@OPT
    [|@VAL::object[|@REP
        [|@OR
        [|@VAL::type[|@USE::IsAtomicType|]
    def @VAL::get(self):
        return self.data['@VAL::name']
|]
        [|@VAL::type[|@USE::IsAtomicType|]
    def @VAL::set(self, value):
        self.data['@VAL::name'] = value
        return self
|]
        [|@VAL::type[|@USE::IsAtomicType|]
    def @VAL::set_get(self, value=None):
        if value is None:
            return self.data['@VAL::name']
        else:
            self.data['@VAL::name'] = value
            return self
|]
        [|@VAL::type[|@USE::VariableGetterSetter|]|]
        [||]|]|]|]|]

@MACRO::Types
    [|@OR
    [|@VAL::bool[|True|]|]
    [|@VAL::int[|0|]|]
    [|@VAL::string[|""|]|]
    [|@VAL::opt[|self.opt(@USE::Types)|]|]
    [|@VAL::rep[|self.rep(@USE::Types)|]|]
    [|@VAL::object[|{@REP(, )
        [|@OR
        [|@VAL::type[|@USE::IsAtomicType|]'@VAL::name': self.data['@VAL::name']|]
        [|'@VAL::name': @VAL::type[|@USE::Types|]|]|]}|]|]|]

import httplib as http
import json


class BasicService:

    #
    # Constructor
    #

    def __init__(self, url):
        self.url = url
        self.path = None

    #
    # Public behaviors
    #

    def http_request(self, path, operation, body=None, header=None, implicit_header=None):
        connection = http.HTTPConnection(self.url)

        if not header:
            header = {}

        if not body:
            body = {}

        if not implicit_header:
            implicit_header = {'Content-type': 'application/json'}

        complete_header = dict(implicit_header.items() + header.items())

        connection.request(operation, self.path + path, json.dumps(body), complete_header)
        try:
            response = connection.getresponse()
            data = response.read()
            return json.loads(data)
        finally:
            connection.close()

    def get_path(self, data, pattern, Attributes):
        return pattern % tuple([self.__get_value(data, attribute) for attribute in Attributes])

    @staticmethod
    def get_data(data, Attributes):
        return '&'.join([key + "=" + str(data[key]) for key in Attributes if data[key]])

    @staticmethod
    def get_object(data, Attributes):
        return dict([(key, data[key]) for key in Attributes if data[key]])

    @staticmethod
    def merge_data(datas):
        data = dict()

        for d in datas:
            if isinstance(d, Type):
                data = dict(data.items() + d.to_external().items())
            else:
                data = dict(data.items() + d.items())

        return data

    #
    # Private behaviors
    #

    def __get_value(self, data, Attributes):
        if Attributes is None or not Attributes:
            return data
        else:
            return self.__get_value(data[Attributes[0]], Attributes[1:])

#
# Types:@REP(,)::types[| @VAL::name|]
#


class Type:

    def __init__(self):
        pass

    def opt(self, t):
        return t

    def rep(self, t):
        return t

@REP::types[|
class @VAL::name(Type):

    def __init__(self, data=None):
        Type.__init__(self)

        if not data:
            self.data = dict()
            @VAL::definition[|@USE::UnsetVariables|]
        else:
            self.data = data
            @VAL::definition[|@USE::SetVariables|]
    @VAL::definition[|@USE::VariableGetterSetter|]
    def to_external(self):
        return @VAL::definition[|@USE::Types|]

|]

#
# Services:@REP(,)::services[| @VAL::name|]
#

@REP::services[|
class __@VAL::name(BasicService):

    #
    # Constructor
    #

    def __init__(self, url@USE::RootParameterNames):
        @VAL::route[|BasicService.__init__(self, url)
        self.implicit_data = self.merge_data([@REP(, )::params[|@VAL::name|]])
        self.path = @VAL::path[|self.get_path(self.implicit_data, @USE::PathAsString, @USE::PathVariables)|]|]

    #<commit_msg>Review and optimize generated python<commit_after>@MACRO::Attributes
    [|@OR
    [|@VAL::object[|[@REP(,)[|'@VAL::name'|]|]]|]
    [|None|]|]

@MACRO::ParameterNames
    [|@REP::params[|, @VAL::name|]|]

@MACRO::ParameterValues
    [|@REP(,)::values[|@OPT[|@VAL::object@REP::fields[|['@VAL']|]|]|]|]

@MACRO::RootParameterNames
    [|@VAL::route[|@USE::ParameterNames|]|]

@MACRO::PathAsString
    [|"/@REP::values[|@OR[|@VAL::name|][|%s|]|]"|]

@MACRO::PathVariables
    [|[@REP(,)::values[|@OPT[|['@VAL::object'@REP::fields[|, '@VAL'|]]|]|]]|]

@MACRO::PushVar[|@DEFINE::VarPath[|@OPT[|@USE::VarPath|]['@VAL::name']|]|]

@MACRO::GenerateGetterSetter
    [|@OR
    [|
    def @VAL::get(self):
        return self.data@USE::VarPath
|]
    [|
    def @VAL::set(self, value):
        self.data@USE::VarPath = value
        return self
|]
    [|
    def @VAL::set_get(self, value=None):
        if value is None:
            return self.data@USE::VarPath
        else:
            self.data@USE::VarPath = value
            return self
|]
    [||]|]

@MACRO::VariableGetterSetter
    [|@OPT
    [|@VAL::object[|@REP[|@USE::PushVar@USE::GenerateGetterSetter@VAL::type[|@USE::VariableGetterSetter|]|]|]|]|]

@MACRO::Types
    [|@OR
    [|@VAL::bool[|True|]|]
    [|@VAL::int[|0|]|]
    [|@VAL::string[|""|]|]
    [|@VAL::opt[|None|]|]
    [|@VAL::rep[|[]|]|]
    [|@VAL::object[|{@REP(, )[|'@VAL::name': @VAL::type[|@USE::Types|]|]|]}|]|]

import httplib as http
import json


class BasicService:

    #
    # Constructor
    #

    def __init__(self, url):
        self.url = url
        self.path = None

    #
    # Public behaviors
    #

    def http_request(self, path, operation, body=None, header=None, implicit_header=None):
        connection = http.HTTPConnection(self.url)

        if not header:
            header = {}

        if not body:
            body = {}

        if not implicit_header:
            implicit_header = {'Content-type': 'application/json'}

        complete_header = dict(implicit_header.items() + header.items())

        connection.request(operation, self.path + path, json.dumps(body), complete_header)
        try:
            response = connection.getresponse()
            data = response.read()
            return json.loads(data)
        finally:
            connection.close()

    def get_path(self, data, pattern, Attributes):
        return pattern % tuple([self.__get_value(data, attribute) for attribute in Attributes])

    @staticmethod
    def get_data(data, Attributes):
        return '&'.join([key + "=" + str(data[key]) for key in Attributes if data[key]])

    @staticmethod
    def get_object(data, Attributes):
        return dict([(key, data[key]) for key in Attributes if data[key]])

    @staticmethod
    def merge_data(datas):
        data = dict()

        for d in datas:
            if isinstance(d, Type):
                data = dict(data.items() + d.to_dict().items())
            else:
                data = dict(data.items() + d.items())

        return data

    #
    # Private behaviors
    #

    def __get_value(self, data, Attributes):
        if Attributes is None or not Attributes:
            return data
        else:
            return self.__get_value(data[Attributes[0]], Attributes[1:])

#
# Types:@REP(,)::types[| @VAL::name|]
#


class Type:

    def __init__(self):
        self.data = None

    def to_dict(self):
        return self.data

@REP::types[|
class @VAL::name(Type):

    def __init__(self, data=None):
        Type.__init__(self)

        if not data:
            self.data = @VAL::definition[|@USE::Types|]
        else:
            self.data = data
    @VAL::definition[|@USE::VariableGetterSetter|]
|]

#
# Services:@REP(,)::services[| @VAL::name|]
#

@REP::services[|
class __@VAL::name(BasicService):

    #
    # Constructor
    #

    def __init__(self, url@USE::RootParameterNames):
        @VAL::route[|BasicService.__init__(self, url)
        self.implicit_data = self.merge_data([@REP(, )::params[|@VAL::name|]])
        self.path = @VAL::path[|self.get_path(self.implicit_data, @USE::PathAsString, @USE::PathVariables)|]|]

    #
{'fraction_non_alphanumeric': 0.2022921396907774, 'fraction_numerical': 0.0006487187804086928, 'mean_word_length': 2.863826232247285, 'pattern_counts': {'":': 0, '<': 3, '<?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': '3814837', 'n_tokens_mistral': 3400, 'n_tokens_neox': 3336, 'n_words': 522}