Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
cherrypy.thread_data.store.rollback()
cherrypy.log("ROLLBACK - " + format_exc(), "STORM")
def try_commit():
if cherrypy.response.stream:
cherrypy.request.hooks.attach('on_end_request', do_commit)
else:
if isinstance(cherrypy.response.body, types.GeneratorType):
cherrypy.response.collapse_body()
do_commit()
class StormHandlerWrapper(object):
# to_skip = (KeyboardInterrupt, SystemExit, cherrypy.HTTPRedirect)
# Nando Florestan does not think the above line is correct,
# because transactions should never be interrupted in the middle:
to_skip = [cherrypy.HTTPRedirect]
def __init__(self):
self.nexthandler = cherrypy.request.handler
cherrypy.request.handler = self
def __call__(self, *args, **kwargs):
try:
cherrypy.request.rolledback = False
result = self.nexthandler(*args, **kwargs)
except Exception, e:
if not isinstance(e, tuple(self.to_skip)):
cherrypy.log("ROLLBACK - " + format_exc(), "STORM")
if hasattr(cherrypy.thread_data, 'store'):
cherrypy.thread_data.store.rollback()
cherrypy.request.rolledback = True
raise
if isinstance(param_data, dict):
equation = param_data[KEY_EQUATION]
focal_points = param_data[KEY_FOCAL_POINTS]
# if focal points or the equation are missing do not update this model parameter
if not focal_points or not equation:
continue
param_data[KEY_EQUATION] = equation.to_json(equation)
param_data[KEY_FOCAL_POINTS] = json.dumps(focal_points)
param_data = json.dumps(param_data)
burst_configuration.update_simulation_parameter(full_name, param_data)
### Update in session BURST configuration for burst-page.
common.add2session(common.KEY_BURST_CONFIG, burst_configuration.clone())
### Clean from session drawing context
common.remove_from_session(KEY_CONTEXT_MPS)
raise cherrypy.HTTPRedirect("/burst/")
lazylibrarian.NZBMATRIX_USER = nzbmatrix_user
lazylibrarian.NZBMATRIX_API = nzbmatrix_api
lazylibrarian.NEWZNAB = newznab
lazylibrarian.NEWZNAB_HOST = newznab_host
lazylibrarian.NEWZNAB_API = newznab_api
lazylibrarian.NEWZBIN = newzbin
lazylibrarian.NEWZBIN_UID = newzbin_uid
lazylibrarian.NEWZBIN_PASS = newzbin_pass
lazylibrarian.EBOOK_TYPE = ebook_type
lazylibrarian.GR_API = gr_api
lazylibrarian.config_write()
raise cherrypy.HTTPRedirect("config")
def default(self, *p, **params):
if len(p) == 0:
return """Error: Not enough URL parameters. Hostname needed"""
hostId, hostName = hosts.ensureHostIdAndUIShortname(p[0])
sprocName = None
if len(p) > 1:
sprocName = p[1]
if params.get('search'):
sprocName = params.get('sproc_search')
url = '/sprocs/show/' + hostName + '/' + sprocName
raise cherrypy.HTTPRedirect(cherrypy.url(url))
interval = {}
interval['from'] = params.get('from',(datetime.datetime.now() - datetime.timedelta(days=8)).strftime('%Y-%m-%d'))
interval['to'] = params.get('to',(datetime.datetime.now() + datetime.timedelta(days=1)).strftime('%Y-%m-%d'))
graphcalls= flotgraph.Graph("graphcalls")
graphcalls.addSeries('Number of calls', 'calls')
graphtime= flotgraph.TimeGraph("graphruntime")
graphtime.addSeries('Total run time', 'runtime')
graphavg= flotgraph.TimeGraph("graphavg")
graphavg.addSeries('Average run time', 'avg')
graphavgself= flotgraph.TimeGraph("graphselfavg")
graphavgself.addSeries('Average self time', 'avgself')
def _access_deny():
user = cherrypy.session.get('username')
if not user:
#Not logged in; that's probably why
login_url = '/auth/login'
if cherrypy.request.method == 'GET':
old_url = cherrypy.request.path_info
old_query = cherrypy.request.query_string
if old_query:
old_url += '?' + old_query
login_url += '?' + urlencode([ ('redirect', old_url) ])
raise cherrypy.HTTPRedirect(login_url)
else:
#Logged in..
raise cherrypy.HTTPRedirect('/auth/deny')
def check_auth(*args, **kwargs):
"""A tool that looks in config for 'auth.require'. If found and it
is not None, a login is required and the entry is evaluated as a list of
conditions that the user must fulfill"""
p = '%sauth/login' % htpc.WEBDIR
conditions = cherrypy.request.config.get('auth.require', None)
if conditions is not None:
username = cherrypy.session.get(SESSION_KEY)
if username:
cherrypy.request.login = username
for condition in conditions:
# A condition is just a callable that returns true or false
if not condition():
raise cherrypy.HTTPRedirect(p)
else:
raise cherrypy.HTTPRedirect(p)
def isUrlAuthorized(self, request):
if len(self.authObservers) == 0:
raise cherrypy.HTTPRedirect('/web/authFailed?reason=noAuthHandlersConfigured')
for observer in self.authObservers:
ret = observer.isUrlAuthorized(request)
if ret is True:
return True
request.setSession('returnTo', '%s?%s' % (
cherrypy.request.path_info,
cherrypy.request.query_string
))
raise cherrypy.HTTPRedirect('/web/login')
def do_login(self, login, password, redirect=b'/', **kwargs):
"""Login. May raise redirect, or return True if request handled."""
response = cherrypy.serving.response
try:
super(AuthFormTool, self).do_login(login, password, **kwargs)
except RdiffError as e:
body = LoginPage().index(redirect, login, str(e))
response.body = body
if "Content-Length" in response.headers:
# Delete Content-Length header so finalize() recalcs it.
del response.headers["Content-Length"]
return True
# Redirect user.
logger.debug('redirect user to %r', redirect or b"/")
raise cherrypy.HTTPRedirect(redirect or b"/")
def redirect(self, url):
raise cherrypy.HTTPRedirect(url)
def clearLogs(self):
headphones.LOG_LIST = []
logger.info("Web logs cleared")
raise cherrypy.HTTPRedirect("logs")