當前位置: 首頁>>代碼示例>>Python>>正文


Python EventSocket._read_cb方法代碼示例

本文整理匯總了Python中eventsocket.EventSocket._read_cb方法的典型用法代碼示例。如果您正苦於以下問題:Python EventSocket._read_cb方法的具體用法?Python EventSocket._read_cb怎麽用?Python EventSocket._read_cb使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在eventsocket.EventSocket的用法示例。


在下文中一共展示了EventSocket._read_cb方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_read_cb_when_no_data

# 需要導入模塊: from eventsocket import EventSocket [as 別名]
# 或者: from eventsocket.EventSocket import _read_cb [as 別名]
 def test_read_cb_when_no_data(self):
   sock = EventSocket()
   sock._sock = mock()
   mock( sock, 'getsockopt' )
   mock( sock, 'close' )
   
   expect( sock.getsockopt ).args( socket.SOL_SOCKET, socket.SO_RCVBUF ).returns( 42 )
   expect( sock._sock.recv ).args( 42 ).returns( '' )
   expect( sock.close )
   
   assert_equals( None, sock._read_cb() )
開發者ID:agoragames,項目名稱:py-eventsocket,代碼行數:13,代碼來源:evented_socket_test.py

示例2: test_read_cb_simplest_case

# 需要導入模塊: from eventsocket import EventSocket [as 別名]
# 或者: from eventsocket.EventSocket import _read_cb [as 別名]
 def test_read_cb_simplest_case(self):
   sock = EventSocket()
   sock._sock = mock()
   mock( sock, 'getsockopt' )
   
   expect( sock.getsockopt ).args( socket.SOL_SOCKET, socket.SO_RCVBUF ).returns( 42 )
   expect( sock._sock.recv ).args( 42 ).returns( 'sumdata' )
   expect( sock._flag_activity )
   
   assert_true( sock._read_cb() )
   assert_equals( bytearray('sumdata'), sock._read_buf )
   assert_equals( 'error reading from socket', sock._error_msg )
開發者ID:agoragames,項目名稱:py-eventsocket,代碼行數:14,代碼來源:evented_socket_test.py

示例3: test_read_cb_when_parent_cb_and_is_a_pending_event_and_already_buffered_data

# 需要導入模塊: from eventsocket import EventSocket [as 別名]
# 或者: from eventsocket.EventSocket import _read_cb [as 別名]
 def test_read_cb_when_parent_cb_and_is_a_pending_event_and_already_buffered_data(self):
   sock = EventSocket()
   sock._read_buf = bytearray('foo')
   sock._sock = mock()
   sock._peername = 'peername'
   sock._parent_read_cb = 'p_read_cb'
   sock._pending_read_cb_event = 'pending_read'
   mock( sock, 'getsockopt' )
   
   expect( sock.getsockopt ).args( socket.SOL_SOCKET, socket.SO_RCVBUF ).returns( 42 )
   expect( sock._sock.recv ).args( 42 ).returns( 'sumdata' )
   expect( sock._flag_activity )
   
   assert_true( sock._read_cb() )
   assert_equals( bytearray('foosumdata'), sock._read_buf )
開發者ID:agoragames,項目名稱:py-eventsocket,代碼行數:17,代碼來源:evented_socket_test.py

示例4: test_read_cb_when_debugging_and_parent_cb_and_no_pending_event

# 需要導入模塊: from eventsocket import EventSocket [as 別名]
# 或者: from eventsocket.EventSocket import _read_cb [as 別名]
 def test_read_cb_when_debugging_and_parent_cb_and_no_pending_event(self):
   sock = EventSocket()
   sock._sock = mock()
   sock._logger = mock()
   sock._peername = 'peername'
   sock._debug = True
   sock._parent_read_cb = 'p_read_cb'
   mock( sock, 'getsockopt' )
   
   expect( sock.getsockopt ).args( socket.SOL_SOCKET, socket.SO_RCVBUF ).returns( 42 )
   expect( sock._sock.recv ).args( 42 ).returns( 'sumdata' )
   expect( sock._logger.debug ).args( 'read 7 bytes from peername' )
   expect( sock._flag_activity )
   expect( eventsocket.event.timeout ).args( 0, sock._protected_cb, sock._parent_read_timer_cb ).returns('pending_read')
   
   assert_true( sock._read_cb() )
   assert_equals( bytearray('sumdata'), sock._read_buf )
   assert_equals( 'pending_read', sock._pending_read_cb_event )
開發者ID:agoragames,項目名稱:py-eventsocket,代碼行數:20,代碼來源:evented_socket_test.py

示例5: test_read_cb_when_buffer_overflow

# 需要導入模塊: from eventsocket import EventSocket [as 別名]
# 或者: from eventsocket.EventSocket import _read_cb [as 別名]
 def test_read_cb_when_buffer_overflow(self):
   sock = EventSocket()
   sock._sock = mock()
   sock._logger = mock()
   sock._peername = 'peername'
   sock._debug = True
   sock._max_read_buffer = 5
   mock( sock, 'getsockopt' )
   mock( sock, 'close' )
   
   expect( sock.getsockopt ).args( socket.SOL_SOCKET, socket.SO_RCVBUF ).returns( 42 )
   expect( sock._sock.recv ).args( 42 ).returns( 'sumdata' )
   expect( sock._logger.debug ).args( 'read 7 bytes from peername' )
   expect( sock._flag_activity )
   expect( sock._logger.debug ).args( 'buffer for peername overflowed!' )
   expect( sock.close )
   
   assert_equals( None, sock._read_cb() )
   assert_equals( bytearray(), sock._read_buf )
開發者ID:agoragames,項目名稱:py-eventsocket,代碼行數:21,代碼來源:evented_socket_test.py


注:本文中的eventsocket.EventSocket._read_cb方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。