<commit_before>'''
helper functions to work with fanstatic
'''

from js.socialshareprivacy import library
import fanstatic


def get_socialshareprivacy_url():
    '''
    call this after you need()ed socialshareprivacy!
    Returns the url from which socialshareprivacy will be shipped.
    '''
    return fanstatic.get_needed().library_url(library)


def _get_resource(module, name):
    resource = getattr(module, name, None)
    if resource is None:
        raise AttributeError('"%s" does not exist' % name)
    if not isinstance(resource, (fanstatic.Resource, fanstatic.Group)):
        raise ValueError('"%s" is not a valid Resource' % name)
    return resource


class FanstaticNeedHelper(object):
    '''
    A helper class to access fanstatic resources
    defined in :module:`adhocracy.static`

    Use it this way::

        from adhocracy import static
        need = FanstaticNeedHelper(static)
        need.stylesheets

    where "stylesheets" is a fanstatic Resource or Group defined
    in adhocracy.static.
    '''

    def __init__(self, module):
        self.module = module

    def __getattr__(self, name):
        return _get_resource(self.module, name).need()<commit_msg>Allow dynamic fanstatic resources<commit_after>'''
helper functions to work with fanstatic
'''

from js.socialshareprivacy import library
import fanstatic


def get_socialshareprivacy_url():
    '''
    call this after you need()ed socialshareprivacy!
    Returns the url from which socialshareprivacy will be shipped.
    '''
    return fanstatic.get_needed().library_url(library)


def _get_resource(module, name):
    resource = getattr(module, name, None)
    if resource is None:
        raise AttributeError('"%s" does not exist' % name)
    if not isinstance(resource, (fanstatic.Resource, fanstatic.Group)):
        raise ValueError('"%s" is not a valid Resource' % name)
    return resource


class FanstaticNeedHelper(object):
    '''
    A helper class to access fanstatic resources
    defined in :module:`adhocracy.static`

    Use it this way::

        from adhocracy import static
        need = FanstaticNeedHelper(static)
        need.stylesheets

    where "stylesheets" is a fanstatic Resource or Group defined
    in adhocracy.static.
    '''

    def __init__(self, module):
        self.module = module
        self.dynamics = {}

    def load_dynamic(self, name, *args, **kwargs):
        if name not in self.dynamics:
            resource_fun = getattr(self.module, name, None)
            if resource_fun is not None:
                assert(type(resource_fun) == type(lambda: None))
                self.dynamics[name] = resource_fun(*args, **kwargs)

        return self.dynamics[name].need()

    def __getattr__(self, name):
        return _get_resource(self.module, name).need()
{'fraction_non_alphanumeric': 0.09172019985724482, 'fraction_numerical': 0.0, 'mean_word_length': 3.1773472429210132, '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': '7050173', 'n_tokens_mistral': 800, 'n_tokens_neox': 763, 'n_words': 248}