in qpid/messaging/endpoints.py [0:0]
def __init__(self, url=None, **options):
"""
Creates a connection. A newly created connection must be opened
with the Connection.open() method before it can be used.
@type url: str
@param url: [ <username> [ / <password> ] @ ] <host> [ : <port> ]
@type host: str
@param host: the name or ip address of the remote host (overriden by url)
@type port: int
@param port: the port number of the remote host (overriden by url)
@type transport: str
@param transport: one of tcp, tcp+tls, or ssl (alias for tcp+tls)
@type heartbeat: int
@param heartbeat: heartbeat interval in seconds
@type username: str
@param username: the username for authentication (overriden by url)
@type password: str
@param password: the password for authentication (overriden by url)
@type sasl_mechanisms: str
@param sasl_mechanisms: space separated list of permitted sasl mechanisms
@type sasl_service: str
@param sasl_service: the service name if needed by the SASL mechanism in use
@type sasl_min_ssf: int
@param sasl_min_ssf: the minimum acceptable security strength factor
@type sasl_max_ssf: int
@param sasl_max_ssf: the maximum acceptable security strength factor
@type reconnect: bool
@param reconnect: enable/disable automatic reconnect
@type reconnect_timeout: float
@param reconnect_timeout: total time to attempt reconnect
@type reconnect_interval_min: float
@param reconnect_interval_min: minimum interval between reconnect attempts
@type reconnect_interval_max: float
@param reconnect_interval_max: maximum interval between reconnect attempts
@type reconnect_interval: float
@param reconnect_interval: set both min and max reconnect intervals
@type reconnect_limit: int
@param reconnect_limit: limit the total number of reconnect attempts
@type reconnect_urls: list[str]
@param reconnect_urls: list of backup hosts specified as urls
@type address_ttl: float
@param address_ttl: time until cached address resolution expires
@type ssl_keyfile: str
@param ssl_keyfile: file with client's private key (PEM format)
@type ssl_certfile: str
@param ssl_certfile: file with client's public (eventually priv+pub) key (PEM format)
@type ssl_trustfile: str
@param ssl_trustfile: file trusted certificates to validate the server
@type ssl_skip_hostname_check: bool
@param ssl_skip_hostname_check: disable verification of hostname in
certificate. Use with caution - disabling hostname checking leaves you
vulnerable to Man-in-the-Middle attacks.
@rtype: Connection
@return: a disconnected Connection
"""
super(Connection, self).__init__()
# List of all attributes
opt_keys = ['host', 'transport', 'port', 'heartbeat', 'username', 'password', 'sasl_mechanisms', 'sasl_service', 'sasl_min_ssf', 'sasl_max_ssf', 'reconnect', 'reconnect_timeout', 'reconnect_interval', 'reconnect_interval_min', 'reconnect_interval_max', 'reconnect_limit', 'reconnect_urls', 'reconnect_log', 'address_ttl', 'tcp_nodelay', 'ssl_keyfile', 'ssl_certfile', 'ssl_trustfile', 'ssl_skip_hostname_check', 'client_properties', 'protocol' ]
# Create all attributes on self and set to None.
for key in opt_keys:
setattr(self, key, None)
# Get values from options, check for invalid options
for (key, value) in options.items():
if key in opt_keys:
setattr(self, key, value)
else:
raise ConnectionError("Unknown connection option %s with value %s" %(key, value))
# Now handle items that need special treatment or have speical defaults:
if self.host:
url = default(url, self.host)
if isinstance(url, basestring):
url = URL(url)
self.host = url.host
if self.transport is None:
if url.scheme == url.AMQP:
self.transport = "tcp"
elif url.scheme == url.AMQPS:
self.transport = "ssl"
else:
self.transport = "tcp"
if self.transport in ("ssl", "tcp+tls"):
self.port = default(url.port, default(self.port, AMQPS_PORT))
else:
self.port = default(url.port, default(self.port, AMQP_PORT))
if self.protocol and self.protocol != "amqp0-10":
raise VersionError(text="Connection option 'protocol' value '" + self.protocol + "' unsupported (must be amqp0-10)")
self.username = default(url.user, self.username)
self.password = default(url.password, self.password)
self.auth_username = None
self.sasl_service = default(self.sasl_service, "qpidd")
self.reconnect = default(self.reconnect, False)
self.reconnect_interval_min = default(self.reconnect_interval_min,
default(self.reconnect_interval, 1))
self.reconnect_interval_max = default(self.reconnect_interval_max,
default(self.reconnect_interval, 2*60))
self.reconnect_urls = default(self.reconnect_urls, [])
self.reconnect_log = default(self.reconnect_log, True)
self.address_ttl = default(self.address_ttl, 60)
self.tcp_nodelay = default(self.tcp_nodelay, False)
self.ssl_keyfile = default(self.ssl_keyfile, None)
self.ssl_certfile = default(self.ssl_certfile, None)
self.ssl_trustfile = default(self.ssl_trustfile, None)
# if ssl_skip_hostname_check was not explicitly set, this will be None
self._ssl_skip_hostname_check_actual = options.get("ssl_skip_hostname_check")
self.ssl_skip_hostname_check = default(self.ssl_skip_hostname_check, False)
self.client_properties = default(self.client_properties, {})
self.options = options
self.id = str(uuid4())
self.session_counter = 0
self.sessions = {}
self._open = False
self._connected = False
self._transport_connected = False
self._lock = RLock()
self._condition = Condition(self._lock)
self._waiter = Waiter(self._condition)
self._modcount = Serial(0)
from .driver import Driver
self._driver = Driver(self)