def sos(self, line, cell=None): 'Magic execute sos expression and statements' # if in line mode, no command line if cell is None: if not self.options: return SoS_exec(line) else: return runfile(code=line, args=self.options) else: return runfile(code=cell, args=line.strip() + ' ' + self.options)
def sosset(self, line): 'Magic that set perminant options for sos and sospaste' # do not return __builtins__ beacuse it is too long... if line.strip(): print('sos options set to "{}"'.format(line.strip())) self.options = line.strip() + ' ' else: return runfile(script=None, code=None)
def sospaste(self, line): 'Magic that execute sos expression and statements from clipboard' # get and print clipboard content try: block = self.shell.hooks.clipboard_get() except ClipboardEmpty: raise UsageError("The clipboard appears to be empty") # print(block.strip()) print('## -- End pasted text --') try: # is it an expression? compile(block, '<string>', 'eval') return SoS_eval(block) except Exception: # is it a list of statement? try: compile(block, '<string>', 'exec') return SoS_exec(block) except Exception: return runfile(code=block, args=self.options + line.strip())