本文整理汇总了Python中eventsocket.EventSocket.connect方法的典型用法代码示例。如果您正苦于以下问题:Python EventSocket.connect方法的具体用法?Python EventSocket.connect怎么用?Python EventSocket.connect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类eventsocket.EventSocket
的用法示例。
在下文中一共展示了EventSocket.connect方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_connect_sets_default_timeout_from_socket
# 需要导入模块: from eventsocket import EventSocket [as 别名]
# 或者: from eventsocket.EventSocket import connect [as 别名]
def test_connect_sets_default_timeout_from_socket(self):
now = time.time()
sock = EventSocket()
expect( time, 'time' ).returns( now )
sock._sock.settimeout( 8.67 )
expect( sock._connect_cb ).args( now+8.67, ('localhost',5309), immediate_raise=True )
sock.connect( ('localhost',5309) )
示例2: test_connect_sets_timeoutat_from_kwargs
# 需要导入模块: from eventsocket import EventSocket [as 别名]
# 或者: from eventsocket.EventSocket import connect [as 别名]
def test_connect_sets_timeoutat_from_kwargs(self):
now = time.time()
sock = EventSocket()
expect( time, 'time' ).returns( now )
expect( sock._connect_cb ).args( now+5.3, ('localhost',5309), immediate_raise=True )
sock.connect( ('localhost',5309), timeout=5.3 )
expect( sock._connect_cb ).args( now+5.7, ('localhost',5309), immediate_raise=True )
sock.connect( ('localhost',5309), timeout_at=now+5.7 )
示例3: Connection
# 需要导入模块: from eventsocket import EventSocket [as 别名]
# 或者: from eventsocket.EventSocket import connect [as 别名]
class Connection(object):
class TooManyChannels(ConnectionError): '''This connection has too many channels open. Non-fatal.'''
class InvalidChannel(ConnectionError): '''The channel id does not correspond to an existing channel. Non-fatal.'''
def __init__(self, **kwargs):
'''
Initialize the connection.
'''
self._debug = kwargs.get('debug', False)
self._logger = kwargs.get('logger', root_logger)
self._user = kwargs.get('user', 'guest')
self._password = kwargs.get('password', 'guest')
self._host = kwargs.get('host', 'localhost')
self._vhost = kwargs.get('vhost', '/')
self._connect_timeout = kwargs.get('connect_timeout', 5)
self._sock_opts = kwargs.get('sock_opts')
self._sock = None
self._heartbeat = kwargs.get('heartbeat')
self._reconnect_cb = kwargs.get('reconnect_cb')
self._close_cb = kwargs.get('close_cb')
self._login_method = kwargs.get('login_method', 'AMQPLAIN')
self._locale = kwargs.get('locale', 'en_US')
self._client_properties = kwargs.get('client_properties')
self._properties = LIBRARY_PROPERTIES.copy()
if self._client_properties:
self._properties.update( self._client_properties )
self._closed = False
self._connected = False
self._close_info = {
'reply_code' : 0,
'reply_text' : 'first connect',
'class_id' : 0,
'method_id' : 0
}
self._channels = {
0 : ConnectionChannel(self, 0)
}
login_response = Writer()
login_response.write_table({'LOGIN': self._user, 'PASSWORD': self._password})
#stream = BytesIO()
#login_response.flush(stream)
#self._login_response = stream.getvalue()[4:] #Skip the length
#at the beginning
self._login_response = login_response.buffer()[4:]
self._channel_counter = 0
self._channel_max = 65535
self._frame_max = 65535
self._frames_read = 0
self._frames_written = 0
self._strategy = kwargs.get('connection_strategy')
if not self._strategy:
self._strategy = ConnectionStrategy( self, self._host, reconnect_cb = self._reconnect_cb )
self._strategy.connect()
self._output_frame_buffer = []
@property
def logger(self):
return self._logger
@property
def debug(self):
return self._debug
@property
def frame_max(self):
return self._frame_max
@property
def channel_max(self):
return self._channel_max
@property
def frames_read(self):
'''Number of frames read in the lifetime of this connection.'''
return self._frames_read
@property
def frames_written(self):
'''Number of frames written in the lifetime of this connection.'''
return self._frames_written
@property
def close_info(self):
'''Return dict with information on why this connection is closed. Will
return None if the connections is open.'''
return self._close_info if self._closed else None
def reconnect(self):
#.........这里部分代码省略.........