<commit_before># vim:ai:et:ff=unix:fileencoding=utf-8:sw=4:ts=4:
# conveyor/src/main/python/conveyor/jsonrpc.py
#
# conveyor - Printing dispatch engine for 3D objects and their friends.
# Copyright © 2012 <NAME> <<EMAIL>>
#
# This program is free software: you can redistribute it and/or modify it under
# the terms of the GNU Affero General Public License as published by the Free
# Software Foundation, either version 3 of the License, or (at your option) any
# later version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
# details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

from __future__ import (absolute_import, print_function, unicode_literals)

import cStringIO as StringIO
import errno
import json
import logging
import io
import operator
import os
import sys
import threading

try:
    import unittest2 as unittest
except ImportError:
    import unittest

import conveyor.event
import conveyor.test
import conveyor.task

class socketadapter(object):
    '''A file-like wrapper for sockets.

    This differs from socket.makefile() in that the read() method doesn't
    buffer until the end of time and it only implements the methods required by
    the _JsonReader and JsonRpc class contracts.

    '''

    def flush(self):
        pass

    def write(self, data):
        self._fp.sendall(data)

    if 'nt' == os.name:
        def __init__(self, fp):
            self._fp = fp
            self._shutdown = False

        def read(self, size=-1):
            while True:
                if self._shutdown:
                    return ''
                else:
                    rlist, wlist, xlist = select.select([self._fp], [], [], 1)
                    if 0 != len(rlist):
                        data = self._fp.recv(size)
                        return data

        def shutdown(self):
            self._shutdown = True
            self._fp.close()
    else:
        def __init__(self, fp):
            self._fp = fp

        def read(self, size=-1):
            data = self._fp.recv(size)
            return data

        def shutdown(self):
            # NOTE: use SHUT_RD instead of SHUT_RDWR or you will get annoying
            # 'Connection reset by peer' errors.
            import socket
            self._fp.shutdown(socket.SHUT_RD)
            self._fp.close()<commit_msg>Import the select module.<commit_after># vim:ai:et:ff=unix:fileencoding=utf-8:sw=4:ts=4:
# conveyor/src/main/python/conveyor/jsonrpc.py
#
# conveyor - Printing dispatch engine for 3D objects and their friends.
# Copyright © 2012 <NAME> <<EMAIL>>
#
# This program is free software: you can redistribute it and/or modify it under
# the terms of the GNU Affero General Public License as published by the Free
# Software Foundation, either version 3 of the License, or (at your option) any
# later version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
# details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

from __future__ import (absolute_import, print_function, unicode_literals)

import cStringIO as StringIO
import errno
import json
import logging
import io
import operator
import os
import sys
import threading

try:
    import unittest2 as unittest
except ImportError:
    import unittest

import conveyor.event
import conveyor.test
import conveyor.task

class socketadapter(object):
    '''A file-like wrapper for sockets.

    This differs from socket.makefile() in that the read() method doesn't
    buffer until the end of time and it only implements the methods required by
    the _JsonReader and JsonRpc class contracts.

    '''

    def flush(self):
        pass

    def write(self, data):
        self._fp.sendall(data)

    if 'nt' == os.name:
        def __init__(self, fp):
            self._fp = fp
            self._shutdown = False

        def read(self, size=-1):
            while True:
                if self._shutdown:
                    return ''
                else:
                    import select
                    rlist, wlist, xlist = select.select([self._fp], [], [], 1)
                    if 0 != len(rlist):
                        data = self._fp.recv(size)
                        return data

        def shutdown(self):
            self._shutdown = True
            self._fp.close()
    else:
        def __init__(self, fp):
            self._fp = fp

        def read(self, size=-1):
            data = self._fp.recv(size)
            return data

        def shutdown(self):
            # NOTE: use SHUT_RD instead of SHUT_RDWR or you will get annoying
            # 'Connection reset by peer' errors.
            import socket
            self._fp.shutdown(socket.SHUT_RD)
            self._fp.close()
{'fraction_non_alphanumeric': 0.07866666666666666, 'fraction_numerical': 0.005333333333333333, 'mean_word_length': 2.3171193935565384, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '6522242', 'n_tokens_mistral': 1459, 'n_tokens_neox': 1383, 'n_words': 556}