<commit_before>import json
import requests
from requests.exceptions import Timeout
from .util import meta_fix

class SalsaObject(object):

    def __init__(self, initial=None):
        _data = {}
        if initial:
            _data.update(initial)
        self.__dict__['_data'] = _data

    def __getattr__(self, attr):
        if attr in self._data:
            return self._data[attr]

    def __setattr__(self, attr, value):
        if attr in self._data:
            self._data[attr] = value
        else:
            self.__dict__[attr] = value

    def whoami(self):
        return self.__class__.__name__

    @classmethod
    def from_list(clazz, objects):
        instances = []
        for obj in objects:
            instances.append(clazz(obj))
        return instances

    @property
    def key(self):
        key_field = "%s_KEY" % self.object
        return self._data.get(key_field)

    def link(self, to_object, with_key):
        pass

    def tag(self, tag):
        pass

    def save(self):
        salsa.save(self.object, self._data, key=self.key)

    def delete(self):
        pass

class Donation(SalsaObject):
    object = 'donation'

class Event(SalsaObject):
    object = 'event'

class Group(SalsaObject):
    object = 'groups'

    def __repr__(self):
        return u"<Group: %s %s>" % (self.key, self.Group_Name)

class Supporter(SalsaObject):
    object = 'supporter'

    def __repr__(self):
        return u"<Supporter: %s %s %s %s>" % (self.key, self.First_Name, self.Last_Name, self.Email)

class SupporterAction(SalsaObject):
    object = 'supporter_action'

class SupporterAddress(SalsaObject):
    object = 'supporter_address'

class SupporterEvent(SalsaObject):
    object = 'supporter_event'

class SupporterGroup(SalsaObject):
    object = 'supporter_groups'

class SignupPage(SalsaObject):
    object = 'signup_page'

class EmailBlast(SalsaObject):
    object = 'email_blast'

# other objects: distributed_event, supporter_action_comment,
# supporter_action_target, supporter_action_content, chapter


def check_authentication(f):
    def wrapper(client, *args, **kwargs):

        if not client.authenticated:
            if client.auth_email and client.auth_password:
                client.authenticate(client.hq, client.auth_email, client.auth_password)

        data = f(client, *args, **kwargs)

        if data and isinstance(data[0], dict):
            if data[0].get('result') == 'error':
                client.authenticated = False
                client.authenticate(client.hq, client.auth_email, client.auth_password)
                data = f(client, *args, **kwargs)

        return data

    return wrapper


class AuthenticationError(Exception):
    pass


class Client(object):

    def __init__(self):
        self.hq = None
        self.auth_email = None<commit_msg>handle single object results<commit_after>import json
import requests
from requests.exceptions import Timeout
from .util import meta_fix

class SalsaObject(object):

    def __init__(self, initial=None):
        _data = {}
        if initial:
            _data.update(initial)
        self.__dict__['_data'] = _data

    def __getattr__(self, attr):
        if attr in self._data:
            return self._data[attr]

    def __setattr__(self, attr, value):
        if attr in self._data:
            self._data[attr] = value
        else:
            self.__dict__[attr] = value

    def whoami(self):
        return self.__class__.__name__

    @classmethod
    def from_list(clazz, objects):
        instances = []
        for obj in objects:
            instances.append(clazz(obj))
        return instances

    @property
    def key(self):
        key_field = "%s_KEY" % self.object
        return self._data.get(key_field)

    def link(self, to_object, with_key):
        pass

    def tag(self, tag):
        pass

    def save(self):
        salsa.save(self.object, self._data, key=self.key)

    def delete(self):
        pass

class Donation(SalsaObject):
    object = 'donation'

class Event(SalsaObject):
    object = 'event'

class Group(SalsaObject):
    object = 'groups'

    def __repr__(self):
        return u"<Group: %s %s>" % (self.key, self.Group_Name)

class Supporter(SalsaObject):
    object = 'supporter'

    def __repr__(self):
        return u"<Supporter: %s %s %s %s>" % (self.key, self.First_Name, self.Last_Name, self.Email)

class SupporterAction(SalsaObject):
    object = 'supporter_action'

class SupporterAddress(SalsaObject):
    object = 'supporter_address'

class SupporterEvent(SalsaObject):
    object = 'supporter_event'

class SupporterGroup(SalsaObject):
    object = 'supporter_groups'

class SignupPage(SalsaObject):
    object = 'signup_page'

class EmailBlast(SalsaObject):
    object = 'email_blast'

# other objects: distributed_event, supporter_action_comment,
# supporter_action_target, supporter_action_content, chapter


def check_authentication(f):
    def wrapper(client, *args, **kwargs):

        if not client.authenticated:
            if client.auth_email and client.auth_password:
                client.authenticate(client.hq, client.auth_email, client.auth_password)

        data = f(client, *args, **kwargs)

        if data and not isinstance(data, dict) and isinstance(data[0], dict):
            if data[0].get('result') == 'error':
                client.authenticated = False
                client.authenticate(client.hq, client.auth_email, client.auth_password)
                data = f(client, *args, **kwargs)

        return data

    return wrapper


class AuthenticationError(Exception):
    pass


class Client(object):

    def __init__(self):
        self.hq = None
        self.auth_email = None
{'fraction_non_alphanumeric': 0.10343017150857543, 'fraction_numerical': 0.0007000350017500875, 'mean_word_length': 2.735294117647059, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '6671451', 'n_tokens_mistral': 1796, 'n_tokens_neox': 1709, 'n_words': 416}