#NEWLINE# def new_transport_init( self , host , connect_timeout ) : #NEWLINE# #INDENT# import errno #NEWLINE# import re #NEWLINE# import socket #NEWLINE# import ssl #NEWLINE# try : #NEWLINE# #INDENT# from socket import SOL_TCP #NEWLINE# #UNINDENT# except ImportError : #NEWLINE# #INDENT# from socket import IPPROTO_TCP as SOL_TCP #NEWLINE# #UNINDENT# try : #NEWLINE# #INDENT# from ssl import SSLError #NEWLINE# #UNINDENT# except ImportError : #NEWLINE# #INDENT# class SSLError ( Exception ) : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# #UNINDENT# from struct import pack , unpack #NEWLINE# from amqp.exceptions import UnexpectedFrame #NEWLINE# from amqp.utils import get_errno , set_cloexec #NEWLINE# _UNAVAIL = ( errno . EAGAIN , errno . EINTR , errno . ENOENT ) #NEWLINE# AMQP_PORT = 5672 #NEWLINE# EMPTY_BUFFER = bytes ( ) #NEWLINE# AMQP_PROTOCOL_HEADER = 'AMQP\x01\x01\x00\t' . encode ( 'latin_1' ) #NEWLINE# IPV6_LITERAL = re . compile ( '\\[([\\.0-9a-f:]+)\\](?::(\\d+))?' ) #NEWLINE# self . connected = True #NEWLINE# msg = None #NEWLINE# port = AMQP_PORT #NEWLINE# m = IPV6_LITERAL . match ( host ) #NEWLINE# if m : #NEWLINE# #INDENT# host = m . group ( 1 ) #NEWLINE# if m . group ( 2 ) : #NEWLINE# #INDENT# port = int ( m . group ( 2 ) ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if ( ':' in host ) : #NEWLINE# #INDENT# ( host , port ) = host . rsplit ( ':' , 1 ) #NEWLINE# port = int ( port ) #NEWLINE# #UNINDENT# #UNINDENT# self . sock = None #NEWLINE# last_err = None #NEWLINE# for res in socket . getaddrinfo ( host , port , 0 , socket . SOCK_STREAM , SOL_TCP ) : #NEWLINE# #INDENT# ( af , socktype , proto , canonname , sa ) = res #NEWLINE# try : #NEWLINE# #INDENT# self . sock = socket . socket ( af , socktype , proto ) #NEWLINE# try : #NEWLINE# #INDENT# set_cloexec ( self . sock , True ) #NEWLINE# #UNINDENT# except NotImplementedError : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# self . sock . settimeout ( connect_timeout ) #NEWLINE# self . sock . connect ( sa ) #NEWLINE# #UNINDENT# except socket . error as exc : #NEWLINE# #INDENT# msg = exc #NEWLINE# self . sock . close ( ) #NEWLINE# self . sock = None #NEWLINE# last_err = msg #NEWLINE# continue #NEWLINE# #UNINDENT# break #NEWLINE# #UNINDENT# if ( not self . sock ) : #NEWLINE# #INDENT# raise socket . error ( last_err ) #NEWLINE# #UNINDENT# try : #NEWLINE# #INDENT# self . sock . setsockopt ( SOL_TCP , socket . TCP_NODELAY , 1 ) #NEWLINE# self . sock . setsockopt ( socket . SOL_SOCKET , socket . SO_KEEPALIVE , 1 ) #NEWLINE# self . _setup_transport ( ) #NEWLINE# self . _write ( AMQP_PROTOCOL_HEADER ) #NEWLINE# #UNINDENT# except ( OSError , IOError , socket . error ) as exc : #NEWLINE# #INDENT# if ( get_errno ( exc ) not in _UNAVAIL ) : #NEWLINE# #INDENT# self . connected = False #NEWLINE# #UNINDENT# raise