<commit_before>from . import errors
from . import backends
import json
import logging
import datetime
import urlparse
import os

try:
  import spaceapi
except ImportError:
  spaceapi = None

log = logging.getLogger('spiff')

class SpiffObjectEncoder(json.JSONEncoder):
  def __init__(self, api, *args, **kwargs):
    super(SpiffObjectEncoder, self).__init__(*args, **kwargs)
    self.__api = api

  def default(self, obj):
    if isinstance(obj, SpiffObject):
      return obj.resource_uri
    if isinstance(obj, datetime.date):
      return str(obj)
    if isinstance(obj, ObjectList):
      l = []
      for o in obj:
        l.append(o.resource_uri)
      return self.default(l)
    try:
      iterable = iter(obj)
    except TypeError:
      pass
    else:
      return list(iterable)
    return super(SpiffObjectEncoder, self).default(obj)

class API(object):
  def __init__(self, uri, verify=True, backend=None):
    if backend is None:
        backend = backends.defaultBackend()
    super(API, self).__init__()
    self.__uri = urlparse.urlparse(uri)
    self.__token = None
    self.__verify = verify
    self.__backend = backend
    self._schema = []
    self._typeSchema = {}

  @classmethod
  def getDefaultAPI(cls, fallback=None, verify=False):
    if 'SPIFF_URL' in os.environ:
        return cls(os.environ['SPIFF_URL'], verify)
    if spaceapi:
        browser = spaceapi.Browser()
        default = browser.defaultAPI(fallback, verify)
        try:
            return cls(default.raw['x-spiff-url'])
        except Exception:
            pass
    return cls(fallback)

  def __repr__(self):
    return "API(%r)"%(self.__uri.geturl())

  def __str__(self):
    return repr(self)

  def subUri(self, uri):
    if not uri.endswith('/'):
      uri += '/'
    if uri.startswith(self.__uri.path):
      return urlparse.urlunparse((self.__uri.scheme, self.__uri.netloc, uri, None,
        None, None))
    else:
      return urlparse.urljoin(self.__uri.geturl(), uri)
    raise ValueError

  def getRequestHeaders(self):
    headers = {
      'accept': 'application/json',
      'content-type': 'application/json'
    }

    if self.__token:
      headers['authorization'] = 'Bearer '+self.__token
    return headers<commit_msg>Handle passing the ssl verify paramter<commit_after>from . import errors
from . import backends
import json
import logging
import datetime
import urlparse
import os

try:
  import spaceapi
except ImportError:
  spaceapi = None

log = logging.getLogger('spiff')

class SpiffObjectEncoder(json.JSONEncoder):
  def __init__(self, api, *args, **kwargs):
    super(SpiffObjectEncoder, self).__init__(*args, **kwargs)
    self.__api = api

  def default(self, obj):
    if isinstance(obj, SpiffObject):
      return obj.resource_uri
    if isinstance(obj, datetime.date):
      return str(obj)
    if isinstance(obj, ObjectList):
      l = []
      for o in obj:
        l.append(o.resource_uri)
      return self.default(l)
    try:
      iterable = iter(obj)
    except TypeError:
      pass
    else:
      return list(iterable)
    return super(SpiffObjectEncoder, self).default(obj)

class API(object):
  def __init__(self, uri, verify=True, backend=None):
    if backend is None:
        backend = backends.defaultBackend()
    super(API, self).__init__()
    self.__uri = urlparse.urlparse(uri)
    self.__token = None
    self.__verify = verify
    self.__backend = backend
    self._schema = []
    self._typeSchema = {}

  @classmethod
  def getDefaultAPI(cls, fallback=None, verify=False):
    if 'SPIFF_URL' in os.environ:
        return cls(os.environ['SPIFF_URL'], verify=verify)
    if spaceapi:
        browser = spaceapi.Browser()
        default = browser.defaultAPI(fallback, verify=verify)
        try:
            return cls(default.raw['x-spiff-url'], verify=verify)
        except Exception:
            pass
    return cls(fallback, verify=verify)

  def __repr__(self):
    return "API(%r)"%(self.__uri.geturl())

  def __str__(self):
    return repr(self)

  def subUri(self, uri):
    if not uri.endswith('/'):
      uri += '/'
    if uri.startswith(self.__uri.path):
      return urlparse.urlunparse((self.__uri.scheme, self.__uri.netloc, uri, None,
        None, None))
    else:
      return urlparse.urljoin(self.__uri.geturl(), uri)
    raise ValueError

  def getRequestHeaders(self):
    headers = {
      'accept': 'application/json',
      'content-type': 'application/json'
    }

    if self.__token:
      headers['authorization'] = 'Bearer '+self.__token
    return headers
{'fraction_non_alphanumeric': 0.11749174917491749, 'fraction_numerical': 0.0, 'mean_word_length': 2.9807355516637477, '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': '6936144', 'n_tokens_mistral': 1420, 'n_tokens_neox': 1409, 'n_words': 344}