当前位置: 首页>>代码示例>>Python>>正文


Python Server.start方法代码示例

本文整理汇总了Python中server.server.Server.start方法的典型用法代码示例。如果您正苦于以下问题:Python Server.start方法的具体用法?Python Server.start怎么用?Python Server.start使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在server.server.Server的用法示例。


在下文中一共展示了Server.start方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: main

# 需要导入模块: from server.server import Server [as 别名]
# 或者: from server.server.Server import start [as 别名]
def main():
    parser = argparse.ArgumentParser(description='Tic Tac Toe')
    subparsers = parser.add_subparsers(title='module', dest='module')
    subparsers.required = True
    subparsers.add_parser('server', help='start the server')
    subparsers.add_parser('client', help='start a client')

    args = parser.parse_args()

    if args.module == 'server':
        server = Server()
        try:
            server.start()
        except BaseException as e:
            logger.error('Process interrupted, stopping the server', exc_info=e)
        finally:
            server.stop()
    elif args.module == 'client':
        client = Client()
        try:
            client.connect()
            client.run()
        except BaseException as e:
            logger.error('Process interrupted, disconnecting the client', exc_info=e)
        finally:
            client.disconnect()
    else:
        print('unknown module {}'.format(args.module), file=sys.stderr)
开发者ID:jchmura,项目名称:PiE,代码行数:30,代码来源:main.py

示例2: StartStop

# 需要导入模块: from server.server import Server [as 别名]
# 或者: from server.server.Server import start [as 别名]
class StartStop(unittest.TestCase):
	def setUp(self):
		"""Call before every test case."""
		self.__server = Server()
		self.__server.setLogLevel(0)
		self.__server.start(False)
	def tearDown(self):
		"""Call after every test case."""
		self.__server.quit()
	
	def testStartStopJail(self):
		name = "TestCase"
		self.__server.addJail(name)
		self.__server.startJail(name)
		time.sleep(1)
		self.__server.stopJail(name)
开发者ID:,项目名称:,代码行数:18,代码来源:

示例3: Transmitter

# 需要导入模块: from server.server import Server [as 别名]
# 或者: from server.server.Server import start [as 别名]
class Transmitter(unittest.TestCase):
	
	def setUp(self):
		"""Call before every test case."""
		self.__server = Server()
		self.__server.setLogLevel(0)
		self.__server.start(False)

	def tearDown(self):
		"""Call after every test case."""
		self.__server.quit()
	
	def testSetActionOK(self):
		name = "TestCase"
		cmdList = [["add", name],
				   ["set", name, "actionstart", "Action Start"],
				   ["set", name, "actionstop", "Action Stop"],
				   ["set", name, "actioncheck", "Action Check"],
				   ["set", name, "actionban", "Action Ban"],
				   ["set", name, "actionunban", "Action Unban"],
				   ["quit"]]
		
		outList = [(0, name),
				   (0, 'Action Start'),
				   (0, 'Action Stop'),
				   (0, 'Action Check'),
				   (0, 'Action Ban'),
				   (0, 'Action Unban'),
				   (0, None)]
		
		cnt = 0
		for cmd in cmdList:
			self.assertEqual(self.__server.transm.proceed(cmd), outList[cnt])
			cnt += 1
	
	def testSetActionNOK(self):
		name = "TestCase"
		cmdList = [["addd", name],
				   ["set", name, "test"],
				   ["prout prout", "Stop"],
				   ["fail2ban", "sucks"],
				   ["set"],
				   ["_/&%", "@*+%&"],
				   [" quit"]]
		
		outList = [1,
				   1,
				   1,
				   1,
				   1,
				   1,
				   1]
		
		cnt = 0
		for cmd in cmdList:
			msg = self.__server.transm.proceed(cmd)
			self.assertEqual(msg[0], outList[cnt])
			cnt += 1
	
	def testJail(self):
		name = "TestCase"
		cmdList = [["add", name],
				   ["set", name, "logpath", "testcases/files/testcase01.log"],
				   ["set", name, "timeregex", "\S{3}\s{1,2}\d{1,2} \d{2}:\d{2}:\d{2}"],
				   ["set", name, "timepattern", "%b %d %H:%M:%S"],
				   ["set", name, "failregex", "Authentication failure"],
				   ["start", name],
				   ["stop", name],
				   ["quit"]]
				  
		for cmd in cmdList:
			self.__server.transm.proceed(cmd)
			if cmd == ["start", name]:
				time.sleep(2)
				jail = self.__server.jails[name]
				self.assertEqual(jail.getFilter().failManager.size(), 0)
				self.assertEqual(jail.getAction().banManager.size(), 2)
开发者ID:alstonfernandez21,项目名称:puppetmodulesrevised,代码行数:79,代码来源:servertestcase.py

示例4: Transmitter

