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


from __future__ import print_function


import json

from api import API
from schema_manager import SchemaManager
from client import Client
from util import to_camel_case


def discover(url):
    """
    Retrieve the API definition from the given URL and construct
    a Patchboard to interface with it.
    """
    # Retrieve JSON data from server
    # Treat url like a file and read mock JSON for now
    with open(url, u"r") as file:
        api_spec = json.load(file)

    return Patchboard(api_spec)


class Patchboard(object):
    """
    The primary client interface to a patchboard server.
    """

    def __init__(self, api_spec):
        self.api = API(api_spec)

        self.schema_manager = SchemaManager(self.api.schemas)
        self.endpoint_classes = self.create_endpoint_classes()
        client = self.spawn()
        # Appears to be unused
        #self.resources = client.resources
        self.context = client.context

    def create_endpoint_classes(self):
        classes = {}
        for resource_name, mapping in self.api.mappings.iteritems():
            if resource_name not in classes:
                schema = self.schema_manager.find_name(resource_name)
                resource_def = mapping.resource
                cls = self.create_class(
                    resource_name,
                    resource_def,
                    schema,
                    mapping)
                classes[resource_name] = cls

        return classes

    def create_class(self, resource_name, definition, schema, mapping):
        # Cannot use unicode for class names
        class_name = to_camel_case(str(resource_name))

        class_parents = (object,)
        # TODO: fill in stub class definition
        class_body = """
def __init__(self):
    pass
        """
        class_dict = {}
        exec(class_body, globals(), class_dict)
        cls = type(class_name, class_parents, class_dict)
        return cls

    def spawn(self, context={}):
        return Client(context, self.api, self.endpoint_classes)<commit_msg>Remove useless code<commit_after># patchboard.py
#
# Copyright 2014 BitVault.


from __future__ import print_function


import json

from resource import Resource
from api import API
from schema_manager import SchemaManager
from client import Client
from util import to_camel_case


def discover(url):
    """
    Retrieve the API definition from the given URL and construct
    a Patchboard to interface with it.
    """
    # Retrieve JSON data from server
    # Treat url like a file and read mock JSON for now
    with open(url, u"r") as file:
        api_spec = json.load(file)

    return Patchboard(api_spec)


class Patchboard(object):
    """
    The primary client interface to a patchboard server.
    """

    def __init__(self, api_spec):
        self.api = API(api_spec)

        self.schema_manager = SchemaManager(self.api.schemas)
        self.endpoint_classes = self.create_endpoint_classes()
        client = self.spawn()
        # Appears to be unused
        #self.resources = client.resources
        self.context = client.context

    def create_endpoint_classes(self):
        classes = {}
        for resource_name, mapping in self.api.mappings.iteritems():
            if resource_name not in classes:
                schema = self.schema_manager.find_name(resource_name)
                resource_def = mapping.resource
                cls = self.create_class(
                    resource_name,
                    resource_def,
                    schema,
                    mapping)
                classes[resource_name] = cls

        return classes

    def create_class(self, resource_name, definition, schema, mapping):
        # Cannot use unicode for class names
        class_name = to_camel_case(str(resource_name))

        class_parents = (Resource,)
        class_dict = {}
        cls = type(class_name, class_parents, class_dict)
        return cls

    def spawn(self, context={}):
        return Client(context, self.api, self.endpoint_classes)
{'fraction_non_alphanumeric': 0.07362262311067772, 'fraction_numerical': 0.0019502681618722574, 'mean_word_length': 2.3357723577235774, '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': '888843', 'n_tokens_mistral': 1133, 'n_tokens_neox': 1073, 'n_words': 332}