<commit_before>#!/usr/bin/env python
# -*- coding: utf-8 -*-

__author__ = '<NAME>'

import logging
import random
import threading
import time
import base64
import requests
from pyes.exceptions import NoServerAvailable
from httplib import HTTPConnection
from fakettypes import *
import socket
import urllib
__all__ = ['connect', 'connect_thread_local']

"""
Work taken from pycassa
"""

DEFAULT_SERVER = ("http", "127.0.0.1", 9200)
#API_VERSION = VERSION.split('.')

log = logging.getLogger('pyes')


class ClientTransport(object):
    """Encapsulation of a client session."""

    def __init__(self, server, framed_transport, timeout, recycle, basic_auth):
        self.connection_type, self.host, self.port = server
        self.timeout = timeout
        self.headers = {}
        #self.client = TimeoutHttpConnectionPool(host, port, timeout)
        #setattr(self.client, "execute", self.execute)
        if recycle:
            self.recycle = time.time() + recycle + random.uniform(0, recycle * 0.1)
        else:
            self.recycle = None

        if basic_auth:
            username = basic_auth.get('username')
            password = basic_auth.get('password')
            base64string = base64.encodestring('%s:%s' %
                                               (username, password))[:-1]
            self.headers["Authorization"] = ("Basic %s" % base64string)

    def execute(self, request):
        """
        Execute a request and return a response
        """
        headers = self.headers.copy()
        headers.update(request.headers)
        response = requests.request(method=Method._VALUES_TO_NAMES[request.method],<commit_msg>Restored use session in requests<commit_after>#!/usr/bin/env python
# -*- coding: utf-8 -*-

__author__ = '<NAME>'

import logging
import random
import threading
import time
import base64
import requests
from pyes.exceptions import NoServerAvailable
from httplib import HTTPConnection
from fakettypes import *
import socket
import urllib
__all__ = ['connect', 'connect_thread_local']

"""
Work taken from pycassa
"""

DEFAULT_SERVER = ("http", "127.0.0.1", 9200)
#API_VERSION = VERSION.split('.')

log = logging.getLogger('pyes')


class ClientTransport(object):
    """Encapsulation of a client session."""

    def __init__(self, server, framed_transport, timeout, recycle, basic_auth=None):
        self.connection_type, self.host, self.port = server
        self.timeout = timeout
        self.headers = {}
        #self.client = TimeoutHttpConnectionPool(host, port, timeout)
        #setattr(self.client, "execute", self.execute)
        if recycle:
            self.recycle = time.time() + recycle + random.uniform(0, recycle * 0.1)
        else:
            self.recycle = None

        if basic_auth:
            username = basic_auth.get('username')
            password = <PASSWORD>_auth.<PASSWORD>('password')
            base64string = base64.encodestring('%s:%s' %
                                               (username, password))[:-1]
            self.headers["Authorization"] = ("Basic %s" % base64string)

    def execute(self, request):
        """
        Execute a request and return a response
        """
        headers = self.headers.copy()
        headers.update(request.headers)
        s = requests.session()
        response = s.request(method=Method._VALUES_TO_NAMES[request.method],
{'fraction_non_alphanumeric': 0.11958456973293768, 'fraction_numerical': 0.013649851632047478, 'mean_word_length': 2.758082497212932, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, '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': '5154024', 'n_tokens_mistral': 987, 'n_tokens_neox': 956, 'n_words': 237}