<commit_before>import requests

class Sia:

    address = 'http://localhost'
    port = 9980
    headers = {
        'User-Agent': 'Sia-Agent',
    }

    def __init__(self, address='http://localhost', port=9980):
        self.set_address(address)
        self.set_port(port)

    def set_address(self, address='http://localhost'):
        """Sets address of Sia object to send requests to.
        If no address is set, resets to localhost.
        """
        self.address = address

    def set_port(self, port=9980):
        """Sets port of Sia object to send requests to.
        If no port is set, resets to 9980.
        """
        self.port = port

    def http_get(self, path, data=None):
        """Helper HTTP GET request function.
        Sends HTTP GET request to given path.
        """
        url = self.address + ':' + str(self.port) + path
        if data is not None:
            resp = requests.get(url, headers=self.headers, files=data)
        else:
            resp = requests.get(url, headers=self.headers)
        if resp.status_code is not requests.codes.ok:
            raise SiaError(resp.status_code, resp.json().get('message'))
        return resp.json()

    def http_post(self, path, data):
        """Helper HTTP POST request function.
        Sends HTTP POST request to given path with given payload.
        """
        url = self.address + ':' + str(self.port) + path
        resp = requests.post(url, headers=self.headers, data=data)
        if resp.status_code != requests.codes.ok:
            raise SiaError(resp.status_code, resp.json().get('message'))

    def get_version(self):
        """Returns the version of siad running."""
        version = self.http_get('/daemon/version')
        return version.get('version')

    def get_consensus(self):
        """Returns information about the consensus set"""
        consensus = self.http_get('/consensus')
        return consensus

    def get_files(self):
        """Returns a list of all files."""
        files = self.http_get('/renter/files')
        return files.get('files')

    def download_file(self, path, siapath):
        """Downloads a file from sia.
        """
        payload = { 'destination': (None, path) }
        self.http_get('/renter/download/'+ siapath, payload)

    def upload_file(self, path, siapath):
        """Uploads a file to sia.
        """
        payload = { 'source': path }
        self.http_post('/renter/upload/' + siapath, payload)

class SiaError(Exception):

    def __init__(self, status_code, message):
        self.status_code = status_code
        self.message = message
<commit_msg>Added gateway, hostdb, and renter bindings<commit_after>import requests

class Sia:

    address = 'http://localhost'
    port = 9980
    headers = {
        'User-Agent': 'Sia-Agent',
    }

    def __init__(self, address='http://localhost', port=9980):
        self.set_address(address)
        self.set_port(port)

    def set_address(self, address='http://localhost'):
        """Sets address of Sia object to send requests to.
        If no address is set, resets to localhost.
        """
        self.address = address

    def set_port(self, port=9980):
        """Sets port of Sia object to send requests to.
        If no port is set, resets to 9980.
        """
        self.port = port

    def http_get(self, path, data=None):
        """Helper HTTP GET request function.
        Sends HTTP GET request to given path.
        """
        url = self.address + ':' + str(self.port) + path
        if data is not None:
            resp = requests.get(url, headers=self.headers, files=data)
        else:
            resp = requests.get(url, headers=self.headers)
        if resp.status_code is not requests.codes.ok:
            raise SiaError(resp.status_code, resp.json().get('message'))
        return resp.json()

    def http_post(self, path, data):
        """Helper HTTP POST request function.
        Sends HTTP POST request to given path with given payload.
        """
        url = self.address + ':' + str(self.port) + path
        resp = requests.post(url, headers=self.headers, data=data)
        if resp.status_code != requests.codes.ok:
            raise SiaError(resp.status_code, resp.json().get('message'))

    def get_version(self):
        """Returns the version of siad running."""
        version = self.http_get('/daemon/version')
        return version.get('version')

    def get_consensus(self):
        """Returns information about the consensus set."""
        return self.http_get('/consensus')

    def get_gateway(self):
        """Returns information aout the gateway."""
        return self.http_get('/gateway')

    def get_host(self):
        """Returns information about the host."""
        return self.http_get('/host')

    def get_files(self):
        """Returns a list of all files."""
        files = self.http_get('/renter/files')
        return files.get('files')

    def get_hostdb(self):
        """Returns list of all known hosts."""
        return self.http_get('/hostdb/all').get('hosts')

    def get_hostdb_active(self, numhosts=None):
        """Returns list of active hosts.
        Optional parameter numhosts for maximum number of hosts returned.
        """
        payload = None
        if numhosts is not None:
            payload = { 'numhosts' : (None, str(numhosts)) }
        return self.http_get('/hostdb/active', payload).get('hosts')

    def get_renter(self):
        """Returns information about the renter."""
        return self.http_get('/renter')

    def download_file(self, path, siapath):
        """Downloads a file from sia.
        """
        payload = { 'destination': (None, path) }
        self.http_get('/renter/download/'+ siapath, payload)

    def upload_file(self, path, siapath):
        """Uploads a file to sia.
        """
        payload = { 'source': path }
        self.http_post('/renter/upload/' + siapath, payload)

class SiaError(Exception):

    def __init__(self, status_code, message):
        self.status_code = status_code
        self.message = message

{'fraction_non_alphanumeric': 0.12422054479816212, 'fraction_numerical': 0.005251066622907778, 'mean_word_length': 2.3360700602079914, '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': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6547835', 'n_tokens_mistral': 1784, 'n_tokens_neox': 1719, 'n_words': 499}