def runsource(self, source): ThreadedStream.push() prompt = self.prompt try: source_to_eval = ''.join(self.buffer + [source]) if code.InteractiveInterpreter.runsource(self, source_to_eval, '<debugger>', 'single'): self.prompt = '... ' self.buffer.append(source) else: self.prompt = '>>> ' del self.buffer[:] finally: source = source.encode('utf-8') return prompt + source + ThreadedStream.fetch()
def runsource(self, source): if isinstance(source, six.text_type): source = source.encode('utf-8') 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: return prompt + source + ThreadedStream.fetch()
def runsource(self, source): if isinstance(source, unicode): source = source.encode('utf-8') 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: return prompt + source + ThreadedStream.fetch()
def __call__(self, environ, start_response): # exec code in open tracebacks or provide shared data if environ.get('PATH_INFO', '').strip('/').endswith('__traceback__'): parameters = url_decode(environ.get('QUERY_STRING', '')) # shared data if 'resource' in parameters and 'mimetype' in parameters: data = load_resource(parameters['resource']) start_response('200 OK', [('Content-Type', str(parameters['mimetype'])), ('Content-Length', str(len(data)))]) yield data return # pastebin elif parameters.get('pastetb'): try: from xmlrpc.client import ServerProxy except: from xmlrpclib import ServerProxy try: length = int(environ['CONTENT_LENGTH']) except (KeyError, ValueError): length = 0 data = environ['wsgi.input'].read(length) s = ServerProxy('http://paste.pocoo.org/xmlrpc/') paste_id = s.pastes.newPaste('pytb', data) start_response('200 OK', [('Content-Type', 'text/plain')]) yield '{"paste_id": %d, "url": "%s"}' % ( paste_id, 'http://paste.pocoo.org/show/%d' % paste_id) return # execute commands in an existing debug context elif self.evalex: try: tb = self.tracebacks[parameters['tb']] frame = parameters['frame'] context = tb[frame] code = parameters['code'] except (IndexError, KeyError): pass else: result = context.exec_expr(code) start_response('200 OK', [('Content-Type', 'text/plain')]) yield result return # wrap the application and catch errors. appiter = None try: appiter = self.application(environ, start_response) for line in appiter: yield line except system_exceptions as e: raise e except: if self.evalex: ThreadedStream.install() exc_info = sys.exc_info() try: headers = [('Content-Type', 'text/html; charset=utf-8')] start_response('500 INTERNAL SERVER ERROR', headers) except: pass debug_context = self.create_debug_context(environ, exc_info) yield debug_page(debug_context).encode('utf8') if hasattr(appiter, 'close'): appiter.close()
result = context.exec_expr(code) start_response('200 OK', [('Content-Type', 'text/plain')]) yield result return # wrap the application and catch errors. appiter = None try: appiter = self.application(environ, start_response) for line in appiter: yield line except system_exceptions, e: raise e except: if self.evalex: ThreadedStream.install() exc_info = sys.exc_info() try: headers = [('Content-Type', 'text/html; charset=utf-8')] start_response('500 INTERNAL SERVER ERROR', headers) except: pass debug_context = self.create_debug_context(environ, exc_info) yield debug_page(debug_context) if hasattr(appiter, 'close'): appiter.close() def format_exception(self, exc_info): """Format a text/plain traceback.""" return self.create_debug_context({
else: result = context.exec_expr(code) start_response('200 OK', [('Content-Type', 'text/plain')]) yield result return # wrap the application and catch errors. appiter = None try: appiter = self.application(environ, start_response) for line in appiter: yield line except system_exceptions, e: raise e except: ThreadedStream.install() exc_info = sys.exc_info() try: headers = [('Content-Type', 'text/html; charset=utf-8')] start_response('500 INTERNAL SERVER ERROR', headers) except: pass debug_context = self.create_debug_context(environ, exc_info) yield debug_page(debug_context) if hasattr(appiter, 'close'): appiter.close() def format_exception(self, exc_info): """Format a text/plain traceback.""" return self.create_debug_context({}, exc_info, True).plaintb