<commit_before># -*- coding: utf-8 -*-
from __future__ import unicode_literals
import os
import re
import six
import requests

from requests.packages.urllib3 import HTTPResponse

if six.PY3:
    from unittest import mock
    from io import BytesIO as BufferIO

    def prepare_for_write(value, charset='utf-8', errors='ignore'):
        if isinstance(value, bytes):
            return value.decode('utf-8')
        return value

else:
    import mock
    from six import StringIO as BufferIO

    def prepare_for_write(value, charset='utf-8', errors='ignore'):
        if isinstance(value, unicode):
            return value.encode(charset, errors)
        return unicode(value, errors=errors).encode(charset)


class Mock(object):
    path = 'fixtures'

    def __init__(self, path=None):
        if path:
            self.path = path

    def __enter__(self):
        def on_send(session, request, *args, **kwargs):
            return self.on_request(session, request, *args, **kwargs)

        self.patch = mock.patch('requests.Session.send', on_send)
        self.patch.start()

    def __exit__(self, exc_type, exc_val, exc_tb):
        self.patch.stop()

    def activate(self, path=None):
        if path is not None:
            if isinstance(path, six.string_types):
                self.path = path

        def activate(func):
            if isinstance(func, type):
                return self._decorate_class(func)

            def wrapper(*args, **kwargs):
                with self:
                    return func(*args, **kwargs)

            return wrapper

        return activate

    def _decorate_class(self, cls):
        for attr in cls.__dict__:
            if callable(getattr(cls, attr)):
                print(getattr(cls, attr))
                setattr(cls, attr, self.activate()(getattr(cls, attr)))
                print(getattr(cls, attr))
        return cls

    def on_request(self, session, request, *args, **kwargs):
        response_path = os.path.join(os.getcwd(), self.path, self._get_filename(request.url))

        if os.path.exists(response_path):
            content_type, content = self._read_body_from_file(response_path)
            response = HTTPResponse(
                status=200,
                body=BufferIO(content),
                preload_content=False,
                headers={'Content-Type': content_type}
            )
            adapter = session.get_adapter(request.url)
            response = adapter.build_response(request, response)
        else:<commit_msg>Remove debug print statements<commit_after># -*- coding: utf-8 -*-
from __future__ import unicode_literals
import os
import re
import six
import requests

from requests.packages.urllib3 import HTTPResponse

if six.PY3:
    from unittest import mock
    from io import BytesIO as BufferIO

    def prepare_for_write(value, charset='utf-8', errors='ignore'):
        if isinstance(value, bytes):
            return value.decode('utf-8')
        return value

else:
    import mock
    from six import StringIO as BufferIO

    def prepare_for_write(value, charset='utf-8', errors='ignore'):
        if isinstance(value, unicode):
            return value.encode(charset, errors)
        return unicode(value, errors=errors).encode(charset)


class Mock(object):
    path = 'fixtures'

    def __init__(self, path=None):
        if path:
            self.path = path

    def __enter__(self):
        def on_send(session, request, *args, **kwargs):
            return self.on_request(session, request, *args, **kwargs)

        self.patch = mock.patch('requests.Session.send', on_send)
        self.patch.start()

    def __exit__(self, exc_type, exc_val, exc_tb):
        self.patch.stop()

    def activate(self, path=None):
        if path is not None:
            if isinstance(path, six.string_types):
                self.path = path

        def activate(func):
            if isinstance(func, type):
                return self._decorate_class(func)

            def wrapper(*args, **kwargs):
                with self:
                    return func(*args, **kwargs)

            return wrapper

        return activate

    def _decorate_class(self, cls):
        for attr in cls.__dict__:
            if callable(getattr(cls, attr)):
                setattr(cls, attr, self.activate()(getattr(cls, attr)))
        return cls

    def on_request(self, session, request, *args, **kwargs):
        response_path = os.path.join(os.getcwd(), self.path, self._get_filename(request.url))

        if os.path.exists(response_path):
            content_type, content = self._read_body_from_file(response_path)
            response = HTTPResponse(
                status=200,
                body=BufferIO(content),
                preload_content=False,
                headers={'Content-Type': content_type}
            )
            adapter = session.get_adapter(request.url)
            response = adapter.build_response(request, response)
        else:
{'fraction_non_alphanumeric': 0.10240963855421686, 'fraction_numerical': 0.0036144578313253013, 'mean_word_length': 2.2386215864759427, '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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1279875', 'n_tokens_mistral': 1416, 'n_tokens_neox': 1355, 'n_words': 352}