<commit_before>from copy import copy
from distutils.util import strtobool


def cast_string_to_type(
    value: str,
    cast: [str, bool, int]
) -> [str, bool, int]:
    if cast is str:
        return value
    elif cast is bool:
        return strtobool(value)
    elif cast is int:
        return int(value)
    else:
        raise KeyError('Invalid `cast` param')


class CallistoCoreTenantApi(object):

    def get_current_domain(self):
        return 1

    @staticmethod
    def site_settings(var, cast=str, request=None, site_id=1):
        '''
        Implement this function to provide multi-tenant functionality for
        you application. You need to be able to derive your current tenant from
        either request or site_id (preferably both)

        The implementation here is a naive mock of a similar implementation in
        callisto campus

        Use like:
            from callisto_core.utils.tenant_api import TenantApi
            TenantApi.site_settings('SOME_NUMBER', cast=int, site_id=10)
        '''
        if request:
            try:
                site_id = request.site.id
            except BaseException:
                site_id = 1

        default_values = {
            'DEMO_MODE': 'False',
            'DISABLE_SIGNUP': 'False',
            'SCHOOL_SHORTNAME': 'callisto-core',
            'COORDINATOR_NAME': 'COORDINATOR_NAME',
            'COORDINATOR_EMAIL': '<EMAIL>',
            'SCHOOL_EMAIL_DOMAIN': 'example.com',
            'COORDINATOR_PUBLIC_KEY': '''
-----BEGIN PGP PUBLIC KEY BLOCK-----
Comment: GPGTools - https://gpgtools.org

<KEY>
SdADsbZ7cCpVm2M/zAaEjbAK7Cvlomiuw2tuyT3EQrfLF9NHb7fIgANuA6VWquNO
wqOE/S/GzEYNtC/a0JqcYF82dzEb3ZvMhezvDuEwCfOEtrQV9sXUUEakQyo/0bRO
dLVuR/ralT9J0wb8RXE9dEkWE38mMgH/GFCIGen+l3gJJOYv/k3xlMcF+Uu7HOeZ
LT31CQIXQkMvUkcbvBKm5ynWvLbcfUcKX0L/YoCUbfd8Mf5KIg3rFMMJZWWOduuq
ePJN/Gcjv69CLB7quZSYSYP6s+1SyKv9HzjHABEBAAG0DWNhbGxpc3RvLWNvcmWJ
ATcEEwEKACEFAldY2/0CGwMFCwkIBwMFFQoJCAsFFgIDAQACHgECF4AACgkQ6+nJ
/nll+xyUaAgAvtQrBbHRP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NxfAB
cL+QqgshFt79Yh0=
=3BvZ
-----END PGP PUBLIC KEY BLOCK-----
            ''',
        }

        defaults_with_signup_disabled = copy(default_values)
        defaults_with_signup_disabled['DISABLE_SIGNUP'] = 'True'

        defaults_with_demo_mode_enabled = copy(default_values)
        defaults_with_demo_mode_enabled['DEMO_MODE'] = 'True'

        site_values = {
            1: default_values,
            2: defaults_with_signup_disabled,
            3: default_values,
            4: defaults_with_demo_mode_enabled,
        }.get(site_id, {})

        value = site_values.get(var, '')
        value = cast_string_to_type(value, cast)

        return value
<commit_msg>silly string casting thing<commit_after>from copy import copy
from distutils.util import strtobool


def cast_string_to_type(
    value: str,
    cast: [str, bool, int]
) -> [str, bool, int]:
    if cast is str:
        return value
    elif cast is bool:
        return strtobool(value)
    elif cast is int:
        return int(value)
    else:
        raise KeyError('Invalid `cast` param')


class CallistoCoreTenantApi(object):

    def get_current_domain(self):
        return 1

    @staticmethod
    def site_settings(var, cast=str, request=None, site_id=1):
        '''
        Implement this function to provide multi-tenant functionality for
        you application. You need to be able to derive your current tenant from
        either request or site_id (preferably both)

        The implementation here is a naive mock of a similar implementation in
        callisto campus

        Use like:
            from callisto_core.utils.tenant_api import TenantApi
            TenantApi.site_settings('SOME_NUMBER', cast=int, site_id=10)
        '''
        if request:
            try:
                site_id = request.site.id
            except BaseException:
                site_id = 1

        default_values = {
            'DEMO_MODE': False,
            'DISABLE_SIGNUP': False,
            'SCHOOL_SHORTNAME': 'callisto-core',
            'COORDINATOR_NAME': 'COORDINATOR_NAME',
            'COORDINATOR_EMAIL': '<EMAIL>',
            'SCHOOL_EMAIL_DOMAIN': 'example.com',
            'COORDINATOR_PUBLIC_KEY': '''
-----BEGIN PGP PUBLIC KEY BLOCK-----
Comment: GPGTools - https://gpgtools.org

<KEY>
-----END PGP PUBLIC KEY BLOCK-----
            ''',
        }

        defaults_with_signup_disabled = copy(default_values)
        defaults_with_signup_disabled['DISABLE_SIGNUP'] = True

        defaults_with_demo_mode_enabled = copy(default_values)
        defaults_with_demo_mode_enabled['DEMO_MODE'] = True

        site_values = {
            1: default_values,
            2: defaults_with_signup_disabled,
            3: default_values,
            4: defaults_with_demo_mode_enabled,
        }.get(site_id, {})

        value = site_values.get(var, '')
        value = cast_string_to_type(str(value), cast)

        return value

{'fraction_non_alphanumeric': 0.07629654255319149, 'fraction_numerical': 0.036569148936170214, 'mean_word_length': 3.121232876712329, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5695568', 'n_tokens_mistral': 2582, 'n_tokens_neox': 2448, 'n_words': 360}