本文整理汇总了Python中pysap.SAPRouter.SAPRoutedStreamSocket.sr方法的典型用法代码示例。如果您正苦于以下问题:Python SAPRoutedStreamSocket.sr方法的具体用法?Python SAPRoutedStreamSocket.sr怎么用?Python SAPRoutedStreamSocket.sr使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pysap.SAPRouter.SAPRoutedStreamSocket
的用法示例。
在下文中一共展示了SAPRoutedStreamSocket.sr方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: PySAPRoutedStreamSocketTest
# 需要导入模块: from pysap.SAPRouter import SAPRoutedStreamSocket [as 别名]
# 或者: from pysap.SAPRouter.SAPRoutedStreamSocket import sr [as 别名]
class PySAPRoutedStreamSocketTest(unittest.TestCase):
test_port = 8005
test_address = "127.0.0.1"
test_string = "TEST" * 10
def start_server(self, handler_cls):
self.server = SAPNIServerThreaded((self.test_address, self.test_port),
handler_cls,
bind_and_activate=False)
self.server.allow_reuse_address = True
self.server.server_bind()
self.server.server_activate()
self.server_thread = Thread(target=self.server.serve_forever)
self.server_thread.start()
def stop_server(self):
self.server.shutdown()
self.server.server_close()
self.server_thread.join()
def test_saproutedstreamsocket(self):
"""Test SAPRoutedStreamSocket"""
self.start_server(SAPRouterServerTestHandler)
sock = socket.socket()
sock.connect((self.test_address, self.test_port))
route = [SAPRouterRouteHop(hostname=self.test_address,
port=self.test_port),
SAPRouterRouteHop(hostname="10.0.0.1",
port="3200")]
self.client = SAPRoutedStreamSocket(sock, route=route,
router_version=40)
packet = self.client.sr(self.test_string)
self.assertIn(SAPNI, packet)
self.assertEqual(packet[SAPNI].length, len(self.test_string) + 4)
self.assertEqual(unpack("!I", packet[SAPNI].payload.load[:4]), (len(self.test_string), ))
self.assertEqual(packet[SAPNI].payload.load[4:], self.test_string)
self.client.close()
self.stop_server()
def test_saproutedstreamsocket_route_error(self):
"""Test SAPRoutedStreamSocket throwing of SAPRouteException if
a route denied return error is received"""
self.start_server(SAPRouterServerTestHandler)
sock = socket.socket()
sock.connect((self.test_address, self.test_port))
route = [SAPRouterRouteHop(hostname=self.test_address,
port=self.test_port),
SAPRouterRouteHop(hostname="10.0.0.2",
port="3200")]
with self.assertRaises(SAPRouteException):
self.client = SAPRoutedStreamSocket(sock, route=route,
router_version=40)
self.stop_server()
def test_saproutedstreamsocket_error(self):
"""Test SAPRoutedStreamSocket throwing of Exception if an invalid
or unexpected packet is received"""
self.start_server(SAPRouterServerTestHandler)
sock = socket.socket()
sock.connect((self.test_address, self.test_port))
with self.assertRaises(Exception):
self.client = SAPRoutedStreamSocket(sock, route=None,
router_version=40)
self.stop_server()
def test_saproutedstreamsocket_getnisocket(self):
"""Test SAPRoutedStreamSocket get nisocket class method"""
self.start_server(SAPRouterServerTestHandler)
# Test using a complete route
route = [SAPRouterRouteHop(hostname=self.test_address,
port=self.test_port),
SAPRouterRouteHop(hostname="10.0.0.1",
port="3200")]
self.client = SAPRoutedStreamSocket.get_nisocket(route=route,
router_version=40)
packet = self.client.sr(self.test_string)
self.assertIn(SAPNI, packet)
self.assertEqual(packet[SAPNI].length, len(self.test_string) + 4)
self.assertEqual(unpack("!I", packet[SAPNI].payload.load[:4]), (len(self.test_string), ))
self.assertEqual(packet[SAPNI].payload.load[4:], self.test_string)
# Test using a route and a target host/port
route = [SAPRouterRouteHop(hostname=self.test_address,
port=self.test_port)]
self.client = SAPRoutedStreamSocket.get_nisocket("10.0.0.1",
#.........这里部分代码省略.........