<commit_before>#!/usr/bin/env python

# This starts up a bunch of servers, one for each of the server type
# and socket typecombinations we have. It then runs through the tests
# for each server, which entails connecting to calling a method on the
# server, asserting something about that method, and then closing the
# connection

from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals

import os.path
import sys
from subprocess import Popen
import time
import unittest
import string
import socket
import errno
import ssl as SSL

from ThriftTest import ThriftTest, SecondService
from ThriftTest.ttypes import *

from thrift.transport import TTransport
from thrift.transport.THeaderTransport import (
    THeaderTransport, TRANSFORM, CLIENT_TYPE,
)
from thrift.transport import TSocket, TSSLSocket
from thrift.protocol import (
    TBinaryProtocol, THeaderProtocol, TMultiplexedProtocol, TCompactProtocol
)

_servers = []
_ports = {}

try:
    from thrift.protocol import fastproto
except ImportError:
    fastproto = None

def start_server(server_type, ssl, server_header, server_context,
        multiple, port):
    server_path = os.path.dirname(sys.argv[0])
    if sys.version_info[0] >= 3:
        server_bin = os.path.join(server_path, 'py3_test_server.par')
    else:
        server_bin = os.path.join(server_path, 'python_test_server.par')

    args = [server_bin, '--port', str(port)]
    if ssl:
        args.append('--ssl')
    if server_header:
        args.append('--header')
    if server_context:
        args.append('--context')
    if multiple:
        args.append('--multiple')
    args.append(server_type)
    stdout = None
    stderr = None
    if sys.stdout.isatty():
        stdout = sys.stdout
        stderr = sys.stderr
    return Popen(args, stdout=stdout, stderr=stderr)

def isConnectionRefused(e):
    if sys.version_info[0] >= 3:
        return isinstance(e, ConnectionRefusedError)
    else:
        return e[0] == errno.ECONNREFUSED

def wait_for_server(port, timeout, ssl=False):
    end = time.time() + timeout
    while time.time() < end:
        try:
            sock = socket.socket()
            if ssl:
                sock = SSL.wrap_socket(sock)
            sock.connect(('localhost', port))
            sock.close()
            return True
        except socket.timeout:
            return False
        except socket.error as e:
            if not isConnectionRefused(e):
                raise
            time.sleep(0.1)
            continue
    return False

class AbstractTest(object):
<commit_msg>Tweak test connections in thrift/test/py/TestClientServer.py<commit_after>#!/usr/bin/env python

# This starts up a bunch of servers, one for each of the server type
# and socket typecombinations we have. It then runs through the tests
# for each server, which entails connecting to calling a method on the
# server, asserting something about that method, and then closing the
# connection

from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals

import os.path
import sys
from subprocess import Popen
import time
import unittest
import string
import socket
import errno
import ssl as SSL

from ThriftTest import ThriftTest, SecondService
from ThriftTest.ttypes import *

from thrift.transport import TTransport
from thrift.transport.THeaderTransport import (
    THeaderTransport, TRANSFORM, CLIENT_TYPE,
)
from thrift.transport import TSocket, TSSLSocket
from thrift.protocol import (
    TBinaryProtocol, THeaderProtocol, TMultiplexedProtocol, TCompactProtocol
)

_servers = []
_ports = {}

try:
    from thrift.protocol import fastproto
except ImportError:
    fastproto = None

def start_server(server_type, ssl, server_header, server_context,
        multiple, port):
    server_path = os.path.dirname(sys.argv[0])
    if sys.version_info[0] >= 3:
        server_bin = os.path.join(server_path, 'py3_test_server.par')
    else:
        server_bin = os.path.join(server_path, 'python_test_server.par')

    args = [server_bin, '--port', str(port)]
    if ssl:
        args.append('--ssl')
    if server_header:
        args.append('--header')
    if server_context:
        args.append('--context')
    if multiple:
        args.append('--multiple')
    args.append(server_type)
    stdout = None
    stderr = None
    if sys.stdout.isatty():
        stdout = sys.stdout
        stderr = sys.stderr
    return Popen(args, stdout=stdout, stderr=stderr)

def isConnectionRefused(e):
    if sys.version_info[0] >= 3:
        return isinstance(e, ConnectionRefusedError)
    else:
        return e[0] == errno.ECONNREFUSED

def wait_for_server(port, timeout, ssl=False):
    end = time.time() + timeout
    while time.time() < end:
        try:
            sock = socket.socket()
            sock.settimeout(end - time.time())
            if ssl:
                sock = SSL.wrap_socket(sock)
            sock.connect(('localhost', port))
            return True
        except socket.timeout:
            return False
        except socket.error as e:
            if not isConnectionRefused(e):
                raise
        finally:
            sock.close()
        time.sleep(0.1)
    return False

class AbstractTest(object):

{'fraction_non_alphanumeric': 0.08466989929130922, 'fraction_numerical': 0.0033569563595673255, 'mean_word_length': 2.9637841832963785, 'pattern_counts': {'":': 0, '<': 5, '<?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': '4720345', 'n_tokens_mistral': 1587, 'n_tokens_neox': 1549, 'n_words': 468}