<commit_before>""" 
IRC API - irc.py
"""

import sys
from .buffer import Buffer
from . import parse
import socket
from .num import NUM as numerics
import time

CONFIG = {}

class IRCHandler(object):
    """ IRCHandler(Dict<string, object> config) - a standard IRC handler """
    def __init__(self, bconfig, verbose=False):
        globals()["CONFIG"] = bconfig
        self.sock = socket.socket()
        self.verbose = verbose
        self.running = True
        self.buff = Buffer()
        self.outbuff = Buffer()
        self.is_welcome = False

    def connect(self):
        """ Connect to the IRC server and start the main loop """
        server = CONFIG["server"].split("|")[0].split(":")
        self.sock.connect((server[0], int(server[1])))
        passwd = CONFIG["server"].split("|", 1)[1]
        if passwd:
            self._send("PASS "+passwd)
        self.mainloop()

    def mainloop(self):
        """ The main loop. """
        loops = 0
        try:
            while self.running:

                time.sleep(0.1)
                if loops != 0:
                    try:
                        self.buff.append(self.sock.recv(1024).decode('utf-8'))
                    except UnicodeDecodeError:
                        try:
                            self.buff.append(self.sock.recv(1024).decode('utf-16'))
                        except:
                            pass
                else:
                    self.sendnick()
                    self.senduser()

                for msg in self.buff:
                    if self.verbose:
                        print('>>> '+msg)<commit_msg>try-catch<commit_after>""" 
IRC API - irc.py
"""

import sys
from .buffer import Buffer
from . import parse
import socket
from .num import NUM as numerics
import time

CONFIG = {}

class IRCHandler(object):
    """ IRCHandler(Dict<string, object> config) - a standard IRC handler """
    def __init__(self, bconfig, verbose=False):
        globals()["CONFIG"] = bconfig
        self.sock = socket.socket()
        self.verbose = verbose
        self.running = True
        self.buff = Buffer()
        self.outbuff = Buffer()
        self.is_welcome = False

    def connect(self):
        """ Connect to the IRC server and start the main loop """
        server = CONFIG["server"].split("|")[0].split(":")
        self.sock.connect((server[0], int(server[1])))
        try:
            passwd = CONFIG["server"].split("|", 1)[1]
            if passwd:
                self._send("PASS "+passwd)
        except:
            pass
        self.mainloop()

    def mainloop(self):
        """ The main loop. """
        loops = 0
        try:
            while self.running:

                time.sleep(0.1)
                if loops != 0:
                    try:
                        self.buff.append(self.sock.recv(1024).decode('utf-8'))
                    except UnicodeDecodeError:
                        try:
                            self.buff.append(self.sock.recv(1024).decode('utf-16'))
                        except:
                            pass
                else:
                    self.sendnick()
                    self.senduser()

                for msg in self.buff:
                    if self.verbose:
                        print('>>> '+msg)
{'fraction_non_alphanumeric': 0.12280169799878714, 'fraction_numerical': 0.01212856276531231, 'mean_word_length': 1.4097881665449232, 'pattern_counts': {'":': 2, '<': 5, '<?xml version=': 0, '>': 11, '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': '449958', 'n_tokens_mistral': 931, 'n_tokens_neox': 862, 'n_words': 218}