Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
server.request = restRequest
cherrypy.server.unsubscribe()
cherrypy.config.update({'environment': 'embedded',
'log.screen': False,
'request.throw_errors': True})
cherrypy.engine.start()
yield server
cherrypy.engine.unsubscribe('start', girder.events.daemon.start)
cherrypy.engine.unsubscribe('stop', girder.events.daemon.stop)
cherrypy.engine.stop()
cherrypy.engine.exit()
cherrypy.tree.apps = {}
cherrypy.tree.girder_app = None
plugin_utilities.getPluginDir = oldPluginDir
plugin_utilities.getPluginWebroots().clear()
plugin_utilities.getPluginFailureInfo().clear()
docs.routes.clear()
def setUpModule():
app = TestApp()
cherrypy.tree.mount(app.getRoot(), '/')
cherrypy.engine.start()
yield "data: %s\n\n" % json.dumps({"clear":True})
for bird in birds:
yield "data: %s\n\n" % json.dumps({"update":bird})
# Send incremental updates as they happen.
while cherrypy.engine.state == cherrypy.engine.states.STARTED:
try:
operation = queue.get(timeout=2.0)
yield "data: %s\n\n" % operation
except:
yield ":\n\n"
cherrypy.log.error("Stopping birds handler.")
return content()
birds._cp_config = {"response.stream": True}
cherrypy.quickstart(Root(), '/', config={
"/js" : {
"tools.staticdir.dir" : os.path.abspath("js"),
"tools.staticdir.on" : True,
}
@cherrypy.expose
@cherrypy.tools.jsonrpchdl()
def services(self, *args, **kwargs):
print "echo service"
print args
print kwargs
method = kwargs['method']
f = getattr(self,method)
res = f(*kwargs['params'])
return dumps({'id':kwargs['id'],'result':res,'error':None})
def echo(self, text):
def setUpModule():
global model, test_server, fake_iso
cherrypy.request.headers = {'Accept': 'application/json'}
patch_auth()
test_server = run_server(test_mode=True)
model = cherrypy.tree.apps['/plugins/kimchi'].root.model
fake_iso = '/tmp/fake.iso'
iso_gen.construct_fake_iso(fake_iso, True, '12.04', 'ubuntu')
@cherrypy.expose
def index(self):
return """
@cherrypy.expose()
def shutdown(self):
""" Shutdown CherryPy and exit script """
self.logger.info("Shutting down htpc-manager.")
cherrypy.engine.exit()
return "HTPC Manager has shut down"
offset = err.errobj.args[0].offset
sql = sql[:offset] + "<**>" + sql[offset:]
cherrypy.log("SERVER DATABASE ERROR %d/%d %s %s.%s %s [instance: %s] (%s);"
" last statement: %s; binds: %s, %s; offset: %s"
% (err.http_code, err.app_code, err.message,
getattr(err.errobj, "__module__", "__builtins__"),
err.errobj.__class__.__name__,
err.errid, err.instance, str(err.errobj).rstrip(),
sql, binds, kwbinds, offset))
for line in err.trace.rstrip().split("\n"): cherrypy.log(" " + line)
cherrypy.response.headers["X-REST-Status"] = str(err.app_code)
cherrypy.response.headers["X-Error-HTTP"] = str(err.http_code)
cherrypy.response.headers["X-Error-ID"] = err.errid
report_error_header("X-Error-Detail", err.message)
report_error_header("X-Error-Info", err.info)
if throw: raise cherrypy.HTTPError(err.http_code, err.message)
elif isinstance(err, RESTError):
if err.errobj:
cherrypy.log("SERVER REST ERROR %s.%s %s (%s); derived from %s.%s (%s)"
% (err.__module__, err.__class__.__name__,
err.errid, err.message,
getattr(err.errobj, "__module__", "__builtins__"),
err.errobj.__class__.__name__,
str(err.errobj).rstrip()))
trace = err.trace
else:
cherrypy.log("SERVER REST ERROR %s.%s %s (%s)"
% (err.__module__, err.__class__.__name__,
err.errid, err.message))
for line in trace.rstrip().split("\n"): cherrypy.log(" " + line)
cherrypy.response.headers["X-REST-Status"] = str(err.app_code)
cherrypy.response.headers["X-Error-HTTP"] = str(err.http_code)
def __check_requirements(self, conditions):
# requested_address = urllib.quote(cherrypy.request.request_line.split()[1])
if conditions is not None:
session = getattr(cherrypy, 'session')
username = session.get(SESSION_KEY, None)
if username:
cherrypy.request.login = username
for condition in conditions:
# A condition is just a callable that returns true or false
if not condition():
# TODO: log why if possible
raise cherrypy.HTTPError(403, 'No allowed')
# TODO: redirect the user to the requested url if the url matches!! -> external view of an event
# raise cherrypy.HTTPRedirect(requested_address)
else:
raise cherrypy.HTTPError(403, 'Not authenticated')