def get_completions(self, info): self.log.debug("get_completitons: info = %s" % info) token = info["help_obj"] matches = [] # from the language environment: slist = scheme.execute_string_rm("(dir)") if not scheme.exception_q(slist): for item in slist: item_str = str(item) if item_str.startswith(token) and item_str not in matches: matches.append(item_str) # special forms and constants: for item in [ "define", "define!", "func", "callback", "if", "help", "define-syntax", "begin", "lambda", "trace-lambda", "try", "catch", "finally", "raise", "choose" ]: if item.startswith(token) and item not in matches: matches.append(item) # add items from scheme.ENVIRONMENT for item in scheme.ENVIRONMENT: if item.startswith(token) and item not in matches: matches.append(item) # add properties and attributes if token is "numpy.ar" if "." in token: components, partial = token.rsplit(".", 1) slist = scheme.execute_string_rm("(dir %s)" % components) if not scheme.exception_q(slist): for item in slist: item_str = str(item) if item_str.startswith( partial) and item_str not in matches: matches.append(components + "." + item_str) # done with language-specific completitions return matches
def get_completions(self, info): self.log.debug("get_completitons: info = %s" % info) token = info["help_obj"] matches = [] # from the language environment: slist = scheme.execute_string_rm("(dir)") if not scheme.exception_q(slist): for item in slist: item_str = str(item) if item_str.startswith(token) and item_str not in matches: matches.append(item_str) # special forms and constants: for item in ["define", "define!", "func", "callback", "if", "help", "define-syntax", "begin", "lambda", "trace-lambda", "try", "catch", "finally", "raise", "choose"]: if item.startswith(token) and item not in matches: matches.append(item) # add items from scheme.ENVIRONMENT for item in scheme.ENVIRONMENT: if item.startswith(token) and item not in matches: matches.append(item) # add properties and attributes if token is "numpy.ar" if "." in token: components, partial = token.rsplit(".", 1) slist = scheme.execute_string_rm("(dir %s)" % components) if not scheme.exception_q(slist): for item in slist: item_str = str(item) if item_str.startswith(partial) and item_str not in matches: matches.append(components + "." + item_str) # done with language-specific completitions return matches
def get_kernel_help_on(self, info, level=0, none_on_fail=False): expr = info["code"] result = scheme.execute_string_rm("(help %s)" % expr) if not scheme.exception_q(result): return result elif expr in ["define", "define!", "func", "callback", "if", "help", "define-syntax", "begin", "lambda", "trace-lambda", "try", "catch", "finally", "raise", "choose"]: help_text = { "define": "(define NAME [DOCSTRING] VALUE) define a global variable (special form)", "define!": "(define! NAME [DOCSTRING] VALUE) define a variable in the host system (special form)", "func": "(func PROCEDURE) for wrapping Scheme procedures as a system function (special form)", "callback": "(callback PROCEDURE) returns a host system function for system callbacks (special form)", "if": "(if TEXT-EXPR TRUE-EXPR FALSE-EXPR) (special form)", "help": "(help ITEM) (special form)", "define-syntax": "(define-syntax NAME NAME-TEST ...) (special form)", "begin": "(begin EXPR...) (special form)", "lambda": "(lambda (VAR...) EXPR...) or (lambda VAR EXPR...) (special form)", "trace-lambda": "(trace-lambda NAME (VAR...) EXPR...) or (trace-lambda NAME VAR EXPR...) (special form)", "try": "(try EXPR (catch EXCEPTION NAME ...)...) (special form)", "catch": "(try EXPR (catch EXCEPTION NAME ...) ...) (special form)", "finally": "(try EXPR (catch EXCEPTION NAME ...)... (finally ...)) (special form)", "raise": "(raise EXCEPTION) (special form)", "choose": "Use (choose ITEM...) to setup non-deterministic interpreter, or use (choose) to go to next choice (special form)" } return help_text[expr] elif none_on_fail: return None else: return "No available help on '%s'" % expr
def do_execute_direct(self, code): try: retval = scheme.execute_string_top( code, "In [%s]" % self.execution_count) except: return "Unhandled Error: " + code if scheme.exception_q(retval): traceback = scheme.get_traceback_string(retval) ename, evalue = scheme.get_exception_values(retval) self.Error(traceback) self.kernel_resp.update({ "status": "error", 'ename': ename, # Exception name, as a string 'evalue': evalue, # Exception value, as a string 'traceback': [line + "\n" for line in traceback.split("\n") ], # traceback frames as strings }) retval = None if retval is scheme.void_value: retval = None elif scheme.end_of_session_q(retval): self.Print( "Use ^D to exit from console; use 'Shutdown Kernel' for other Jupyter frontends." ) retval = None return retval
def do_execute_file(self, filename): # for the %run FILENAME magic retval = scheme.execute_file_rm(filename) if scheme.exception_q(retval): traceback = scheme.get_traceback_string(retval) ename, evalue = scheme.get_exception_values(retval) self.Error(traceback) return None
def do_execute_direct(self, code): try: retval = scheme.execute_string_top(code, "In [%s]" % self.execution_count) except: return "Unhandled Error: " + code if scheme.exception_q(retval): self.Error(scheme.get_traceback_string(retval)) retval = None if retval is scheme.void_value: retval = None return retval
def do_execute_direct(self, code): try: retval = scheme.execute_string_top( code, "In [%s]" % self.execution_count) except: return "Unhandled Error: " + code if scheme.exception_q(retval): self.Error(scheme.get_traceback_string(retval)) retval = None if retval is scheme.void_value: retval = None return retval
def do_execute_direct(self, code): try: retval = scheme.execute_string_top(code, "In [%s]" % self.execution_count) except: return "Unhandled Error: " + code if scheme.exception_q(retval): traceback = scheme.get_traceback_string(retval) ename, evalue = scheme.get_exception_values(retval) self.Error(traceback) self.kernel_resp.update({ "status": "error", 'ename' : ename, # Exception name, as a string 'evalue' : evalue, # Exception value, as a string 'traceback' : [line + "\n" for line in traceback.split("\n")], # traceback frames as strings }) retval = None if retval is scheme.void_value: retval = None return retval
case_name = ''.join(replace(c) for c in case_name.lower()) group_name = str(group_name) count = get_count(group_name, case_name) test_name = 'test_%s_%s_%s' % (group_name, case_name, count) compare = """ Procedure: %s : %s : %s """ % (proc_exp, test_exp, result_exp) def test(self): self.assertTrue( result, "%s %s %s:\n%s%s" % (group_name, repr(case_name), count, traceback, compare)) setattr(TestScheme, test_name, test) ## Add dynamic tests: scheme.make_test_callback = callback retval = scheme.execute_file_rm(filename) if scheme.exception_q(retval): traceback = scheme.get_traceback_string(retval) ename, evalue = scheme.get_exception_values(retval) print(traceback) raise Exception(ename) if __name__ == "__main__": unittest.main()