<commit_before>'''
Provides access to pluggable backend infrastructucture.

Target backends must be configured in the settings by adding
the desired backend to the value of the TARGET variable.
'''
import logging

__all__ = [
    'AbstractHandler',
    'register_handler',
    'remove_handler',
    'get_handlers',
    'create',
    'read',
    'update',
    'delete',
]
_handlers = {
    'Concept': [],
    'Encounter': [],
    'Location':[],
    'Procedure':[],
    'Observation':[],
    'Observer'[],
    'Subject':[],
}

class AbstractHandler(object)
    def __init__(self, **kwargs):
        pass
    
    def create_model(self):
        pass

    def read_model(self):
        pass

    def update_model(self):
        pass

    def delete_model(self):
        pass

def register_handler(model, target):
    pass

def remove_handler(model, target):
    pass

def get_handlers(model):
    ''' Returns the callable for sending the instance 
        to the target.
    '''
    return _handlers.get(model, [])

def create(model, obj, auth=None, *args, **kwargs):
    ''' Handles the instance creation in the backend and returns a list
        of objects created.
        
        This effectively wraps a POST call to the dispatch server and
        forwards it to the frontend. The first handler registered will
        be used as the primary 
    '''
    handlers = get_handlers(model)
    result = []
    if not handlers:
        logging.warn("No handler defined for %s" % model) 
    for handler in handlers:
        handler_instance = handler(auth=auth)
        caller = handler.getattr('create_model', None)
        if caller:
            if result:
                caller(obj,*args,**kwargs)
            else:
                result = caller(obj,*args,**kwargs)
        else:
            logging.warn("No callable defined.")
    return result

def read(model, obj, auth=None, *args, **kwargs):
    ''' Handles the instance fetch in the backend and returns a list
        of objects created.
        
        This effectively wraps a POST call to the dispatch server and
        forwards it to the frontend. The first handler registered will
        be used as the primary 
    '''
    handlers = get_handlers(model)
    result = []
    if not handlers:
        logging.warn("No handler defined for %s" % model) 
    for handler in handlers:
        handler_instance = handler(auth=auth)
        caller = handler.getattr('read_model', None)
        if caller:
            if result:
                caller(obj,*args,**kwargs)
            else:
                result = caller(obj,*args,**kwargs)
        else:
            logging.warn("No callable defined.")
    return result

def update(model, obj, auth=None, *args, **kwargs):
    ''' Handles the instance fetch in the backend and returns a list
        of objects created.
        
        This effectively wraps a PUT call to the dispatch server and
        forwards it to the frontend. The first handler registered will
        be used as the primary 
    '''
    handlers = get_handlers(model)
    result = []
    if not handlers:
        logging.warn("No handler defined for %s" % model) 
    for handler in handlers:
        handler_instance = handler(auth=auth)
        caller = handler.getattr('update_model', None)
        if caller:
            if result:
                caller(obj,*args,**kwargs)
            else:
                result = caller(obj,*args,**kwargs)
        else:
            logging.warn("No callable defined.")
    return result

def delete(model, obj, auth=None, *args, **kwargs):
    ''' Handles the instance delete in the backend and returns a list
        of objects created.
        
        This effectively wraps a DELETE call to the dispatch server and
        forwards it to the frontend. The first handler registered will
        be used as the primary 
    '''
    handlers = get_handlers(model)
    result = []
    if not handlers:
        logging.warn("No handler defined for %s" % model) 
    for handler in handlers:
        handler_instance = handler(auth=auth)
        caller = handler.getattr('delete_model', None)
        if caller:
            if result:
                caller(obj,*args,**kwargs)
            else:
                result = caller(obj,*args,**kwargs)
        else:
            logging.warn("No callable defined.")
    return result<commit_msg>Update to the abstract backend handler.<commit_after>'''
Provides access to pluggable backend infrastructucture.

Target backends must be configured in the settings by adding
the desired backend to the value of the TARGET variable.
'''
import logging

__all__ = [
    'AbstractHandler',
    'register_handler',
    'remove_handler',
    'get_handlers',
    'create',
    'read',
    'update',
    'delete',
]
_handlers = {
    'Concept': [],
    'RelationShip': [],
    'RelationshipCategory':[],
    'Device': [],
    'Encounter': [],
    'Event': [],
    'Instruction': [],
    'Location':[],
    'Notification': [],
    'Procedure':[],
    'Observation':[],
    'Observer'[],
    'Procedure': [],
    'Subject':[],
}

