python类engine()的实例源码

test_plugins.py 文件源码 项目:auth-tool 作者: luciddg 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def test_change_passwd_bad_dn(self):
        with self.assertRaises(cherrypy.process.wspbus.ChannelFailures):
            cherrypy.engine.publish('ldap-change-password', 'bob,,', 'alicepw', self.hashes)
test_plugins.py 文件源码 项目:auth-tool 作者: luciddg 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
def test_add_sshpubkey(self):
        # key validation happens at the model level; using a short key for brevity
        sshpubkey = 'ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAo1d01QraTlMVSsbxNrRFi9wrf+M7Q== fakekey'
        cherrypy.engine.publish('ldap-add-key', 'bob', sshpubkey)
        bob = cherrypy.engine.publish('ldap-user-by-uid', 'bob').pop()
        self.assertEqual(sshpubkey in bob['sshPublicKey'], True)
test_plugins.py 文件源码 项目:auth-tool 作者: luciddg 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def setUpClass(cls):
        cherrypy.engine.stop()
        cherrypy.engine.passwd = PasswordEnginePlugin(cherrypy.engine)
        cherrypy.engine.passwd.subscribe()
        cherrypy.engine.start()
test_plugins.py 文件源码 项目:auth-tool 作者: luciddg 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def tearDownClass(cls):
        cherrypy.engine.passwd.unsubscribe()
        del cherrypy.engine.passwd
test_plugins.py 文件源码 项目:auth-tool 作者: luciddg 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def test_plugin(self, mock_random):
        print cherrypy.engine.publish
        hashes = cherrypy.engine.publish('password-hash', 'changeme').pop()
        self.assertIsInstance(hashes, dict)
        self.assertEqual(hashes['userPassword'], '{SSHA}6QBuyak4WbsUzcqUKx0yB74RFUFvDbys')
        self.assertEqual(hashes['sambaNTPassword'], '6597D9FE8469E21D840E2CBFF8D43C8B')
test_plugins.py 文件源码 项目:auth-tool 作者: luciddg 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def setUpClass(cls):
        cherrypy.engine.stop()
        cherrypy.engine.token = TokenEnginePlugin(cherrypy.engine, secret="testsecret")
        cherrypy.engine.token.subscribe()
        cherrypy.engine.start()
test_plugins.py 文件源码 项目:auth-tool 作者: luciddg 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def tearDownClass(cls):
        cherrypy.engine.token.unsubscribe()
        del cherrypy.engine.token
test_plugins.py 文件源码 项目:auth-tool 作者: luciddg 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def test_valid_token(self, mock_epoch):
        valid = cherrypy.engine.publish('token-verify', self.valid_token, self.data).pop()
        self.assertEqual(valid, True)
test_plugins.py 文件源码 项目:auth-tool 作者: luciddg 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def test_invalid_token(self, mock_epoch):
        invalid = cherrypy.engine.publish('token-verify', self.invalid_token, self.data).pop()
        self.assertEqual(invalid, False)
test_plugins.py 文件源码 项目:auth-tool 作者: luciddg 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def test_invalid_data(self, mock_epoch):
        invalid = cherrypy.engine.publish('token-verify', self.valid_token, 'baddata').pop()
        self.assertEqual(invalid, False)
test_plugins.py 文件源码 项目:auth-tool 作者: luciddg 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def test_expired_token(self, mock_epoch=15999.0):
        invalid = cherrypy.engine.publish('token-verify', self.valid_token, self.data).pop()
        self.assertEqual(invalid, False)
serve.py 文件源码 项目:auth-tool 作者: luciddg 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def run(self):
        engine = cherrypy.engine

        if hasattr(engine, "signal_handler"):
            engine.signal_handler.subscribe()

        if hasattr(engine, "console_control_handler"):
            engine.console_control_handler.subscribe()

        engine.start()
        engine.block()
cherrypyserver.py 文件源码 项目:arduino-ciao-meteor-ddp-connector 作者: andrea689 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def cleanup(self):
        """
        Terminate all connections and clear the pool. Executed when the engine stops.
        """
        self.manager.close_all()
        self.manager.stop()
        self.manager.join()
