<commit_before>from .endpoint import ApiEndpoint, BoundApiEndpoint

class BoundApiResource(object):
  def __init__(self, resource, id, api_url):
    self._resource = resource
    self._id = id

    if id is None:
      self._base_url = api_url
    else:
      self._base_url = '{api_url}/{id}'.format(
      api_url=api_url,
      id=id,
    )

  def __getattr__(self, attr):
    endpoint = self._resource._endpoints.get(attr)
    if endpoint:
      return BoundApiEndpoint(self, endpoint)
    else:
      sub_resource = self._resource._sub_resources.get(attr)
      if sub_resource:
        return PartiallyBoundApiResource(sub_resource, self)
    raise AttributeError(attr)

class PartiallyBoundApiResource(object):
  def __init__(self, resource, bound_parent_resource):
    self._resource = resource
    self._bound_parent_resource = bound_parent_resource

  def __call__(self, id=None):
    api_url = '{parent_api_url}/{name}'.format(
      parent_api_url=self._bound_parent_resource._base_url,
      name=self._resource._name
    )
    return BoundApiResource(self._resource, id, api_url)

class BaseApiResource(object):
  def __init__(self, conn, name, version, endpoints=None, resources=None):
    self._conn = conn
    self._name = name
    self._version = version

    self._endpoints = dict((
      (endpoint._attribute_name, endpoint)
      for endpoint
      in endpoints
    )) if endpoints else {}

    self._sub_resources = dict((
      (resource._name, resource)
      for resource
      in resources
    )) if resources else {}

  def __call__(self, id=None):
    api_url = '{api_url}/{version}/{name}'.format(
      api_url=self._conn.api_url,
      version=self._version,
      name=self._name,
    )
    return BoundApiResource(self, id, api_url)

class ApiResource(BaseApiResource):
  def __init__(self, conn, name, response_cls, endpoints):
    super(ApiResource, self).__init__(
      conn=conn,
      name=name,
      version='v0',
      endpoints=(endpoints + [
        ApiEndpoint(None, response_cls, 'GET', 'fetch'),
      ])
    )

  def create(self, **kwargs):
    return self._response_cls(
      self._conn._post(self._base_url('create'), kwargs),
    )

  def _base_url(self, suffix):
    return '{api_url}/{version}/{name}/{suffix}'.format(
      api_url=self._conn.api_url,
      version=self._version,
      name=self._name,<commit_msg>response class on v0 object only<commit_after>from .endpoint import ApiEndpoint, BoundApiEndpoint

class BoundApiResource(object):
  def __init__(self, resource, id, api_url):
    self._resource = resource
    self._id = id

    if id is None:
      self._base_url = api_url
    else:
      self._base_url = '{api_url}/{id}'.format(
      api_url=api_url,
      id=id,
    )

  def __getattr__(self, attr):
    endpoint = self._resource._endpoints.get(attr)
    if endpoint:
      return BoundApiEndpoint(self, endpoint)
    else:
      sub_resource = self._resource._sub_resources.get(attr)
      if sub_resource:
        return PartiallyBoundApiResource(sub_resource, self)
    raise AttributeError(attr)

class PartiallyBoundApiResource(object):
  def __init__(self, resource, bound_parent_resource):
    self._resource = resource
    self._bound_parent_resource = bound_parent_resource

  def __call__(self, id=None):
    api_url = '{parent_api_url}/{name}'.format(
      parent_api_url=self._bound_parent_resource._base_url,
      name=self._resource._name
    )
    return BoundApiResource(self._resource, id, api_url)

class BaseApiResource(object):
  def __init__(self, conn, name, version, endpoints=None, resources=None):
    self._conn = conn
    self._name = name
    self._version = version

    self._endpoints = dict((
      (endpoint._attribute_name, endpoint)
      for endpoint
      in endpoints
    )) if endpoints else {}

    self._sub_resources = dict((
      (resource._name, resource)
      for resource
      in resources
    )) if resources else {}

  def __call__(self, id=None):
    api_url = '{api_url}/{version}/{name}'.format(
      api_url=self._conn.api_url,
      version=self._version,
      name=self._name,
    )
    return BoundApiResource(self, id, api_url)

class ApiResource(BaseApiResource):
  def __init__(self, conn, name, response_cls, endpoints):
    super(ApiResource, self).__init__(
      conn=conn,
      name=name,
      version='v0',
      endpoints=(endpoints + [
        ApiEndpoint(None, response_cls, 'GET', 'fetch'),
      ])
    )
    self._response_cls = response_cls

  def create(self, **kwargs):
    return self._response_cls(
      self._conn._post(self._base_url('create'), kwargs),
    )

  def _base_url(self, suffix):
    return '{api_url}/{version}/{name}/{suffix}'.format(
      api_url=self._conn.api_url,
      version=self._version,
      name=self._name,
{'fraction_non_alphanumeric': 0.11294019587414045, 'fraction_numerical': 0.000625130235465722, 'mean_word_length': 3.316546762589928, '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': '4396093', 'n_tokens_mistral': 1522, 'n_tokens_neox': 1491, 'n_words': 306}