<commit_before>

class StateMachine(object):
    
    def __init__(self):

        # The four main states of the state machine:
        self.__NOT_STARTED_YET = 0
        self.__WAITING_TO_BE_AVAILABLE = 1
        self.__IS_AVAILABLE = 2
        self.__IS_AVAILABLE_BUT_WANTS_TO_STOP = 3
        self.__PERMANENTLY_UNAVAILABLE = 4 # roughly corresponds to _stopping and _closing in pika usage example.

        # Init state machine:
        self.__state = self.__NOT_STARTED_YET

        # More detail
        self.detail_closed_by_publisher = False
        self.detail_asked_to_closed_by_publisher = False
        self.detail_could_not_connect = False
        self.detail_authentication_exception = False

    #
    # Setters
    #

    ''' Called by the rabbit thread.'''
    def set_to_available(self):
        self.__state = self.__IS_AVAILABLE

    ''' Called by the main thread.'''
    def set_to_wanting_to_stop(self):
        self.__state = self.__IS_AVAILABLE_BUT_WANTS_TO_STOP

    ''' Called by the main thread.'''
    def set_to_waiting_to_be_available(self):
        self.__state = self.__WAITING_TO_BE_AVAILABLE

    ''' Called by the rabbit thread.'''
    def set_to_permanently_unavailable(self):
        self.__state = self.__PERMANENTLY_UNAVAILABLE

    #
    # Getters for states
    #

    def is_NOT_STARTED_YET(self):
        if self.__state == self.__NOT_STARTED_YET:
            return True
        return False

    def is_WAITING_TO_BE_AVAILABLE(self):
        if self.__state == self.__WAITING_TO_BE_AVAILABLE:
            return True
        return False

    def is_AVAILABLE(self):
        if self.__state == self.__IS_AVAILABLE:
            return True
        return False

    def is_AVAILABLE_BUT_WANTS_TO_STOP(self):
        if self.__state == self.__IS_AVAILABLE_BUT_WANTS_TO_STOP:
            return True
        return False

    def is_PERMANENTLY_UNAVAILABLE(self):
        if self.__state == self.__PERMANENTLY_UNAVAILABLE:
            return True
        return False

    #
    # Combined getters
    # (convenience wrappers)
    #

    def is_available_for_client_publishes(self):
        return self.__IS_AVAILABLE

    def is_available_for_server_communication(self):
        if self.__IS_AVAILABLE:
            return True
        if self.__IS_AVAILABLE_BUT_WANTS_TO_STOP:
            return True
        return False




    #
    # Reasons for closing
    #

    '''
    Needed by asynchronous.py to inform if messages
    are not accepted anymore.
    '''
    def get_reason_shutdown(self):
        if self.detail_closed_by_publisher or self.detail_asked_to_closed_by_publisher:
            return 'Was closed by publisher'
        elif self.detail_could_not_connect:
            return 'Could not connect'
        elif self.detail_authentication_exception:
            return 'Could not authenticate'
        else:
            return 'Unknown'<commit_msg>Removed unused methods.<commit_after>

class StateMachine(object):
    
    def __init__(self):

        # The four main states of the state machine:
        self.__NOT_STARTED_YET = 0
        self.__WAITING_TO_BE_AVAILABLE = 1
        self.__IS_AVAILABLE = 2
        self.__IS_AVAILABLE_BUT_WANTS_TO_STOP = 3
        self.__PERMANENTLY_UNAVAILABLE = 4 # roughly corresponds to _stopping and _closing in pika usage example.

        # Init state machine:
        self.__state = self.__NOT_STARTED_YET

        # More detail
        self.detail_closed_by_publisher = False
        self.detail_asked_to_closed_by_publisher = False
        self.detail_could_not_connect = False
        self.detail_authentication_exception = False

    #
    # Setters
    #

    ''' Called by the rabbit thread.'''
    def set_to_available(self):
        self.__state = self.__IS_AVAILABLE

    ''' Called by the main thread.'''
    def set_to_wanting_to_stop(self):
        self.__state = self.__IS_AVAILABLE_BUT_WANTS_TO_STOP

    ''' Called by the main thread.'''
    def set_to_waiting_to_be_available(self):
        self.__state = self.__WAITING_TO_BE_AVAILABLE

    ''' Called by the rabbit thread.'''
    def set_to_permanently_unavailable(self):
        self.__state = self.__PERMANENTLY_UNAVAILABLE

    #
    # Getters for states
    #

    def is_NOT_STARTED_YET(self):
        if self.__state == self.__NOT_STARTED_YET:
            return True
        return False

    def is_WAITING_TO_BE_AVAILABLE(self):
        if self.__state == self.__WAITING_TO_BE_AVAILABLE:
            return True
        return False

    def is_AVAILABLE(self):
        if self.__state == self.__IS_AVAILABLE:
            return True
        return False

    def is_AVAILABLE_BUT_WANTS_TO_STOP(self):
        if self.__state == self.__IS_AVAILABLE_BUT_WANTS_TO_STOP:
            return True
        return False

    def is_PERMANENTLY_UNAVAILABLE(self):
        if self.__state == self.__PERMANENTLY_UNAVAILABLE:
            return True
        return False


    '''
    Needed by asynchronous.py to inform if messages
    are not accepted anymore.
    '''
    def get_reason_shutdown(self):
        if self.detail_closed_by_publisher or self.detail_asked_to_closed_by_publisher:
            return 'Was closed by publisher'
        elif self.detail_could_not_connect:
            return 'Could not connect'
        elif self.detail_authentication_exception:
            return 'Could not authenticate'
        else:
            return 'Unknown'
{'fraction_non_alphanumeric': 0.06358274972355327, 'fraction_numerical': 0.0018429782528566164, 'mean_word_length': 2.436985433818873, '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': '3625779', 'n_tokens_mistral': 1709, 'n_tokens_neox': 1645, 'n_words': 364}