<commit_before>#
# Copyright (c) 2010 Red Hat, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#           http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#


import inspect
from papyon.util.odict import odict
from codegen.doc.documentation import Documentation

class MethodHelper():

    NON_ARG_TEMPLATE = ':not-arg'

    @staticmethod
    def getMethodArgs(module, cls, method, get_varargs=False, get_keywords=False, drop_self=False):
        '''Returns list of method's arguments'''
        if hasattr(module, cls):
            cls_ref = getattr(module, cls)
            if cls_ref and hasattr(cls_ref, method):
                method_ref = getattr(cls_ref, method)
                if method_ref:
                    try:
                        res = getattr(inspect.getargspec(method_ref), 'args')
                        if not res: res = []
                        if drop_self and res.__contains__('self'):
                            res.remove('self')
                        if get_varargs:
                            varargs_res = getattr(inspect.getargspec(method_ref), 'varargs')
                            if varargs_res: res.append(varargs_res)
                        if get_keywords:
                            keywords_res = getattr(inspect.getargspec(method_ref), 'keywords')
                            if keywords_res: res.append(keywords_res)
                        return res
                    except:
                        pass
        return []

    @staticmethod
    def get_method_params(module, clazz, method, holder=odict()):
        args = MethodHelper.getMethodArgs(module, clazz, method)
        if args:
            if len(args) == 3:
                if not holder.has_key(args[2]):
                    holder[args[2]] = args[1]
                else:
                    if holder[args[2]] == None:
                        if args[1] != None:
                            holder[args[2]] = 'None, ' + args[1]
                    else:
                        holder[args[2]] = holder[args[2]] + ', ' + args[1]
            elif len(args) == 2:
                if not holder.has_key(args[1]):
                    holder[args[1]] = None
                else:
                    if holder[args[1]] == None:
                        if holder[args[1]] != None:
                            holder[args[1]] = 'None' + ', ' + holder[args[1]]
                    else:
                        holder[args[1]] = holder[args[1]] + ', ' + 'None'
        return holder

    @staticmethod
    def get_documented_arguments(method_ref, as_params_collection=False, spilt_or=False):
        """Return a list of documented arguments for specific method, ignoring metadata."""
        return MethodHelper.get_arguments_documentation(method_ref, as_params_collection, spilt_or, ignore_non_args=True)


    @staticmethod
    def get_arguments_documentation(method_ref, as_params_collection=False, spilt_or=False, ignore_non_args=False):
        """Return a list of documented arguments with arguments metadata for specific method."""

        PARAM_ANNOTATION = '@param'
        IVAR_ANNOTATION = '@ivar'
        params_list = []
        ivars_list = []
        PERIOD_SYMBOL = '-'

        if method_ref and method_ref.__doc__:
            doc = method_ref.__doc__
            params_arr = doc.split('\n')

            for var in params_arr:
                if not ignore_non_args and var.find(Documentation.OVERLOAD_TEMPLATE) != -1:
                    params_list.append('\n' + var.strip() + MethodHelper.NON_ARG_TEMPLATE + '\n')
                elif '' != var and var.find(PARAM_ANNOTATION) != -1:
                    splitted_line = var.strip().split(' ')
                    if len(splitted_line) >= 2:
                        prefix = splitted_line[0].replace((PARAM_ANNOTATION + ' '),<commit_msg>cli: remove codegen.doc.documentation import<commit_after>#
# Copyright (c) 2010 Red Hat, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#           http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#


import inspect
from papyon.util.odict import odict

class MethodHelper():

    NON_ARG_TEMPLATE = ':not-arg'

    @staticmethod
    def getMethodArgs(module, cls, method, get_varargs=False, get_keywords=False, drop_self=False):
        '''Returns list of method's arguments'''
        if hasattr(module, cls):
            cls_ref = getattr(module, cls)
            if cls_ref and hasattr(cls_ref, method):
                method_ref = getattr(cls_ref, method)
                if method_ref:
                    try:
                        res = getattr(inspect.getargspec(method_ref), 'args')
                        if not res: res = []
                        if drop_self and res.__contains__('self'):
                            res.remove('self')
                        if get_varargs:
                            varargs_res = getattr(inspect.getargspec(method_ref), 'varargs')
                            if varargs_res: res.append(varargs_res)
                        if get_keywords:
                            keywords_res = getattr(inspect.getargspec(method_ref), 'keywords')
                            if keywords_res: res.append(keywords_res)
                        return res
                    except:
                        pass
        return []

    @staticmethod
    def get_method_params(module, clazz, method, holder=odict()):
        args = MethodHelper.getMethodArgs(module, clazz, method)
        if args:
            if len(args) == 3:
                if not holder.has_key(args[2]):
                    holder[args[2]] = args[1]
                else:
                    if holder[args[2]] == None:
                        if args[1] != None:
                            holder[args[2]] = 'None, ' + args[1]
                    else:
                        holder[args[2]] = holder[args[2]] + ', ' + args[1]
            elif len(args) == 2:
                if not holder.has_key(args[1]):
                    holder[args[1]] = None
                else:
                    if holder[args[1]] == None:
                        if holder[args[1]] != None:
                            holder[args[1]] = 'None' + ', ' + holder[args[1]]
                    else:
                        holder[args[1]] = holder[args[1]] + ', ' + 'None'
        return holder

    @staticmethod
    def get_documented_arguments(method_ref, as_params_collection=False, spilt_or=False):
        """Return a list of documented arguments for specific method, ignoring metadata."""
        return MethodHelper.get_arguments_documentation(method_ref, as_params_collection, spilt_or, ignore_non_args=True)


    @staticmethod
    def get_arguments_documentation(method_ref, as_params_collection=False, spilt_or=False, ignore_non_args=False):
        """Return a list of documented arguments with arguments metadata for specific method."""

        PARAM_ANNOTATION = '@param'
        IVAR_ANNOTATION = '@ivar'
        params_list = []
        ivars_list = []
        PERIOD_SYMBOL = '-'

        if method_ref and method_ref.__doc__:
            doc = method_ref.__doc__
            params_arr = doc.split('\n')

            for var in params_arr:
                if not ignore_non_args and var.find('Overload') != -1:
                    params_list.append('\n' + var.strip() + MethodHelper.NON_ARG_TEMPLATE + '\n')
                elif '' != var and var.find(PARAM_ANNOTATION) != -1:
                    splitted_line = var.strip().split(' ')
                    if len(splitted_line) >= 2:
                        prefix = splitted_line[0].replace((PARAM_ANNOTATION + ' '),
{'fraction_non_alphanumeric': 0.09898894897719257, 'fraction_numerical': 0.0075241006348459915, 'mean_word_length': 1.8066644671725502, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '954517', 'n_tokens_mistral': 2357, 'n_tokens_neox': 2239, 'n_words': 599}