Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
# it mirrors the session function
forumCount = cherrypy.session.forum.get('forumCount', 0) + 1
cherrypy.session.forum['forumCount'] = forumCount
key = cherrypy.session.forum.key
cookieName = cherrypy.session.forum.cookieName
return self.__examplePage('ram', forumCount, self.samplePages, key, cookieName)
forum.exposed=True
cherrypy.root = HitCounter()
if __name__ == '__main__':
cherrypy.config.update(file = "tutorial.conf")
cherrypy.server.start()
sys.path = [''] + sys.path
for i in imports or []:
exec('import %s' % i)
for c in configfiles or []:
cherrypy.config.update(c)
# If there's only one app mounted, merge config into it.
if len(cherrypy.tree.apps) == 1:
for app in cherrypy.tree.apps.values():
if isinstance(app, Application):
app.merge(c)
engine = cherrypy.engine
if environment is not None:
cherrypy.config.update({'environment': environment})
# Only daemonize if asked to.
if daemonize:
# Don't print anything to stdout/sterr.
cherrypy.config.update({'log.screen': False})
plugins.Daemonizer(engine).subscribe()
if pidfile:
plugins.PIDFile(engine, pidfile).subscribe()
if hasattr(engine, 'signal_handler'):
engine.signal_handler.subscribe()
if hasattr(engine, 'console_control_handler'):
engine.console_control_handler.subscribe()
if (fastcgi and (scgi or cgi)) or (scgi and cgi):
result[section][option] = value
return result
cherrypy.lib.reprconf.Parser.as_dict = new_as_dict
instance = LdapCherry()
app = cherrypy.tree.mount(instance, '/', configfile)
cherrypy.config.update(configfile)
instance.reload(app.config, debug)
engine = cherrypy.engine
# Turn off autoreload
cherrypy.config.update({'engine.autoreload.on': False})
if environment is not None:
cherrypy.config.update({'environment': environment})
# Only daemonize if asked to.
if daemonize:
# Don't print anything to stdout/sterr.
cherrypy.config.update({'log.screen': False})
plugins.Daemonizer(engine).subscribe()
if pidfile:
plugins.PIDFile(engine, pidfile).subscribe()
if hasattr(engine, "signal_handler"):
engine.signal_handler.subscribe()
if hasattr(engine, "console_control_handler"):
engine.console_control_handler.subscribe()
if (fastcgi and (scgi or cgi)) or (scgi and cgi):
def start_server(self, httphandler):
"""use the configuration to setup and start the cherrypy server
"""
cherrypy.config.update({'log.screen': True})
ipv6_enabled = config['server.ipv6_enabled']
if config['server.localhost_only']:
socket_host = "::1" if ipv6_enabled else "127.0.0.1"
else:
socket_host = "::" if ipv6_enabled else "0.0.0.0"
resourcedir = os.path.abspath(pathprovider.getResourcePath('res'))
react_client_dir = os.path.abspath(pathprovider.getResourcePath('res/react-client/dist'))
if config['server.ssl_enabled']:
cert = pathprovider.absOrConfigPath(config['server.ssl_certificate'])
pkey = pathprovider.absOrConfigPath(config['server.ssl_private_key'])
cherrypy.config.update({
'server.ssl_certificate': cert,
'server.ssl_private_key': pkey,
'server.socket_port': config['server.ssl_port'],
if not mapper_file_name.endswith('/base.js') and not mapper_file_name.endswith('/_example.js'):
with open(mapper_file_name) as f:
mappers += f.read()
return mappers
if __name__ == '__main__':
import argparse
parser = argparse.ArgumentParser()
parser.add_argument('environment', type=str, help="Must be either 'production' or 'development'")
args = parser.parse_args()
if args.environment == 'production':
cherrypy.config.update(PRODUCTION_SERVER_CONFIG)
cherrypy.quickstart(RepoGrams(), config=PRODUCTION_INSTANCE_CONFIG)
elif args.environment == 'development':
cherrypy.config.update(DEVELOPMENT_SERVER_CONFIG)
cherrypy.tree.mount(RepoGrams(), '/app', DEVELOPMENT_INSTANCE_CONFIG_APP)
cherrypy.quickstart(config=DEVELOPMENT_INSTANCE_CONFIG_STATIC)
else:
parser.error("Unknown environment: %s" % args.environment)
def __init__(self, img_dir='', timeout=500):
self._lock = threading.Lock()
self._handlers = Handlers(self._lock, timeout=timeout)
cherrypy.config.update({'server.socket_host': '0.0.0.0',
'server.socket_port': 9999,
'server.thread_pool_max': -1,
'server.protocol_version':"HTTP/1.0"})
conf = {'/static':
{'tools.staticdir.on': True,
'tools.staticdir.dir': os.path.join(current_dir, 'static'),
'tools.staticdir.content_types': {'appcache': 'text/cache-manifest'}},
'/imgs':
{'tools.staticdir.on': True,
'tools.staticdir.dir': img_dir},
'/': {'tools.sessions.locking': 'explicit'}}
non_blocking_quickstart(self._handlers, config=conf)
rp_server = RPServer(registration_info, settings["behaviour"],
settings["server"]["verify_ssl"])
# Mount the WSGI callable object (app) on the root directory
cherrypy.tree.mount(rp_server, "/")
# Set the configuration of the web server
cherrypy.config.update({
'tools.sessions.on': True,
'server.socket_port': args.port,
'server.socket_host': '0.0.0.0' # nosec
})
if baseurl.startswith("https://"):
cherrypy.config.update({
'server.ssl_module': 'builtin',
'server.ssl_certificate': settings["server"]["cert"],
'server.ssl_private_key': settings["server"]["key"],
'server.ssl_certificate_chain': settings["server"]["cert_chain"]
})
# Start the CherryPy WSGI web server
cherrypy.engine.start()
cherrypy.engine.block()
result['times']['prepare_fetch_input'] = time.time() - start
start = time.time()
prediction = self.job_model.predict(self.model, numpy.array(encoded_inputs))
result['times']['prediction'] = time.time() - start
self.lock.release()
except Exception as e:
self.lock.release()
return simplejson.dumps({'error': type(e).__name__, 'message': e.message})
result['prediction'] = prediction
return simplejson.dumps(result)
cherrypy.config.update({
'server.socket_host': host,
'server.socket_port': port,
'server.thread_pool': 1,
})
print("Starting server ... Use http://127.0.0.1:8000/predict?paths=path_to_image.jpg or upload files named 'uploads[0]' to http://127.0.0.1:8000/predict.")
cherrypy.quickstart(WebServer(self.lock, self.job_model, self.model))
def update_cherrypy_config(config):
PLUGIN_MANAGER.hook.configure_cherrypy(config=config)
cherrypy.config.update(config)
def wsgi_app(service_cls, *args, **kwargs):
"""Return a WSGI application.
service_cls - Class to launch web service. Must have the constants
service_cls.NS and service_cls.UTIL. *args and **kwargs are
passed to its constructor.
"""
cherrypy.server.unsubscribe()
cherrypy.config.update({'engine.autoreload.on': False})
cherrypy.config.update({'environment': 'embedded'})
cherrypy.engine.start()
cherrypy.engine.signal_handler.unsubscribe()
config = _configure(service_cls)
try:
return cherrypy.Application(service_cls(*args, **kwargs), None, config)
finally:
cherrypy.engine.stop()