<commit_before>from abc import ABCMeta, abstractmethod

from django.conf import settings
from django.utils.module_loading import import_string


class Api(object):
    '''
        Used to route calls to from inside of callisto/delivery/* to api(s) inside of other apps

        Extending objects should have 'api_env_variable' and 'default_classpath' members.
        See DeliveryApi for an example
    '''

    def __init__(self):
        self.set_api_class(self.api_env_variable, self.default_classpath)

    def __getattr__(self, attr):
        return getattr(self.api_implementation, attr)

    def set_api_class(self, api_env_variable, default_classpath):
        override_class_path = getattr(
            settings,
            api_env_variable,
            default_classpath,
        )
        self.api_implementation = import_string(override_class_path)


class DeliveryApi(Api):
    '''
        Used to route calls to from inside of callisto/delivery/* to
        notification api(s) inside of other apps

        this object is called with
            from callisto.delivery.api import DeliveryApi
            DeliveryApi().example_call

        which maps to CALLISTO_NOTIFICATION_API
            CALLISTO_NOTIFICATION_API.example_call

        use CALLISTO_NOTIFICATION_API to override the class that
        DeliveryApi maps to
    '''

    api_env_variable = 'CALLISTO_NOTIFICATION_API'
    default_classpath = 'callisto.delivery.api.AbstractNotification'

    def __getattr__(self, attr):
        if attr in AbstractNotification.__dict__.keys():
            return getattr(self.api_implementation, attr)
        else:
            raise NotImplementedError('Attribute not implemented on abstract Notification class')


class AbstractNotification:
    __metaclass__ = ABCMeta

    @abstractmethod
    def send_report_to_authority(self):
        pass

    @abstractmethod
    def send_matching_report_to_authority(self):
        pass

    @abstractmethod
    def send_user_notification(self):
        pass<commit_msg>allow abitrary methods to be defined on DeliveryApi<commit_after>from abc import ABCMeta, abstractmethod

from django.conf import settings
from django.utils.module_loading import import_string


class Api(object):
    '''
        Used to route calls to from inside of callisto/delivery/* to api(s) inside of other apps

        Extending objects should have 'api_env_variable' and 'default_classpath' members.
        See DeliveryApi for an example
    '''

    def __init__(self):
        self.set_api_class(self.api_env_variable, self.default_classpath)

    def __getattr__(self, attr):
        return getattr(self.api_implementation, attr)

    def set_api_class(self, api_env_variable, default_classpath):
        override_class_path = getattr(
            settings,
            api_env_variable,
            default_classpath,
        )
        self.api_implementation = import_string(override_class_path)


class DeliveryApi(Api):
    '''
        Used to route calls to from inside of callisto/delivery/* to
        notification api(s) inside of other apps

        this object is called with
            from callisto.delivery.api import DeliveryApi
            DeliveryApi().example_call

        which maps to CALLISTO_NOTIFICATION_API
            CALLISTO_NOTIFICATION_API.example_call

        use CALLISTO_NOTIFICATION_API to override the class that
        DeliveryApi maps to
    '''

    api_env_variable = 'CALLISTO_NOTIFICATION_API'
    default_classpath = 'callisto.delivery.api.AbstractNotification'

    def __getattr__(self, attr):
        return getattr(self.api_implementation, attr, None)


class AbstractNotification:
    __metaclass__ = ABCMeta

    @abstractmethod
    def send_report_to_authority(self):
        pass

    @abstractmethod
    def send_matching_report_to_authority(self):
        pass

    @abstractmethod
    def send_user_notification(self):
        pass
{'fraction_non_alphanumeric': 0.05828455077627895, 'fraction_numerical': 0.0, 'mean_word_length': 2.977732793522267, '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': '7285685', 'n_tokens_mistral': 1107, 'n_tokens_neox': 1058, 'n_words': 286}