class AbstractHandler(object)
    def __init__(self, model, **kwargs):
        pass
    
    def create_concept(self):
        return None

    def create_relationship(self):
        return None
    
    def create_relationshipcategory(self):
        return None
    
    def create_device(self):
        return None
    
    def create_encounter(self):
        return None
    
    def create_event(self):
        return None
    
    def create_instruction(self):
        return None
    
    def create_location(self):
        return None
    
    def create_notification(self):
        return None
    
    def create_observation(self):
        return None
    
    def create_observer(self):
        return None
    
    def create_procedure(self):
        return None
    
    def create_subject(self):
        return None
    
    # Read functions
    def read_concept(self):
        return None
    
    def read_relationship(self):
        return None
    
    def read_relationshipcategory(self):
        return None
    
    def read_device(self):
        return None
    
    def read_encounter(self):
        return None
    
    def read_event(self):
        return None
    
    def read_instruction(self):
        return None
    
    def read_location(self):
        return None
    
    def read_notification(self):
        return None
    
    def read_observation(self):
        return None
    
    def read_observer(self):
        return None
    
    def read_procedure(self)
        return None:
    
    def read_subject(self):
        return None

    # update methods
    def update_concept(self):
        return None
    
    def update_relationship(self):
        return None
    
    def update_relationshipcategory(self):
        return None
    
    def update_device(self):
        return None
    
    def update_encounter(self):
        return None
    
    def update_event(self):
        return None
    
    def update_instruction(self):
        return None
    
    def update_location(self):
        return None
    
    def update_notification(self):
        return None
    
    def update_observation(self):
        return None
    
    def update_observer(self):
        return None
    
    def update_procedure(self)
        return None:
    
    def update_subject(self):
        return None
    
    # Delete methods
    def delete_concept(self):
        return None
    
    def delete_relationship(self):
        return None
    
    def delete_relationshipcategory(self):
        return None
    
    def delete_device(self):
        return None
    
    def delete_encounter(self):
        return None
    
    def delete_event(self):
        return None
    
    def delete_instruction(self):
        return None
    
    def delete_location(self):
        return None
    
    def delete_notification(self):
        return None
    
    def delete_observation(self):
        return None
    
    def delete_observer(self):
        return None
    
    def delete_procedure(self)
        return None:
    
    def delete_subject(self):
        return None
    


def register_handler(model, target):
    pass

def remove_handler(model, target):
    pass

def get_handlers(model):
    ''' Returns the callable for sending the instance 
        to the target.
    '''
    return _handlers.get(model, [])

def create(model, obj, auth=None, *args, **kwargs):
    ''' Handles the instance creation in the backend and returns a list
        of objects created.
        
        This effectively wraps a POST call to the dispatch server and
        forwards it to the frontend. The first handler registered will
        be used as the primary 
    '''
    handlers = get_handlers(model)
    result = []
    if not handlers:
        logging.warn("No handler defined for %s" % model) 
    for handler in handlers:
        handler_instance = handler(auth=auth)
        caller = handler.getattr('create_%s' % model.lower(), None)
        if caller:
            if result:
                caller(obj,*args,**kwargs)
            else:
                result = caller(obj,*args,**kwargs)
        else:
            logging.warn("No callable defined.")
    return result

def read(model, obj, auth=None, *args, **kwargs):
    ''' Handles the instance fetch in the backend and returns a list
        of objects created.
        
        This effectively wraps a POST call to the dispatch server and
        forwards it to the frontend. The first handler registered will
        be used as the primary 
    '''
    handlers = get_handlers(model)
    result = []
    if not handlers:
        logging.warn("No handler defined for %s" % model) 
    for handler in handlers:
        handler_instance = handler(auth=auth)
        caller = handler.getattr('read_%s' % model.lower(), None)
        if caller:
            if result:
                caller(obj,*args,**kwargs)
            else:
                result = caller(obj,*args,**kwargs)
        else:
            logging.warn("No callable defined.")
    return result

def update(model, obj, auth=None, *args, **kwargs):
    ''' Handles the instance fetch in the backend and returns a list
        of objects created.
        
        This effectively wraps a PUT call to the dispatch server and
        forwards it to the frontend. The first handler registered will
        be used as the primary 
    '''
    handlers = get_handlers(model)
    result = []
    if not handlers:
        logging.warn("No handler defined for %s" % model) 
    for handler in handlers:
        handler_instance = handler(auth=auth)
        caller = handler.getattr('update_%s' % model.lower(), None)
        if caller:
            if result:
                caller(obj,*args,**kwargs)
            else:
                result = caller(obj,*args,**kwargs)
        else:
            logging.warn("No callable defined.")
    return result

def delete(model, obj, auth=None, *args, **kwargs):
    ''' Handles the instance delete in the backend and returns a list
        of objects created.
        
        This effectively wraps a DELETE call to the dispatch server and
        forwards it to the frontend. The first handler registered will
        be used as the primary 
    '''
    handlers = get_handlers(model)
    result = []
    if not handlers:
        logging.warn("No handler defined for %s" % model) 
    for handler in handlers:
        handler_instance = handler(auth=auth)
        caller = handler.getattr('delete_%s' % model.lower(), None)
        if caller:
            if result:
                caller(obj,*args,**kwargs)
            else:
                result = caller(obj,*args,**kwargs)
        else:
            logging.warn("No callable defined.")
    return result
{'fraction_non_alphanumeric': 0.08634368669817691, 'fraction_numerical': 0.0, 'mean_word_length': 2.085677083333333, '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': '4915784', 'n_tokens_mistral': 3229, 'n_tokens_neox': 3155, 'n_words': 1038}