Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
# forever
while not self._stop_event.is_set():
# read line from Node's stdout
line = self.ps.stdout.readline()
# see if it parses as JSON
obj = None
try:
if line:
obj = json.loads(line)
# if it does and is a pixiedust object
if obj and isinstance(obj, dict) and obj['_pixiedust']:
if obj['type'] == 'display':
pdf = pandas.DataFrame(obj['data'])
ShellAccess.pdf = pdf
display(pdf)
elif obj['type'] == 'print':
print(json.dumps(obj['data']))
elif obj['type'] == 'store':
print('!!! Warning: store is now deprecated - Node.js global variables are automatically propagated to Python !!!')
variable = 'pdf'
if 'variable' in obj:
variable = obj['variable']
ShellAccess[variable] = pandas.DataFrame(obj['data'])
elif obj['type'] == 'html':
IPython.display.display(IPython.display.HTML(obj['data']))
elif obj['type'] == 'image':
IPython.display.display(IPython.display.HTML('<img src="{0}">'.format(obj['data'])))
elif obj['type'] == 'variable':
ShellAccess[obj['key']] = obj['value']
if self.vw:
self.vw.setCache(obj['key'], obj['value'])