# 需要导入模块: from server.server import Server [as 别名]
# 或者: from server.server.Server import start [as 别名]
class Transmitter(unittest.TestCase):
	
	def setUp(self):
		"""Call before every test case."""
		self.__server = Server()
		self.__transm = self.__server._Server__transm
		self.__server.setLogTarget("/dev/null")
		self.__server.setLogLevel(0)
		sock_fd, sock_name = tempfile.mkstemp('fail2ban.sock', 'transmitter')
		os.close(sock_fd)
		pidfile_fd, pidfile_name = tempfile.mkstemp(
			'fail2ban.pid', 'transmitter')
		os.close(pidfile_fd)
		self.__server.start(sock_name, pidfile_name, force=False)
		self.jailName = "TestJail1"
		self.__server.addJail(self.jailName, "auto")

	def tearDown(self):
		"""Call after every test case."""
		self.__server.quit()

	def setGetTest(self, cmd, inValue, outValue=None, jail=None):
		setCmd = ["set", cmd, inValue]
		getCmd = ["get", cmd]
		if jail is not None:
			setCmd.insert(1, jail)
			getCmd.insert(1, jail)
		if outValue is None:
			outValue = inValue

		self.assertEqual(self.__transm.proceed(setCmd), (0, outValue))
		self.assertEqual(self.__transm.proceed(getCmd), (0, outValue))

	def setGetTestNOK(self, cmd, inValue, jail=None):
		setCmd = ["set", cmd, inValue]
		getCmd = ["get", cmd]
		if jail is not None:
			setCmd.insert(1, jail)
			getCmd.insert(1, jail)

		# Get initial value before trying invalid value
		initValue = self.__transm.proceed(getCmd)[1]
		self.assertEqual(self.__transm.proceed(setCmd)[0], 1)
		# Check after failed set that value is same as previous
		self.assertEqual(self.__transm.proceed(getCmd), (0, initValue))

	def jailAddDelTest(self, cmd, values, jail):
		cmdAdd = "add" + cmd
		cmdDel = "del" + cmd

		self.assertEqual(
			self.__transm.proceed(["get", jail, cmd]), (0, []))
		for n, value in enumerate(values):
			self.assertEqual(
				self.__transm.proceed(["set", jail, cmdAdd, value]),
				(0, values[:n+1]))
			self.assertEqual(
				self.__transm.proceed(["get", jail, cmd]),
				(0, values[:n+1]))
		for n, value in enumerate(values):
			self.assertEqual(
				self.__transm.proceed(["set", jail, cmdDel, value]),
				(0, values[n+1:]))
			self.assertEqual(
				self.__transm.proceed(["get", jail, cmd]),
				(0, values[n+1:]))

	def jailAddDelRegexTest(self, cmd, inValues, outValues, jail):
		cmdAdd = "add" + cmd
		cmdDel = "del" + cmd

		if outValues is None:
			outValues = inValues

		self.assertEqual(
			self.__transm.proceed(["get", jail, cmd]), (0, []))
		for n, value in enumerate(inValues):
			self.assertEqual(
				self.__transm.proceed(["set", jail, cmdAdd, value]),
				(0, outValues[:n+1]))
			self.assertEqual(
				self.__transm.proceed(["get", jail, cmd]),
				(0, outValues[:n+1]))
		for n, value in enumerate(inValues):
			self.assertEqual(
				self.__transm.proceed(["set", jail, cmdDel, 0]), # First item
				(0, outValues[n+1:]))
			self.assertEqual(
				self.__transm.proceed(["get", jail, cmd]),
				(0, outValues[n+1:]))

	def testPing(self):
		self.assertEqual(self.__transm.proceed(["ping"]), (0, "pong"))

	def testSleep(self):
		t0 = time.time()
		self.assertEqual(self.__transm.proceed(["sleep", "1"]), (0, None))
		t1 = time.time()
		# Approx 1 second delay
		self.assertAlmostEqual(t1 - t0, 1, places=2)
#.........这里部分代码省略.........
开发者ID:pborreli,项目名称:fail2ban,代码行数:103,代码来源:servertestcase.py

示例5: serverStartWithParams

# 需要导入模块: from server.server import Server [as 别名]
# 或者: from server.server.Server import start [as 别名]
 def serverStartWithParams():
     base_dir = os.path.dirname(os.path.dirname(__file__))  # This is your Project Root
     config_path = os.path.join(base_dir, 'tests/configs/config_no_vlan')  # Join Project Root with config
     Server.start(config_path=config_path)
开发者ID:freifunk-darmstadt,项目名称:TestFramework,代码行数:6,代码来源:test_Server_2.py

示例6:

# 需要导入模块: from server.server import Server [as 别名]
# 或者: from server.server.Server import start [as 别名]
#!/usr/bin/env python3

from server.server import Server

try:
    Server.start()
except KeyboardInterrupt:
    Server.stop()
开发者ID:PumucklOnTheAir,项目名称:TestFramework,代码行数:10,代码来源:start_server.py

示例7: serverStartWithParams

# 需要导入模块: from server.server import Server [as 别名]
# 或者: from server.server.Server import start [as 别名]
 def serverStartWithParams():
     base_dir = os.path.dirname(os.path.dirname(__file__))  # This is your Project Root
     config_path = os.path.join(base_dir, "framework_unittests/configs/config_no_vlan")
     Server.start(config_path=config_path)
开发者ID:PumucklOnTheAir,项目名称:TestFramework,代码行数:6,代码来源:test_A_cli.py

示例8: serverStartWithParams

# 需要导入模块: from server.server import Server [as 别名]
# 或者: from server.server.Server import start [as 别名]
 def serverStartWithParams():
     Server.start()
开发者ID:PumucklOnTheAir,项目名称:TestFramework,代码行数:4,代码来源:test_R_Server_VLAN.py

示例9: serverStartWithParams

# 需要导入模块: from server.server import Server [as 别名]
# 或者: from server.server.Server import start [as 别名]
 def serverStartWithParams():
     Server.start(debug_mode=True, config_path="../tests/config", vlan_activate=False)
开发者ID:freifunk-darmstadt,项目名称:TestFramework,代码行数:4,代码来源:test_server_alive.py

示例10: serverStartWithParams

# 需要导入模块: from server.server import Server [as 别名]
# 或者: from server.server.Server import start [as 别名]
 def serverStartWithParams():
     Server.start(config_path='framework_unittests/configs/config_no_vlan')
开发者ID:PumucklOnTheAir,项目名称:TestFramework,代码行数:4,代码来源:test_server_alive.py


注:本文中的server.server.Server.start方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。