<commit_before># -*- coding: utf-8 -*-

from django.conf import settings
from django.core.exceptions import ImproperlyConfigured

from maintenance_mode import io


def get_maintenance_mode():
    # If maintenance mode is defined in settings, it has priority.
    if settings.MAINTENANCE_MODE is not None:
        return settings.MAINTENANCE_MODE

    value = io.read_file(settings.MAINTENANCE_MODE_STATE_FILE_PATH, '0')

    if value not in ['0', '1']:
        raise ValueError('state file content value is not 0|1')

    value = bool(int(value))
    return value


def set_maintenance_mode(value):
    # If maintenance mode is defined in settings, it can't be changed.
    if settings.MAINTENANCE_MODE is not None:
        raise ImproperlyConfigured('Maintenance mode cannot be set dynamically if defined in settings.')

    if not isinstance(value, bool):
        raise TypeError('value argument type is not boolean')

    value = str(int(value))
    io.write_file(settings.MAINTENANCE_MODE_STATE_FILE_PATH, value)<commit_msg>Improved code quality<commit_after># -*- coding: utf-8 -*-

from django.conf import settings
from django.core.exceptions import ImproperlyConfigured

from maintenance_mode import io


def get_maintenance_mode():
    # If maintenance mode is defined in settings, it has priority.
    if settings.MAINTENANCE_MODE is not None:
        return settings.MAINTENANCE_MODE

    value = io.read_file(settings.MAINTENANCE_MODE_STATE_FILE_PATH, '0')

    if value not in ['0', '1']:
        raise ValueError('state file content value is not 0|1')

    value = bool(int(value))
    return value


def set_maintenance_mode(value):
    # If maintenance mode is defined in settings, it can't be changed.
    if settings.MAINTENANCE_MODE is not None:
        raise ImproperlyConfigured(
            'Maintenance mode cannot be set dynamically ' \
            'if defined in settings.')

    if not isinstance(value, bool):
        raise TypeError('value argument type is not boolean')

    value = str(int(value))
    io.write_file(settings.MAINTENANCE_MODE_STATE_FILE_PATH, value)
{'fraction_non_alphanumeric': 0.07975167144221586, 'fraction_numerical': 0.0057306590257879654, 'mean_word_length': 3.645232815964523, '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': '481804', 'n_tokens_mistral': 615, 'n_tokens_neox': 604, 'n_words': 202}