<commit_before>def output_open_file(obj, size_t bufsz=NMSG_WBUFSZ_MAX):
    if type(obj) == str:
        obj = open(obj, 'w')
    o = output()
    o._open_file(obj.fileno(), bufsz)
    o.fileobj = obj
    return o

def output_open_sock(addr, port, size_t bufsz=NMSG_WBUFSZ_ETHER):
    obj = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    obj.connect((addr, port))
    obj.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
    o = output()
    o._open_sock(obj.fileno(), bufsz)
    o.fileobj = obj
    return o

def output_open_callback(func):
    o = output()
    o._open_callback(func)
    return o

cdef void callback(nmsg_message_t _msg, void *user) with gil:
    cdef _recv_message msg

    msg = _recv_message()
    msg.set_instance(_msg)

    (<object>user)(msg)

cdef class output(object):
    cdef nmsg_output_t _instance
    cdef public object fileobj
    cdef str output_type

    open_file = staticmethod(output_open_file)
    open_sock = staticmethod(output_open_sock)
    open_callback = staticmethod(output_open_callback)

    def __cinit__(self):
        self._instance = NULL
<commit_msg>pynmsg: add broadcast flag to output_open_sock()<commit_after>def output_open_file(obj, size_t bufsz=NMSG_WBUFSZ_MAX):
    if type(obj) == str:
        obj = open(obj, 'w')
    o = output()
    o._open_file(obj.fileno(), bufsz)
    o.fileobj = obj
    return o

def output_open_sock(addr, port, size_t bufsz=NMSG_WBUFSZ_ETHER, broadcast=False):
    obj = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    obj.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
    if broadcast:
        obj.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
    obj.connect((addr, port))
    o = output()
    o._open_sock(obj.fileno(), bufsz)
    o.fileobj = obj
    return o

def output_open_callback(func):
    o = output()
    o._open_callback(func)
    return o

cdef void callback(nmsg_message_t _msg, void *user) with gil:
    cdef _recv_message msg

    msg = _recv_message()
    msg.set_instance(_msg)

    (<object>user)(msg)

cdef class output(object):
    cdef nmsg_output_t _instance
    cdef public object fileobj
    cdef str output_type

    open_file = staticmethod(output_open_file)
    open_sock = staticmethod(output_open_sock)
    open_callback = staticmethod(output_open_callback)

    def __cinit__(self):
        self._instance = NULL

{'fraction_non_alphanumeric': 0.10025380710659898, 'fraction_numerical': 0.0012690355329949238, 'mean_word_length': 3.6463654223968565, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '1513330', 'n_tokens_mistral': 877, 'n_tokens_neox': 856, 'n_words': 179}