cherrypy_server.py 文件源码 项目:of 作者: OptimalBPM 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def start_server():
    """
        Initialize and start the server.
    """
    if hasattr(cherrypy.engine, 'subscribe'):  # CherryPy >= 3.1
        pass
    else:
        raise Exception("This application requires CherryPy >= 3.1 or higher.")
        # cherrypy.engine.on_stop_engine_list.append(_save_data)

    # Some global configuration

    cherrypy.config.update({"server.ssl_certificate": os.path.join(os.path.dirname(__file__), "../cert.pem"),
                            "server.ssl_private_key": os.path.join(os.path.dirname(__file__), "../privkey.pem")})

    # cherrypy.config.update(config=os.path.join(script_dir, "config.ini"))
    app = cherrypy.tree.mount(Server(), '/',
                              {'/':
                                  {
                                      "tools.staticdir.root": os.path.abspath(
                                          os.path.join(os.path.dirname(__file__), "static")),
                                      "tools.decode.on": True,
                                      "tools.trailing_slash.on": True,
                                      "tools.staticdir.on": True,
                                      "tools.staticdir.index": "index.html",
                                      "tools.staticdir.dir": ""
                                  }
                              })

    if hasattr(cherrypy.engine, "signal_handler"):
        cherrypy.engine.signal_handler.subscribe()
    if hasattr(cherrypy.engine, "console_control_handler"):
        cherrypy.engine.console_control_handler.subscribe()
    cherrypy.engine.start()
    cherrypy.engine.block()
cherrypyserver.py 文件源码 项目:wptagent 作者: WPO-Foundation 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def cleanup(self):
        """
        Terminate all connections and clear the pool. Executed when the engine stops.
        """
        self.manager.close_all()
        self.manager.stop()
        self.manager.join()
rest_api.py 文件源码 项目:xivo-ctid-ng 作者: wazo-pbx 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def run(self):
        wsgi_app_https = ReverseProxied(ProxyFix(wsgi.WSGIPathInfoDispatcher({'/': app})))
        wsgi_app_http = ReverseProxied(ProxyFix(wsgi.WSGIPathInfoDispatcher({'/': adapter_app})))
        cherrypy.server.unsubscribe()
        cherrypy.config.update({'environment': 'production'})

        bind_addr = (self.config['listen'], self.config['port'])

        server_https = wsgi.WSGIServer(bind_addr=bind_addr,
                                       wsgi_app=wsgi_app_https)
        server_https.ssl_adapter = http_helpers.ssl_adapter(self.config['certificate'],
                                                            self.config['private_key'])
        ServerAdapter(cherrypy.engine, server_https).subscribe()
        logger.debug('WSGIServer starting... uid: %s, listen: %s:%s',
                     os.getuid(), bind_addr[0], bind_addr[1])

        for route in http_helpers.list_routes(app):
            logger.debug(route)

        if self.adapter_config['enabled']:
            bind_addr = (self.adapter_config['listen'], self.adapter_config['port'])
            server_adapter = wsgi.WSGIServer(bind_addr=bind_addr,
                                             wsgi_app=wsgi_app_http)
            ServerAdapter(cherrypy.engine, server_adapter).subscribe()
            logger.debug('WSGIServer starting... uid: %s, listen: %s:%s',
                         os.getuid(), bind_addr[0], bind_addr[1])

            for route in http_helpers.list_routes(adapter_app):
                logger.debug(route)

        else:
            logger.debug('Adapter server is disabled')

        try:
            cherrypy.engine.start()
            cherrypy.engine.wait(states.EXITING)
        except KeyboardInterrupt:
            logger.warning('Stopping xivo-ctid-ng: KeyboardInterrupt')
            cherrypy.engine.exit()
rest_api.py 文件源码 项目:xivo-ctid-ng 作者: wazo-pbx 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def stop(self):
        cherrypy.engine.exit()
rest_api.py 文件源码 项目:xivo-ctid-ng 作者: wazo-pbx 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def join(self):
        if cherrypy.engine.state == states.EXITING:
            cherrypy.engine.block()
sessions.py 文件源码 项目:autosub-bootstrapbill 作者: BenjV 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def load(self):
        """Copy stored session data into this session instance."""
        data = self._load()
        # data is either None or a tuple (session_data, expiration_time)
        if data is None or data[1] < self.now():
            if self.debug:
                cherrypy.log('Expired session %r, flushing data.' % self.id,
                             'TOOLS.SESSIONS')
            self._data = {}
        else:
            if self.debug:
                cherrypy.log('Data loaded for session %r.' % self.id,
                             'TOOLS.SESSIONS')
            self._data = data[0]
        self.loaded = True

        # Stick the clean_thread in the class, not the instance.
        # The instances are created and destroyed per-request.
        cls = self.__class__
        if self.clean_freq and not cls.clean_thread:
            # clean_up is an instancemethod and not a classmethod,
            # so that tool config can be accessed inside the method.
            t = cherrypy.process.plugins.Monitor(
                cherrypy.engine, self.clean_up, self.clean_freq * 60,
                name='Session cleanup')
            t.subscribe()
            cls.clean_thread = t
            t.start()
            if self.debug:
                cherrypy.log('Started cleanup thread.', 'TOOLS.SESSIONS')


问题


面经


文章

微信
公众号

扫码关注公众号