Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def init_logging(self):
""" Setup logging so that messages are proxied to Python.
"""
if window.console.ori_log:
return # already initialized the loggers
# Keep originals
window.console.ori_log = window.console.log
window.console.ori_info = window.console.info or window.console.log
window.console.ori_warn = window.console.warn or window.console.log
window.console.ori_error = window.console.error or window.console.log
def log(msg):
window.console.ori_log(msg)
for session in self.sessions.values():
session.send_command("PRINT", str(msg))
def info(msg):
window.console.ori_info(msg)
for session in self.sessions.values():
session.send_command("INFO", str(msg))
def warn(msg):
window.console.ori_warn(msg)
for session in self.sessions.values():
session.send_command("WARN", str(msg))
def error(msg):
evt = dict(message=str(msg), error=msg, preventDefault=lambda: None)
def init_logging(self):
""" Setup logging so that messages are proxied to Python.
"""
if window.console.ori_log:
return # already initialized the loggers
# Keep originals
window.console.ori_log = window.console.log
window.console.ori_info = window.console.info or window.console.log
window.console.ori_warn = window.console.warn or window.console.log
window.console.ori_error = window.console.error or window.console.log
def log(msg):
window.console.ori_log(msg)
for session in self.sessions.values():
session.send_command("PRINT", str(msg))
def info(msg):
window.console.ori_info(msg)
for session in self.sessions.values():
session.send_command("INFO", str(msg))
def warn(msg):
window.console.ori_warn(msg)
for session in self.sessions.values():
session.send_command("WARN", str(msg))
def error(msg):
evt = dict(message=str(msg), error=msg, preventDefault=lambda: None)
on_error(evt)
def info(msg):
window.console.ori_info(msg)
for session in self.sessions.values():
session.send_command("INFO", str(msg))
def warn(msg):
for x in ['_process_actions', '_process_reactions', '_process_calls']:
if ('Loop.' + x) in stack[i]:
stack = stack[:i]
break
# Pop items from in between
for i in reversed(range(len(stack))):
for x in ['flx_action ']:
if stack[i] and stack[i].count(x):
stack.pop(i)
# Combine and tweak the message some more
msg += '\n' + '\n'.join(stack)
elif evt.message and evt.lineno: # message, url, linenumber
msg += "\nIn %s:%i" % (evt.filename, evt.lineno)
# Handle error
evt.preventDefault() # Don't do the standard error
window.console.ori_error(msg)
for session in self.sessions.values():
session.send_command("ERROR", short_msg)
def _receive_command(self, command):
""" Process a command send from the server.
"""
cmd = command[0]
if cmd == 'PING':
# Used for roundtrip stuff, do at least one iter loop here ...
window.setTimeout(self.send_command, 10, 'PONG', command[1])
elif cmd == 'INIT_DONE':
window.flexx.spin(None)
while len(self._pending_commands):
self._receive_raw_command(self._pending_commands.pop(0))
self._pending_commands = None
# print('init took', time() - self._init_time)
elif cmd == 'PRINT':
(window.console.ori_log or window.console.log)(command[1])
elif cmd == 'EXEC':
eval(command[1])
elif cmd == 'EVAL':
x = None
if len(command) == 2:
x = eval(command[1])
elif len(command) == 3:
x = eval('this.instances.' + command[1] + '.' + command[2])
console.log(str(x)) # print (and thus also sends back result)
elif cmd == 'EVALANDRETURN':
try:
x = eval(command[1])
except Exception as err:
x = str(err)
eval_id = command[2] # to identify the result in Python
self.send_command("EVALRESULT", x, eval_id)
def warn(msg):
window.console.ori_warn(msg)
for session in self.sessions.values():
session.send_command("WARN", str(msg))
def error(msg):