<commit_before>"""
The Connection class negotiates and manages the connection state.

"""
import locale
import logging
import sys
import socket
try:
    import ssl
except ImportError:
    ssl = None

from pamqp import frame
from pamqp import header
from pamqp import exceptions as pamqp_exceptions
from pamqp import specification
from pamqp import PYTHON3

from rmqid import base
from rmqid import channel
from rmqid import exceptions
from rmqid import message
from rmqid import utils
from rmqid import __version__

LOGGER = logging.getLogger(__name__)


class Connection(base.StatefulObject):
    """The Connection object is responsible for negotiating a connection and
    managing its state.

    """
    CANCEL_METHOD = ['Basic.Cancel']
    CHANNEL = 0
    CONNECTION_TIMEOUT = 1
    CONTENT_METHODS = ['Basic.Deliver', 'Basic.GetOk', 'Basic.Return']
    DEFAULT_HEARTBEAT_INTERVAL = 3
    DEFAULT_LOCALE = 'en_US'
    DEFAULT_URL = 'amqp://guest:guest@localhost:5672/%2F'
    DEFAULT_VHOST = '%2F'
    GUEST = 'guest'
    PORTS = {'amqp': 5672, 'amqps': 5671}

    def __init__(self, url=DEFAULT_URL):
        """Create a new instance of the Connection object

        :param str url: The AMQP connection URL

        """
        super(Connection, self).__init__()
        self._args = self._process_url(url)
        self._buffer = bytes() if PYTHON3 else str()
        self._channels = dict()
        self._messages = dict()
        self._stack = list()
        self._heartbeat = 0
        self._maximum_channels = 0
        self.maximum_frame_size = specification.FRAME_MAX_SIZE
        self.minimum_frame_size = specification.FRAME_MIN_SIZE
        self._properties = dict()
        self._socket = None
        self._connect()

    def __enter__(self):
        return self

    def __exit__(self, exc_type, exc_val, exc_tb):
        if exc_type:
            LOGGER.exception('Connection context manager closed on exception',
                             exc_tb)
            raise exc_type(exc_val)
        LOGGER.debug('Closing connection')
        self.close()

    def close(self):
        """Close the connection, including all open channels"""
        if not self.closed:
            LOGGER.debug('Closing the connection')
            self._set_state(self.CLOSING)
            self._close_channels()<commit_msg>Fix using the default URL for a non-specified connection<commit_after>"""
The Connection class negotiates and manages the connection state.

"""
import locale
import logging
import sys
import socket
try:
    import ssl
except ImportError:
    ssl = None

from pamqp import frame
from pamqp import header
from pamqp import exceptions as pamqp_exceptions
from pamqp import specification
from pamqp import PYTHON3

from rmqid import base
from rmqid import channel
from rmqid import exceptions
from rmqid import message
from rmqid import utils
from rmqid import __version__

LOGGER = logging.getLogger(__name__)


class Connection(base.StatefulObject):
    """The Connection object is responsible for negotiating a connection and
    managing its state.

    """
    CANCEL_METHOD = ['Basic.Cancel']
    CHANNEL = 0
    CONNECTION_TIMEOUT = 1
    CONTENT_METHODS = ['Basic.Deliver', 'Basic.GetOk', 'Basic.Return']
    DEFAULT_HEARTBEAT_INTERVAL = 3
    DEFAULT_LOCALE = 'en_US'
    DEFAULT_URL = 'amqp://guest:guest@localhost:5672/%2F'
    DEFAULT_VHOST = '%2F'
    GUEST = 'guest'
    PORTS = {'amqp': 5672, 'amqps': 5671}

    def __init__(self, url=None):
        """Create a new instance of the Connection object

        :param str url: The AMQP connection URL

        """
        super(Connection, self).__init__()
        self._args = self._process_url(url or self.DEFAULT_URL)
        self._buffer = bytes() if PYTHON3 else str()
        self._channels = dict()
        self._messages = dict()
        self._stack = list()
        self._heartbeat = 0
        self._maximum_channels = 0
        self.maximum_frame_size = specification.FRAME_MAX_SIZE
        self.minimum_frame_size = specification.FRAME_MIN_SIZE
        self._properties = dict()
        self._socket = None
        self._connect()

    def __enter__(self):
        return self

    def __exit__(self, exc_type, exc_val, exc_tb):
        if exc_type:
            LOGGER.exception('Connection context manager closed on exception',
                             exc_tb)
            raise exc_type(exc_val)
        LOGGER.debug('Closing connection')
        self.close()

    def close(self):
        """Close the connection, including all open channels"""
        if not self.closed:
            LOGGER.debug('Closing the connection')
            self._set_state(self.CLOSING)
            self._close_channels()
{'fraction_non_alphanumeric': 0.08251807741386644, 'fraction_numerical': 0.00893236920459379, 'mean_word_length': 2.789685737308622, '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': '7515496', 'n_tokens_mistral': 1390, 'n_tokens_neox': 1336, 'n_words': 409}