<commit_before>import socket
from logging.handlers import SysLogHandler

from six import text_type

__all__ = ['configparser', 'UTFFixedSysLogHandler']

try:
    import ConfigParser as configparser
except ImportError:
    import configparser


class UTFFixedSysLogHandler(SysLogHandler):

    """
    Python 2.6 backport of Python 2.7 SysLogHandler.
    This handler should be compatible with Python > 2.6 as well.
    Fixes BOM issue, bug Reference: http://bugs.python.org/issue7077
    """

    def emit(self, record):
        """
        Emit a record.

        The record is formatted, and then sent to the syslog server.  If
        exception information is present, it is NOT sent to the server.
        """
        msg = self.format(record) + '\000'
        """
        We need to convert record level to lowercase, maybe this will
        change in the future.
        """
        prio = '<%d>' % self.encodePriority(self.facility,
                                            self.mapPriority(record.levelname))
        prio = prio.encode('utf-8')

        # Message may be a string. Convert to bytes as required by RFC 5424.
        if isinstance(msg, text_type):
            msg = msg.encode('utf-8')

        msg = prio + msg
        try:
            if self.unixsocket:
                try:
                    self.socket.send(msg)
                except socket.error:
                    self._connect_unixsocket(self.address)
                    self.socket.send(msg)
            elif getattr(self, 'socktype', socket.SOCK_DGRAM):
                self.socket.sendto(msg, self.address)
            else:
                self.socket.sendall(msg)
        except (KeyboardInterrupt, SystemExit):
            raise
        except:
            self.handleError(record)<commit_msg>Force every syslog message to fit in single line by default<commit_after>import socket
from logging.handlers import SysLogHandler

from six import text_type

__all__ = ['configparser', 'UTFFixedSysLogHandler']

try:
    import ConfigParser as configparser
except ImportError:
    import configparser


class UTFFixedSysLogHandler(SysLogHandler):

    """
    Python 2.6 backport of Python 2.7 SysLogHandler.
    This handler should be compatible with Python > 2.6 as well.
    Fixes BOM issue, bug Reference: http://bugs.python.org/issue7077
    """

    def __init__(self, join_lines=True, **kwargs):
        self.join_lines = join_lines
        SysLogHandler.__init__(self, **kwargs)

    def emit(self, record):
        """
        Emit a record.

        The record is formatted, and then sent to the syslog server.  If
        exception information is present, it is NOT sent to the server.
        """
        original_message = record.msg
        try:
            if self.join_lines:
                record.msg = original_message.replace('\n', r'\n')
            msg = self.format(record) + '\000'
            """
            We need to convert record level to lowercase, maybe this will
            change in the future.
            """
            prio = '<%d>' % self.encodePriority(self.facility,
                                                self.mapPriority(record.levelname))
            prio = prio.encode('utf-8')

            # Message may be a string. Convert to bytes as required by RFC 5424.
            if isinstance(msg, text_type):
                msg = msg.encode('utf-8')

            msg = prio + msg
            try:
                if self.unixsocket:
                    try:
                        self.socket.send(msg)
                    except socket.error:
                        self._connect_unixsocket(self.address)
                        self.socket.send(msg)
                elif getattr(self, 'socktype', socket.SOCK_DGRAM):
                    self.socket.sendto(msg, self.address)
                else:
                    self.socket.sendall(msg)
            except (KeyboardInterrupt, SystemExit):
                raise
            except:
                self.handleError(record)
        finally:
            record.msg = original_message
{'fraction_non_alphanumeric': 0.08339465293107677, 'fraction_numerical': 0.009320578857002697, 'mean_word_length': 1.7295850066934404, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3711832', 'n_tokens_mistral': 1115, 'n_tokens_neox': 1046, 'n_words': 316}