我们从Python开源项目中,提取了以下50个代码示例,用于说明如何使用code.InteractiveInterpreter()。
def runsource(self, source): source = source.rstrip() + '\n' ThreadedStream.push() prompt = self.more and '... ' or '>>> ' try: source_to_eval = ''.join(self.buffer + [source]) if code.InteractiveInterpreter.runsource(self, source_to_eval, '<debugger>', 'single'): self.more = True self.buffer.append(source) else: self.more = False del self.buffer[:] finally: output = ThreadedStream.fetch() return prompt + source + output
def runsource(self, source): source = source.rstrip() + '\n' ThreadedStream.push() prompt = self.more and '... ' or '>>> ' try: source_to_eval = ''.join(self.buffer + [source]) if code.InteractiveInterpreter.runsource(self, source_to_eval, '<debugger>', 'single'): self.more = True self.buffer.append(source) else: self.more = False del self.buffer[:] finally: output = ThreadedStream.fetch() return prompt + escape(source) + output
def initInterpreter(self, interpreterLocals=None): if interpreterLocals: # when we pass in locals, we don't want it to be named "self" # so we rename it with the name of the class that did the passing # and reinsert the locals back into the interpreter dictionary # maybe this still works when run outside maya try: selfName = interpreterLocals['self'].__class__.__name__ interpreterLocalVars = interpreterLocals.pop('self') self.interpreterLocals[selfName] = interpreterLocalVars except: pass self.interpreterLocals = interpreterLocals else: self.interpreterLocals = interpreterLocals self.interpreter = self.InteractiveInterpreter(self.interpreterLocals)
def _core_loadlib(self, request, response): data_tlv = packet_get_tlv(request, TLV_TYPE_DATA) if (data_tlv['type'] & TLV_META_TYPE_COMPRESSED) == TLV_META_TYPE_COMPRESSED: return ERROR_FAILURE self.last_registered_extension = None symbols_for_extensions = {'meterpreter': self} symbols_for_extensions.update(EXPORTED_SYMBOLS) i = code.InteractiveInterpreter(symbols_for_extensions) i.runcode(compile(data_tlv['value'], '', 'exec')) extension_name = self.last_registered_extension if extension_name: check_extension = lambda x: x.startswith(extension_name) lib_methods = list(filter(check_extension, list(self.extension_functions.keys()))) for method in lib_methods: response += tlv_pack(TLV_TYPE_METHOD, method) return ERROR_SUCCESS, response