<commit_before>from requests.exceptions import *
from requests.models import Response

import requests
import urlparse
import json

class _Request(object):
    """
    Issues requests to the collections API
    """
    def __init__(self,zkconnection):
        self.connection = zkconnection
        self.client = requests.Session()
        
    def request(self,path,params,method='GET',body=None):
        headers = {'content-type': 'application/json'}
        params['wt'] = 'json'

        servers = list(self.connection.servers)
        host = servers.pop(0)
        def make_request(host,path):
            fullpath = urlparse.urljoin(host,path)
            try:
                r = self.client.request(method,fullpath,
                                        params=params,
                                        headers=headers)
                
                return r.json
            except ConnectionError:
                host = servers.pop(0)
                return make_request(host,path)
       
        result = make_request(host,path)
        return result

    def update(self,path,params,body):
        return self.request(path,params,body,method='POST')

    def get(self,path,params):
        return self.request(path,params,method='GET')

class Collection(object):
    """
    Class to manage collections
    """
    def __init__(self,connection):
        self.connection = connection
        self.client = _Request(connection)
        
    def create(self,name,num_shards,params={}):
        params.update({'action':'CREATE','name':name,'numShards':num_shards})
        self.client.get('admin/collections',params)
                             
    def delete(self,name,params={}):
        params.update({'action':'DELETE','name':name})
        self.client.get('admin/collections',params)
        
    def reload(self,name,params={}):
        params.update({'action':'RELOAD','name':name})<commit_msg>add list command to collection<commit_after>from requests.exceptions import *
from requests.models import Response

import requests
import urlparse
import json

class _Request(object):
    """
    Issues requests to the collections API
    """
    def __init__(self,zkconnection):
        self.connection = zkconnection
        self.client = requests.Session()
        
    def request(self,path,params,method='GET',body=None):
        headers = {'content-type': 'application/json'}
        params['wt'] = 'json'

        servers = list(self.connection.servers)
        host = servers.pop(0)
        def make_request(host,path):
            fullpath = urlparse.urljoin(host,path)
            try:
                r = self.client.request(method,fullpath,
                                        params=params,
                                        headers=headers)
                
                return r.json
            except ConnectionError:
                host = servers.pop(0)
                return make_request(host,path)
       
        result = make_request(host,path)
        return result

    def update(self,path,params,body):
        return self.request(path,params,body,method='POST')

    def get(self,path,params):
        return self.request(path,params,method='GET')

class Collection(object):
    """
    Class to manage collections
    """
    def __init__(self,connection):
        self.connection = connection
        self.client = _Request(connection)

    def list(self):
        params.update({'action':'STATUS',})
        data = self.client.get('admin/cores',params)
        return data['status'].keys()
        
    def create(self,name,num_shards,params={}):
        params.update({'action':'CREATE','name':name,'numShards':num_shards})
        self.client.get('admin/collections',params)
                             
    def delete(self,name,params={}):
        params.update({'action':'DELETE','name':name})
        self.client.get('admin/collections',params)
        
    def reload(self,name,params={}):
        params.update({'action':'RELOAD','name':name})
{'fraction_non_alphanumeric': 0.12182993535554451, 'fraction_numerical': 0.000994530084535057, 'mean_word_length': 2.2158273381294964, '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': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3679667', 'n_tokens_mistral': 1074, 'n_tokens_neox': 1052, 'n_words': 190}