<commit_before>cdef class io(object):
    cdef nmsg_io_t _instance

    cdef int filter_vid
    cdef int filter_msgtype
    cdef list inputs
    cdef list outputs

    def __cinit__(self):
        self._instance = NULL

    def __dealloc__(self):
        if self._instance != NULL:
            nmsg_io_destroy(&self._instance)

    def __init__(self):
        self.filter_vid = 0
        self.filter_msgtype = 0
        self.inputs = []
        self.outputs = []

        self._instance = nmsg_io_init()
        if self._instance == NULL:
            raise Exception, 'nmsg_io_init() failed'
        #nmsg_io_set_debug(self._instance, 4)

    def add_input(self, input i):
        cdef nmsg_res res

        res = nmsg_io_add_input(self._instance, i._instance, NULL)
        if res != nmsg_res_success:
            raise Exception, 'nmsg_io_add_input() failed'
        self.inputs.append(i)
        i._instance = NULL

    def add_input_channel(self, str ch_input):
        fname = None
        for f in chalias_fnames:
            if os.path.isfile(f):
                fname = f
        if fname == None:
            raise Exception, 'unable to locate nmsg channel alias file'

        for line in open(fname):
            ch, socks = line.strip().split(None, 1)
            if ch == ch_input:
                for sock in socks.split():
                    addr, ports = sock.split('/', 1)
                    portrange = [ int(p) for p in ports.split('..', 1) ]
                    for port in range(portrange[0], portrange[1] + 1):
                        i = input.open_sock(addr, port)
                        self.add_input(i)

    def add_output(self, output o):
        cdef nmsg_res

        res = nmsg_io_add_output(self._instance, o._instance, NULL)
        if res != nmsg_res_success:
            raise Exception, 'nmsg_io_add_output() failed'<commit_msg>pynmsg: support single-port portspecs in chalias file<commit_after>cdef class io(object):
    cdef nmsg_io_t _instance

    cdef int filter_vid
    cdef int filter_msgtype
    cdef list inputs
    cdef list outputs

    def __cinit__(self):
        self._instance = NULL

    def __dealloc__(self):
        if self._instance != NULL:
            nmsg_io_destroy(&self._instance)

    def __init__(self):
        self.filter_vid = 0
        self.filter_msgtype = 0
        self.inputs = []
        self.outputs = []

        self._instance = nmsg_io_init()
        if self._instance == NULL:
            raise Exception, 'nmsg_io_init() failed'
        #nmsg_io_set_debug(self._instance, 4)

    def add_input(self, input i):
        cdef nmsg_res res

        res = nmsg_io_add_input(self._instance, i._instance, NULL)
        if res != nmsg_res_success:
            raise Exception, 'nmsg_io_add_input() failed'
        self.inputs.append(i)
        i._instance = NULL

    def add_input_channel(self, str ch_input):
        fname = None
        for f in chalias_fnames:
            if os.path.isfile(f):
                fname = f
        if fname == None:
            raise Exception, 'unable to locate nmsg channel alias file'

        for line in open(fname):
            ch, socks = line.strip().split(None, 1)
            if ch == ch_input:
                for sock in socks.split():
                    addr, portspec = sock.split('/', 1)
                    if '..' in portspec:
                        portrange = [ int(p) for p in portspec.split('..', 1) ]
                        for port in range(portrange[0], portrange[1] + 1):
                            i = input.open_sock(addr, port)
                            self.add_input(i)
                    else:
                        i = input.open_sock(addr, portspec)
                        self.add_input(i)

    def add_output(self, output o):
        cdef nmsg_res

        res = nmsg_io_add_output(self._instance, o._instance, NULL)
        if res != nmsg_res_success:
            raise Exception, 'nmsg_io_add_output() failed'
{'fraction_non_alphanumeric': 0.09230769230769231, 'fraction_numerical': 0.004539722572509458, 'mean_word_length': 1.7427385892116183, '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': '67382', 'n_tokens_mistral': 1228, 'n_tokens_neox': 1175, 'n_words': 307}