<commit_before># encoding: utf-8
import pika
from custom_exceptions import (NoConnectionToMQ, InvalidCredentialsError,
                               UnknownMQError, InsufficientPermissionsError,
                               RouteNotFoundError)


class MQConnection(object):
    def __init__(self, appkey, hostname, port=None, username=None,
                 password=None):

        self.credentials = None
        if username and password is not None:
            self.credentials = pika.PlainCredentials(username, password)

        self.parameters = pika.ConnectionParameters(
            host=hostname,
            port=port,
            credentials=self.credentials)

        self.connection = None

    def open(self):
        try:
            self.connection = pika.BlockingConnection(self.parameters)
        except pika.exceptions.ConnectionClosed as e:
            raise NoConnectionToMQ(exception=e)
        except pika.exceptions.ProbableAuthenticationError as e:
            raise InvalidCredentialsError(exception=e)
        except Exception as e:
            raise UnknownMQError(exception=e)<commit_msg>Transforma classe de mqconnection em singleton<commit_after># encoding: utf-8
import pika
from custom_exceptions import (NoConnectionToMQ, InvalidCredentialsError,
                               UnknownMQError, InsufficientPermissionsError,
                               RouteNotFoundError)
from singleton import Singleton


class MQConnection(object):

    __metaclass__ = Singleton

    def __init__(self, appkey, hostname, port=None, username=None,
                 password=<PASSWORD>):

        self.credentials = None
        if username and password is not None:
            self.credentials = pika.PlainCredentials(username, password)

        self.parameters = pika.ConnectionParameters(
            host=hostname,
            port=port,
            credentials=self.credentials)

        self.connection = None

    def open(self):
        try:
            self.connection = pika.BlockingConnection(self.parameters)
        except pika.exceptions.ConnectionClosed as e:
            raise NoConnectionToMQ(exception=e)
        except pika.exceptions.ProbableAuthenticationError as e:
            raise InvalidCredentialsError(exception=e)
        except Exception as e:
            raise UnknownMQError(exception=e)
{'fraction_non_alphanumeric': 0.06433745206646783, 'fraction_numerical': 0.0008521516829995739, 'mean_word_length': 2.397973950795948, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, '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': '3846054', 'n_tokens_mistral': 590, 'n_tokens_neox': 571, 'n_words': 138}