<commit_before>from requests.api import request
from itertools import chain


def extend(base, name=None, **kwargs):
    return type(name, (base,), kwargs)


class Entity(dict):
    __getattr__ = dict.get

    def __repr__(self):
        printable = self.name or self.id

        if not printable:
            return super(Entity, self).__repr__()

        return '%s: %s' % (
            self.__class__.__name__,
            printable.encode("utf-8")
        )


Signal = extend(Entity, 'Signal')
Path = extend(Entity, 'Path')


class Edge(Entity):

    def to_signal(self, action, graph):
        # signal types: create or update
        action = "edge_%s" % action

        from_id, to_id = map(self.get, ('from', 'to'))
        from_node = graph.get_node(from_id)
        to_node = graph.get_node(to_id)
        kwargs = dict(action=action,
                      name=self.edge_type,
                      from_name=from_node.name,
                      from_type=from_node.type,
                      to_name=to_node.name,
                      to_type=to_node.type,
                      reference=self.get('reference', None),
                      weight=self.get('weight'),
                      properties=self.properties)
        return Signal(**kwargs)


class Node(Entity):

    def to_signal(self, action, graph):
        # signal types: create or update
        action = "node_%s" % action
        kwargs = dict(action=action,
                      name=self.name,
                      type=self.type['name'],
                      reference=self.reference,
                      image=self.image,
                      color=self.type['color'],
                      url=self.url,
                      description=self.description,
                      properties=self.properties)
        return Signal(**kwargs)


class EdgeType(Entity):

    def to_signal(self, action):
        action = "edgetype_%s" % action
        kwargs = dict(action=action)
        kwargs.update(dict((k, self.get(k, None)) for k in ['name', 'color', 'name_alias', 'weighted',
                                                            'properties', 'image_as_icon', 'image']))
        return Signal(**kwargs)


class NodeType(Entity):

    def to_signal(self, action):
        action = "nodetype_%s" % action
        kwargs = dict(action=action)
        kwargs.update(dict((k, self.get(k, None)) for k in ['name', 'color', 'name_alias', 'size_limit',<commit_msg>Switching to UserDict as base class for Entity, removing extends function<commit_after>from collections import UserDict
from requests.api import request
from itertools import chain


class Entity(UserDict):
    """Base class for all objects."""


class Signal(Entity):
    """Represents a signal operation in the Graph Commons infrastructure."""


class Path(Entity):
    """Represents a path object in the Graph Commons infrastructure."""


class Edge(Entity):
    """Represents an edge object in the Graph Commons infrastructure."""

    def to_signal(self, action, graph):
        # signal types: create or update
        action = "edge_%s" % action

        from_id, to_id = map(self.get, ('from', 'to'))
        from_node = graph.get_node(from_id)
        to_node = graph.get_node(to_id)
        kwargs = dict(action=action,
                      name=self.edge_type,
                      from_name=from_node.name,
                      from_type=from_node.type,
                      to_name=to_node.name,
                      to_type=to_node.type,
                      reference=self.get('reference', None),
                      weight=self.get('weight'),
                      properties=self.properties)
        return Signal(**kwargs)


class Node(Entity):
    """Represents a node object in the Graph Commons infrastructure."""

    def to_signal(self, action, graph):
        # signal types: create or update
        action = "node_%s" % action
        kwargs = dict(action=action,
                      name=self.name,
                      type=self.type['name'],
                      reference=self.reference,
                      image=self.image,
                      color=self.type['color'],
                      url=self.url,
                      description=self.description,
                      properties=self.properties)
        return Signal(**kwargs)


class EdgeType(Entity):
    """Represents an edge type object in the Graph Commons infrastructure."""

    def to_signal(self, action):
        action = "edgetype_%s" % action
        kwargs = dict(action=action)
        kwargs.update(dict((k, self.get(k, None)) for k in ['name', 'color', 'name_alias', 'weighted',
                                                            'properties', 'image_as_icon', 'image']))
        return Signal(**kwargs)


class NodeType(Entity):
    """Represents a node type object in the Graph Commons infrastructure."""

    def to_signal(self, action):
        action = "nodetype_%s" % action
        kwargs = dict(action=action)
        kwargs.update(dict((k, self.get(k, None)) for k in ['name', 'color', 'name_alias', 'size_limit',
{'fraction_non_alphanumeric': 0.11317435496481626, 'fraction_numerical': 0.00019546520719311962, 'mean_word_length': 1.9374282433983927, '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': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2919697', 'n_tokens_mistral': 1402, 'n_tokens_neox': 1328, 'n_words': 345}