<commit_before>"""
This module contains all the beekeeper classes that are used on the front end
to directly interface between the developer and the remote API.
"""

from __future__ import absolute_import, division
from __future__ import unicode_literals, print_function

import copy
from functools import partial
from keyword import iskeyword

from beekeeper.variables import Variables
from beekeeper.hive import Hive
from beekeeper.comms import Request

class Endpoint(object):

    """
    Contains the settings for an endpoint, as well as a backref to the API
    """

    def __init__(self, parent, path, **kwargs):
        self.parent = parent
        self.path = path
        self.vars = Variables(**kwargs.get('variables', {}))
        self.methods = kwargs.get('methods', ['GET'])
        self.mimetype = kwargs.get('mimetype', None)

    def variables(self):
        """
        Get API-level variables, and add in Endpoint-level variables.
        """
        return self.parent.variables().add(**self.vars)

    def url(self):
        """
        Combine the API-level root URL with the Endpoint's path.
        """
        return self.parent.base_url() + self.path

    def new_action(self, method='GET', **kwargs):
        """
        Create a new Action linked to this endpoint with the given args.
        """
        if method not in self.methods:
            raise TypeError('{} not in valid method(s): {}.'.format(method, self.methods))
        return Action(self, method, **kwargs)

    def format(self):
        """
        Get the Endpoint-level mimetype, deferring to the API level settings
        if the Endpoint object doesn't have a value.
        """
        if self.mimetype:
            return self.mimetype
        else:
            return self.parent.format()

class APIObject(object):

    """
    Holds Action objects in the appropriate namespace, and provides a __getitem__
    dundermethod so that we can subscript by object ID when such exists
    """

    def __init__(self, parent, actions, **kwargs):
        self.description = kwargs.get('description', None)
        self.id_variable = kwargs.get('id_variable', None)
        if self.id_variable and iskeyword(self.id_variable):
            self.id_variable = '_' + self.id_variable
        self.actions = {}
        for name, action in actions.items():
            self.add_action(name, parent, action)

    def __getitem__(self, key):
        """
        Allows us to subscript, dictionary-style, on the object if we
        know what the object's unique key is.
        """
        if self.id_variable:
            return APIObjectInstance(self, key)
        raise TypeError('Object cannot be addressed by ID')

    def defined_actions(self):
        """
        Get a list of the available Actions on the APIObject.
        """
        return [name for name in self.actions]

    def add_action(self, name, parent, action):
        """
        Add a single Action to the APIObject.
        """
        if iskeyword(name):<commit_msg>Removing unnecessary logic in previous commit - keyword.iskeyword() returns False when passed a NoneType object<commit_after>"""
This module contains all the beekeeper classes that are used on the front end
to directly interface between the developer and the remote API.
"""

from __future__ import absolute_import, division
from __future__ import unicode_literals, print_function

import copy
from functools import partial
from keyword import iskeyword

from beekeeper.variables import Variables
from beekeeper.hive import Hive
from beekeeper.comms import Request

class Endpoint(object):

    """
    Contains the settings for an endpoint, as well as a backref to the API
    """

    def __init__(self, parent, path, **kwargs):
        self.parent = parent
        self.path = path
        self.vars = Variables(**kwargs.get('variables', {}))
        self.methods = kwargs.get('methods', ['GET'])
        self.mimetype = kwargs.get('mimetype', None)

    def variables(self):
        """
        Get API-level variables, and add in Endpoint-level variables.
        """
        return self.parent.variables().add(**self.vars)

    def url(self):
        """
        Combine the API-level root URL with the Endpoint's path.
        """
        return self.parent.base_url() + self.path

    def new_action(self, method='GET', **kwargs):
        """
        Create a new Action linked to this endpoint with the given args.
        """
        if method not in self.methods:
            raise TypeError('{} not in valid method(s): {}.'.format(method, self.methods))
        return Action(self, method, **kwargs)

    def format(self):
        """
        Get the Endpoint-level mimetype, deferring to the API level settings
        if the Endpoint object doesn't have a value.
        """
        if self.mimetype:
            return self.mimetype
        else:
            return self.parent.format()

class APIObject(object):

    """
    Holds Action objects in the appropriate namespace, and provides a __getitem__
    dundermethod so that we can subscript by object ID when such exists
    """

    def __init__(self, parent, actions, **kwargs):
        self.description = kwargs.get('description', None)
        self.id_variable = kwargs.get('id_variable', None)
        if iskeyword(self.id_variable):
            self.id_variable = '_' + self.id_variable
        self.actions = {}
        for name, action in actions.items():
            self.add_action(name, parent, action)

    def __getitem__(self, key):
        """
        Allows us to subscript, dictionary-style, on the object if we
        know what the object's unique key is.
        """
        if self.id_variable:
            return APIObjectInstance(self, key)
        raise TypeError('Object cannot be addressed by ID')

    def defined_actions(self):
        """
        Get a list of the available Actions on the APIObject.
        """
        return [name for name in self.actions]

    def add_action(self, name, parent, action):
        """
        Add a single Action to the APIObject.
        """
        if iskeyword(name):
{'fraction_non_alphanumeric': 0.09408120006522093, 'fraction_numerical': 0.0, 'mean_word_length': 2.4931662870159452, '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': '1824751', 'n_tokens_mistral': 1651, 'n_tokens_neox': 1602, 'n_words': 594}