mirror of
				https://github.com/python/cpython.git
				synced 2025-10-30 21:21:22 +00:00 
			
		
		
		
	Added print_exception() convenience function.
This commit is contained in:
		
							parent
							
								
									6ba66d0116
								
							
						
					
					
						commit
						f85de8a440
					
				
					 1 changed files with 21 additions and 3 deletions
				
			
		
							
								
								
									
										24
									
								
								Lib/cgi.py
									
										
									
									
									
								
							
							
						
						
									
										24
									
								
								Lib/cgi.py
									
										
									
									
									
								
							|  | @ -397,7 +397,7 @@ | ||||||
| 
 | 
 | ||||||
| """ | """ | ||||||
| 
 | 
 | ||||||
| __version__ = "2.0b2" | __version__ = "2.0b3" | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| # Imports | # Imports | ||||||
|  | @ -1089,9 +1089,27 @@ def test(environ=os.environ): | ||||||
| 	print_directory() | 	print_directory() | ||||||
| 	print_arguments() | 	print_arguments() | ||||||
| 	print_environ_usage() | 	print_environ_usage() | ||||||
|  | 	def f(): | ||||||
|  | 	    exec "testing print_exception() -- <I>italics?</I>" | ||||||
|  | 	def g(f=f): | ||||||
|  | 	    f() | ||||||
|  | 	print "<H3>What follows is a test, not an actual exception:</H3>" | ||||||
|  | 	g() | ||||||
|     except: |     except: | ||||||
| 	print "\n\n<PRE>"	# Turn off HTML word wrap | 	print_exception() | ||||||
| 	traceback.print_exc() | 
 | ||||||
|  | def print_exception(type=None, value=None, tb=None, limit=None): | ||||||
|  |     if type is None: | ||||||
|  | 	type, value, tb = sys.exc_type, sys.exc_value, sys.exc_traceback | ||||||
|  |     import traceback | ||||||
|  |     print | ||||||
|  |     print "<H3>Traceback (innermost last):</H3>" | ||||||
|  |     list = traceback.format_tb(tb, limit) + \ | ||||||
|  | 	   traceback.format_exception_only(type, value) | ||||||
|  |     print "<PRE>%s<B>%s</B></PRE>" % ( | ||||||
|  | 	escape(string.join(list[:-1], "")), | ||||||
|  | 	escape(list[-1]), | ||||||
|  | 	) | ||||||
| 
 | 
 | ||||||
| def print_environ(environ=os.environ): | def print_environ(environ=os.environ): | ||||||
|     """Dump the shell environment as HTML.""" |     """Dump the shell environment as HTML.""" | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Guido van Rossum
						Guido van Rossum