<commit_before>from __future__ import print_function
from pygelf.tcp import GelfTcpHandler
import ssl
import socket
import sys


class GelfTlsHandler(GelfTcpHandler):

    def __init__(self, cert, **kwargs):
        super(GelfTlsHandler, self).__init__(**kwargs)
        self.cert = cert

    def makeSocket(self, timeout=1):
        s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        if hasattr(s, 'settimeout'):
            s.settimeout(timeout)

        try:
            wrapped_socket = ssl.wrap_socket(s, ca_certs=self.cert, cert_reqs=ssl.CERT_REQUIRED)
            wrapped_socket.connect((self.host, self.port))
            return wrapped_socket
        except Exception as e:
            print('SSL socket exception:', e, file=sys.stderr)<commit_msg>cert argument is now optional for TLS handler<commit_after>from __future__ import print_function
from pygelf.tcp import GelfTcpHandler
import ssl
import socket
import sys


class GelfTlsHandler(GelfTcpHandler):

    def __init__(self, cert=None, **kwargs):
        super(GelfTlsHandler, self).__init__(**kwargs)
        self.cert = cert

    def makeSocket(self, timeout=1):
        s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        if hasattr(s, 'settimeout'):
            s.settimeout(timeout)

        try:
            if self.cert is None:
                wrapped_socket = ssl.wrap_socket(s)
            else:
                wrapped_socket = ssl.wrap_socket(s, ca_certs=self.cert, cert_reqs=ssl.CERT_REQUIRED)
            wrapped_socket.connect((self.host, self.port))
            return wrapped_socket
        except Exception as e:
            print('SSL socket exception:', e, file=sys.stderr)
{'fraction_non_alphanumeric': 0.09280190362879238, 'fraction_numerical': 0.001189767995240928, 'mean_word_length': 2.8227272727272728, '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': '451659', 'n_tokens_mistral': 517, 'n_tokens_neox': 509, 'n_words': 117}