<commit_before>import zmq
import ZeroMQ
import System

class Socket(ZeroMQ.ZSocket):
    _closed = None
    def __new__(cls, context=None, socket_type=None, shadow=None):
        if not context or not socket_type:
            raise ValueError()
        rv = ZeroMQ.ZSocket.__new__(cls, context, socket_type)
        if shadow:
            raise NotImplementedError()
        return rv

    @property
    def closed(self):
        return self._closed

    def close(self):
        self.Close()
        self._closed = True

    def set(self, opt, val):
        if isinstance(val, bytes):
            val = val.ToByteArray()
        self.SetOption(opt, val)

    def get(self, opt):
        return self.GetOption(opt)

    @property
    def linger(self):
        return self.Linger.TotalMilliseconds

    @linger.setter
    def linger(self, value):
        self.Linger = System.TimeSpan.FromMilliseconds(value)

    # clrzmq4 exposes the underlying C byte array as a C# string or Byte[], string is easier to deal with.
    @property
    def identity(self):
        return bytes(self.IdentityString)
    @identity.setter
    def identity(self, value):
        self.IdentityString = str(value)

    def connect(self, address):
        self.Connect(address)

    def send(self, message, flags=0, copy=False, track=False):
        #if isinstance(message, unicode):
        #    raise TypeError("Message must be in bytes, not an unicode Object")

        if not isinstance(message, zmq.Frame):
            message = zmq.Frame(message)

        self.Send(message, System.Enum.Parse(ZeroMQ.ZSocketFlags, str(flags)))

        #zmq_msg = ffi.new('zmq_msg_t*')
        #c_message = ffi.new('char[]', message)
        #rc = C.zmq_msg_init_size(zmq_msg, len(message))
        #_check_rc(rc)
        #C.memcpy(C.zmq_msg_data(zmq_msg), c_message, len(message))
        #_retry_sys_call(C.zmq_msg_send, zmq_msg, self._zmq_socket, flags)
        #rc2 = C.zmq_msg_close(zmq_msg)
        #_check_rc(rc2)

        if track:
            raise NotImplementedError()
            # return zmq.MessageTracker()

    #def recv(self, flags=0, copy=True, track=False):
    #    zmq_msg = ffi.new('zmq_msg_t*')
    #    C.zmq_msg_init(zmq_msg)
        
    #    try:
    #        _retry_sys_call(C.zmq_msg_recv, zmq_msg, self._zmq_socket, flags)
    #    except Exception:
    #        C.zmq_msg_close(zmq_msg)
    #        raise

    #    _buffer = ffi.buffer(C.zmq_msg_data(zmq_msg), C.zmq_msg_size(zmq_msg))
    #    value = _buffer[:]
    #    rc = C.zmq_msg_close(zmq_msg)
    #    _check_rc(rc)

    #    frame = Frame(value, track=track)
    #    frame.more = self.getsockopt(RCVMORE)

    #    if copy:
    #        return frame.bytes
    #    else:
    #        return frame<commit_msg>smoke test working again<commit_after>import zmq
import ZeroMQ
import System

class Socket(ZeroMQ.ZSocket):
    _closed = None
    def __new__(cls, context=None, socket_type=None, shadow=None):
        if not context or not socket_type:
            raise ValueError()
        rv = ZeroMQ.ZSocket.__new__(cls, context, socket_type)
        if shadow:
            raise NotImplementedError()
        return rv

    @property
    def closed(self):
        return self._closed

    def close(self):
        self.Close()
        self._closed = True

    def set(self, opt, val):
        if isinstance(val, bytes):
            val = val.ToByteArray()
        self.SetOption(opt, val)

    def get(self, opt):
        if opt == ZeroMQ.ZSocketOption.RCVMORE:
            return self.ReceiveMore
        return self.GetOption(opt)

    @property
    def linger(self):
        return self.Linger.TotalMilliseconds

    @linger.setter
    def linger(self, value):
        self.Linger = System.TimeSpan.FromMilliseconds(value)

    # clrzmq4 exposes the underlying C byte array as a C# string or Byte[], string is easier to deal with.
    @property
    def identity(self):
        return bytes(self.IdentityString)
    @identity.setter
    def identity(self, value):
        self.IdentityString = str(value)

    def connect(self, address):
        self.Connect(address)

    def send(self, message, flags=0, copy=False, track=False):
        #if isinstance(message, unicode):
        #    raise TypeError("Message must be in bytes, not an unicode Object")

        if not isinstance(message, zmq.Frame):
            message = zmq.Frame(message)

        self.Send(message, System.Enum.Parse(ZeroMQ.ZSocketFlags, str(flags)))

        if track:
            raise NotImplementedError()
            # return zmq.MessageTracker()

    def recv(self, flags=0, copy=True, track=False):
        if track:
            raise NotImplementedError("recv track option")

        frame, err = self.ReceiveFrame(System.Enum.Parse(ZeroMQ.ZSocketFlags, str(flags)))

        if copy:
            return bytes(frame.Read())
        else:
            return zmq.Frame(frame)
{'fraction_non_alphanumeric': 0.10051241623965314, 'fraction_numerical': 0.0015766653527788726, 'mean_word_length': 2.144361833952912, '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': '783085', 'n_tokens_mistral': 1644, 'n_tokens_neox': 1527, 'n_words': 361}