<commit_before># resource.py
#
# Copyright 2014 BitVault.


from __future__ import print_function

import json

from action import Action
from exception import PatchboardError


class ResourceType(type):
    """A metaclass for resource classes."""

    # Must override to supply  default arguments
    def __new__(cls, name, patchboard, definition, schema, mapping):
        return type.__new__(cls, name, (Resource,), {})

    def __init__(cls, name, patchboard, definition, schema, mapping):

        setattr(cls, 'api', classmethod(lambda(self_): patchboard.api))

        setattr(cls, 'schema', classmethod(lambda(self_): schema))

        setattr(cls, 'mapping', classmethod(lambda(self_): mapping))

        if schema:
            if u'properties' in schema:
                for name, schema_def in schema[u'properties'].iteritems():
                    setattr(
                        cls,
                        name,
                        lambda(self): self.attributes[name])

            if schema.get(u'additionalProperties', False) is not False:
                def additional_fn(self, name, *args):
                    # TODO: see if this is the right implementation; the
                    # ruby code intercepts calls *before* normal lookup,
                    # so possibly this should use __getattribute__. OTOH
                    # that may just be an artifact of Ruby and not part
                    # of the design.
                    try:
                        return self.attributes[name]
                    except KeyError:
                        raise AttributeError

                setattr(cls, '__getattr__', additional_fn)

        setattr(
            cls,
            'generate_url',
            classmethod(
                lambda(self_, params): mapping.generate_url(params)))

        for name, action in definition[u'actions'].iteritems():
            action = Action(patchboard, name, action)

            def action_fn(self, *args):
                return action.request(self, self.url, args)

            setattr(cls, name, action_fn)

        # Must be called last
        super(ResourceType, cls).__init__(name, (Resource,), {})


class Resource(object):<commit_msg>Fix varargs splat<commit_after># resource.py
#
# Copyright 2014 BitVault.


from __future__ import print_function

import json

from action import Action
from exception import PatchboardError


class ResourceType(type):
    """A metaclass for resource classes."""

    # Must override to supply  default arguments
    def __new__(cls, name, patchboard, definition, schema, mapping):
        return type.__new__(cls, name, (Resource,), {})

    def __init__(cls, name, patchboard, definition, schema, mapping):

        setattr(cls, 'api', classmethod(lambda(self_): patchboard.api))

        setattr(cls, 'schema', classmethod(lambda(self_): schema))

        setattr(cls, 'mapping', classmethod(lambda(self_): mapping))

        if schema:
            if u'properties' in schema:
                for name, schema_def in schema[u'properties'].iteritems():
                    setattr(
                        cls,
                        name,
                        lambda(self): self.attributes[name])

            if schema.get(u'additionalProperties', False) is not False:
                def additional_fn(self, name, *args):
                    # TODO: see if this is the right implementation; the
                    # ruby code intercepts calls *before* normal lookup,
                    # so possibly this should use __getattribute__. OTOH
                    # that may just be an artifact of Ruby and not part
                    # of the design.
                    try:
                        return self.attributes[name]
                    except KeyError:
                        raise AttributeError

                setattr(cls, '__getattr__', additional_fn)

        setattr(
            cls,
            'generate_url',
            classmethod(
                lambda(self_, params): mapping.generate_url(params)))

        for name, action in definition[u'actions'].iteritems():
            action = Action(patchboard, name, action)

            def action_fn(self, *args):
                return action.request(self, self.url, *args)

            setattr(cls, name, action_fn)

        # Must be called last
        super(ResourceType, cls).__init__(name, (Resource,), {})


class Resource(object):
{'fraction_non_alphanumeric': 0.09029497860842153, 'fraction_numerical': 0.0018013960819635217, 'mean_word_length': 1.9051667756703727, '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': '1269509', 'n_tokens_mistral': 1150, 'n_tokens_neox': 1069, 'n_words': 341}