<commit_before>from adhocracy.properties.interfaces import IProperty
from adhocracy.resources import interfaces
from adhocracy.utils import (
    get_ifaces_from_module,
    get_all_taggedvalues,
)
from substanced.content import add_content_type
from zope.dottedname.resolve import resolve
from zope.interface import directlyProvides


class ResourceFactory(object):

    """Basic resource factory."""

    def __init__(self, iface):
        assert iface.isOrExtends(interfaces.IResource)
        taggedvalues = get_all_taggedvalues(iface)
        self.class_ = resolve(taggedvalues["content_class"])
        self.resource_iface = iface
        base_ifaces = taggedvalues["basic_properties_interfaces"]
        ext_ifaces = taggedvalues["extended_properties_interfaces"]
        self.prop_ifaces = [resolve(i) for i in base_ifaces.union(ext_ifaces)]
        for i in self.prop_ifaces:
            assert i.isOrExtends(IProperty)

    def __call__(self, **kwargs):
        content = self.class_()
        directlyProvides(content, [self.resource_iface] + self.prop_ifaces)<commit_msg>resource factory: use alsoProvides instead of directlyProvides to apply iproperty ifaces<commit_after>from adhocracy.properties.interfaces import IProperty
from adhocracy.resources import interfaces
from adhocracy.utils import (
    get_ifaces_from_module,
    get_all_taggedvalues,
)
from substanced.content import add_content_type
from zope.dottedname.resolve import resolve
from zope.interface import (
    directlyProvides,
    alsoProvides,
)


class ResourceFactory(object):

    """Basic resource factory."""

    def __init__(self, iface):
        assert iface.isOrExtends(interfaces.IResource)
        taggedvalues = get_all_taggedvalues(iface)
        self.class_ = resolve(taggedvalues["content_class"])
        self.resource_iface = iface
        base_ifaces = taggedvalues["basic_properties_interfaces"]
        ext_ifaces = taggedvalues["extended_properties_interfaces"]
        self.prop_ifaces = [resolve(i) for i in base_ifaces.union(ext_ifaces)]
        for i in self.prop_ifaces:
            assert i.isOrExtends(IProperty)

    def __call__(self, **kwargs):
        content = self.class_()
        directlyProvides(content, self.resource_iface)
        alsoProvides(content, self.prop_ifaces)
{'fraction_non_alphanumeric': 0.07886710239651416, 'fraction_numerical': 0.0, 'mean_word_length': 4.079646017699115, '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': '5554601', 'n_tokens_mistral': 683, 'n_tokens_neox': 660, 'n_words': 141}