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


Python Server.handle_request方法代码示例

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


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

示例1: run

# 需要导入模块: from server import Server [as 别名]
# 或者: from server.Server import handle_request [as 别名]
    def run(self):
        """
        Start HTTP daemon
        """
        self.log("Starting new API instance on %d" % self.port)
        http_handler = Handler
        SocketServer.TCPServer.allow_reuse_address = True

        try:
            http_service = ApiServer((self.host, self.port), http_handler, manager=self.manager)
        except socket.error as e:
            self.log("Failed to bind to port. Got: %s" % str(e))
            return False

        if self.ssl:
            self.manager.get_key({'hostname': self.ssl, 'algo': 'RSA', 'bits': 2048})
            key_path = self.manager.get_key_path(self.ssl)

            while True:
                res = self.manager.cert({'hostname': self.ssl, 'ip': '127.0.0.1'})
                if res['status'] != 'available':
                    time.sleep(10)
                    continue

                self.log("Certificate successfully received for %s" % self.ssl)
                break

            cert_path = self.manager.get_fullchain_path(self.ssl)
            self.log("Key: %s, Cert: %s" % (key_path, cert_path))
            http_service.socket = ssl.wrap_socket(http_service.socket, keyfile=key_path, certfile=cert_path, server_side=True)

        self.log("HTTP API server started")
        while self.is_running():
            http_service.handle_request()
开发者ID:alxark,项目名称:scmt,代码行数:36,代码来源:service.py

示例2: TestMySQLServer

# 需要导入模块: from server import Server [as 别名]
# 或者: from server.Server import handle_request [as 别名]
class TestMySQLServer(unittest.TestCase):

    def setUp(self):
        self.server = Server()

    def tearDown(self):
        self.server.shut_down()

    def test_register(self):
        expected_msg = u"<html><head></head><body>Thank you for registering ironman</body></html>"
        result = self.server.handle_request({'action': 'register',
                                             'username': 'ironman',
                                             'password': 'superhero',
                                             'format': 'html',
                                             'db': 'default'})
        self.assertEqual(result, expected_msg, u"Invalid output")
        # This is not enough, I should open the db and do a query like:
        # SELECT EXISTS(SELECT 1 FROM mysql.user WHERE user = 'ironman')
        # And if returns a 1 then, the user was created.

    def test_register_invalid_db(self):
        pass

    def test_login(self):
        expected_msg = u"<html><head></head><body>Login OK</body></html>"
        result = self.server.handle_request({'action': 'login',
                                             'username': 'ironman',
                                             'password': 'superhero',
                                             'format': 'html',
                                             'db': 'default'})
        self.assertEqual(result, expected_msg, u"Invalid output")

    def test_login_invalid_username(self):
        pass

    def test_login_invalid_password(self):
        pass

    def test_login_empty_username_and_password(self):
        pass

    def test_execute_sql(self):
        pass

    def test_execute_invalid_sql(self):
        pass

    def test_output_json_format(self):
        pass

    def test_output_html_format(self):
        pass
开发者ID:fedexcastro,项目名称:testserver,代码行数:54,代码来源:tests.py


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