<commit_before>import sys

from pycellbase.commons import get, deprecated


class _ParentRestClient(object):
    """Queries the REST service given the different query params"""
    def __init__(self, session, configuration, subcategory, category):
        self._session = session
        self._configuration = configuration
        self._subcategory = subcategory
        self._category = category

    def _get(self, resource, query_id=None, options=None):
        """Queries the REST service and returns the result"""
        response = get(session=self._session,
                       host=self._configuration.host,
                       version=self._configuration.version,
                       species=self._configuration.species,
                       category=self._category,
                       subcategory=self._subcategory,
                       query_id=query_id,
                       resource=resource,
                       options=options)
        return response

    def _post(self, resource, query_id=None, options=None, data=None):
        """Queries the REST service and returns the result"""
        response = get(session=self._session,
                       host=self._configuration.host,
                       version=self._configuration.version,
                       species=self._configuration.species,
                       category=self._category,
                       subcategory=self._subcategory,
                       query_id=query_id,
                       resource=resource,
                       options=options,
                       method='post',
                       data=data)
        return response

    def get_help(self, method_name=None, show_params=False, **options):

        # Getting swagger documentation
        response = get(session=self._session,
                       host=self._configuration.host,
                       version='swagger.json',
                       species=None,
                       category=None,
                       subcategory=None,
                       resource=None,
                       options=options)
        sys.stdout.write(self.__class__.__name__ + '\n')

        # Getting class methods
        methods = [
            func for func in dir(self)
            if callable(getattr(self, func)) and not func.startswith('_')
        ]

        text = '{indent}{bullet} {name}: {desc}\n'
        for method in methods:
            if method_name is not None and method_name != method:
                continue
            # Getting method info
            method_swag = (method[4:] if method.startswith('get_') else method)
            path_info = [response['paths'][path] for path in response['paths']
                         if self._category in path and self._subcategory in path
                         and method_swag in path]
            if not path_info:
                continue
            if 'summary' not in path_info[0]['get']:
                continue
            desc = path_info[0]['get']['summary']
            desc = desc.replace('http://bioinfo.hpc.cam.ac.uk/cellbase',
                                self._configuration.host)
            sys.stdout.write(text.format(indent=' ' * 4,
                                         bullet='-',
                                         name=method,
                                         desc=desc))
            # Getting method parameters
            if not show_params:
                continue
            for param in path_info[0]['get']['parameters']:
                if param['name'] in ['version', 'species', 'Output format']:
                    continue
                desc = param['description'] if 'description' in param else '-'
                desc = desc.replace('http://bioinfo.hpc.cam.ac.uk/cellbase',
                                    self._configuration.host)
                sys.stdout.write(text.format(indent=' ' * 8,
                                             bullet='*',
                                             name=param['name'],
                                             desc=desc))


class _Feature(_ParentRestClient):
    """Queries the RESTful service for feature data"""
    def __init__(self, session, configuration, subcategory):
        _category = 'feature'
        super(_Feature, self).__init__(session, configuration, subcategory,
                                       _category)

    def get_model(self):
        """Returns the model for a specific element"""
        return self._get('model')
<commit_msg>python: check if method is POST in get_help function<commit_after>import sys

from pycellbase.commons import get, deprecated


class _ParentRestClient(object):
    """Queries the REST service given the different query params"""
    def __init__(self, session, configuration, subcategory, category):
        self._session = session
        self._configuration = configuration
        self._subcategory = subcategory
        self._category = category

    def _get(self, resource, query_id=None, options=None):
        """Queries the REST service and returns the result"""
        response = get(session=self._session,
                       host=self._configuration.host,
                       version=self._configuration.version,
                       species=self._configuration.species,
                       category=self._category,
                       subcategory=self._subcategory,
                       query_id=query_id,
                       resource=resource,
                       options=options)
        return response

    def _post(self, resource, query_id=None, options=None, data=None):
        """Queries the REST service and returns the result"""
        response = get(session=self._session,
                       host=self._configuration.host,
                       version=self._configuration.version,
                       species=self._configuration.species,
                       category=self._category,
                       subcategory=self._subcategory,
                       query_id=query_id,
                       resource=resource,
                       options=options,
                       method='post',
                       data=data)
        return response

    def get_help(self, method_name=None, show_params=False, **options):

        # Getting swagger documentation
        response = get(session=self._session,
                       host=self._configuration.host,
                       version='swagger.json',
                       species=None,
                       category=None,
                       subcategory=None,
                       resource=None,
                       options=options)
        sys.stdout.write(self.__class__.__name__ + '\n')

        # Getting class methods
        methods = [
            func for func in dir(self)
            if callable(getattr(self, func)) and not func.startswith('_')
        ]

        text = '{indent}{bullet} {name}: {desc}\n'
        for method in methods:
            if method_name is not None and method_name != method:
                continue
            # Getting method info
            method_swag = (method[4:] if method.startswith('get_') else method)
            path_info = [response['paths'][path] for path in response['paths']
                         if self._category in path and self._subcategory in path
                         and method_swag in path]
            if not path_info:
                continue
            # TODO This is a temporary check to fix POST methods, that should be removed.
            if 'get' not in path_info[0]:
                continue
            if 'summary' not in path_info[0]['get']:
                continue
            desc = path_info[0]['get']['summary']
            desc = desc.replace('http://bioinfo.hpc.cam.ac.uk/cellbase', self._configuration.host)
            sys.stdout.write(text.format(indent=' ' * 4,
                                         bullet='-',
                                         name=method,
                                         desc=desc))
            # Getting method parameters
            if not show_params:
                continue
            for param in path_info[0]['get']['parameters']:
                if param['name'] in ['version', 'species', 'Output format']:
                    continue
                desc = param['description'] if 'description' in param else '-'
                desc = desc.replace('http://bioinfo.hpc.cam.ac.uk/cellbase',
                                    self._configuration.host)
                sys.stdout.write(text.format(indent=' ' * 8,
                                             bullet='*',
                                             name=param['name'],
                                             desc=desc))


class _Feature(_ParentRestClient):
    """Queries the RESTful service for feature data"""
    def __init__(self, session, configuration, subcategory):
        _category = 'feature'
        super(_Feature, self).__init__(session, configuration, subcategory,
                                       _category)

    def get_model(self):
        """Returns the model for a specific element"""
        return self._get('model')

{'fraction_non_alphanumeric': 0.08881436607529208, 'fraction_numerical': 0.0014063176114236262, 'mean_word_length': 1.445120338534779, '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': 28, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3388666', 'n_tokens_mistral': 2121, 'n_tokens_neox': 2002, 'n_words': 526}