<commit_before>import cStringIO
from xmlrpclib import Transport
from xmlrpclib import ServerProxy, Fault
from xmlrpclib import getparser, ProtocolError
import httplib


class XmlrpcTestClientTransport(object):

    def __init__(self, client):
        self.client = client

    def getparser(self):
        return getparser()

    def request(self, host, handler, request_body, verbose = False):
        parser, unmarshaller = self.getparser()
        response = self.client.post(handler, request_body, 'text/xml')
        if response.status_code != 200:
            raise ProtocolError(
              '%s%s' % (host, handler),
              response.status_code,
              httplib.responses.get(response.status_code, ''),
              dict(response.items()),
            )
        parser.feed(response.content)
        return unmarshaller.close()

def get_serverproxy(client, path):
    return ServerProxy('http://localhost' + path,
            transport=XmlrpcTestClientTransport(client))

class XmlRpcAssertsMixin(object):
    def assertLoginRequired(self, method, *args, **kwargs):
        self.assertRaises(Fault, method, *args, **kwargs)

    def login(self, client, username):
        get_serverproxy(client, '/xmlrpc/').login(username, 'test')<commit_msg>Made xmlrpc testhelpers support and default to use_datetime.<commit_after>import cStringIO
from xmlrpclib import Transport
from xmlrpclib import ServerProxy, Fault
from xmlrpclib import getparser, ProtocolError
import httplib


class XmlrpcTestClientTransport(object):

    def __init__(self, client, use_datetime=True):
        self.client = client
        self.use_datetime = use_datetime

    def getparser(self):
        return getparser(use_datetime=self.use_datetime)

    def request(self, host, handler, request_body, verbose=False):
        parser, unmarshaller = self.getparser()
        response = self.client.post(handler, request_body, 'text/xml')
        if response.status_code != 200:
            raise ProtocolError(
              '%s%s' % (host, handler),
              response.status_code,
              httplib.responses.get(response.status_code, ''),
              dict(response.items()),
            )
        parser.feed(response.content)
        return unmarshaller.close()


def get_serverproxy(client, path):
    return ServerProxy('http://localhost' + path,
            transport=XmlrpcTestClientTransport(client))

class XmlRpcAssertsMixin(object):
    def assertLoginRequired(self, method, *args, **kwargs):
        self.assertRaises(Fault, method, *args, **kwargs)

    def login(self, client, username):
        get_serverproxy(client, '/xmlrpc/').login(username, 'test')

    def logout(self, client):
        get_serverproxy(client, '/xmlrpc/').logout()
{'fraction_non_alphanumeric': 0.10639070442992012, 'fraction_numerical': 0.002178649237472767, 'mean_word_length': 3.2061068702290076, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 12}, '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': '6174745', 'n_tokens_mistral': 789, 'n_tokens_neox': 766, 'n_words': 177}