77from __future__ import print_function
88__docformat__ = 'restructuredtext'
99
10- import sys , os , keyword , linecache , tokenize , inspect , cgi
10+ import sys , os , keyword , linecache , tokenize , inspect
1111import pydoc , traceback
1212
1313from roundup .anypy .html import html_escape
1414
15- from roundup .cgi import templating , TranslationService
15+ from roundup .cgi import TranslationService
1616from roundup .anypy .strings import s2b
1717
18+
1819def get_translator (i18n = None ):
1920 """Return message translation function (gettext)
2021
@@ -30,31 +31,34 @@ def get_translator(i18n=None):
3031 """
3132 try :
3233 return i18n .gettext
33- except :
34+ except AttributeError :
3435 return TranslationService .get_translation ().gettext
3536
37+
3638def breaker ():
3739 return ('<body bgcolor="white">' +
3840 '<font color="white" size="-5"> > </font> ' +
3941 '</table>' * 5 )
4042
43+
4144def niceDict (indent , dict ):
4245 l = []
4346 for k in sorted (dict ):
4447 v = dict [k ]
45- l .append ('<tr><td><strong>%s</strong></td><td>%s</td></tr>' % (k ,
48+ l .append ('<tr><td><strong>%s</strong></td><td>%s</td></tr>' % (k ,
4649 html_escape (repr (v ))))
4750 return '\n ' .join (l )
4851
52+
4953def pt_html (context = 5 , i18n = None ):
5054 _ = get_translator (i18n )
5155 esc = html_escape
5256 exc_info = [esc (str (value )) for value in sys .exc_info ()[:2 ]]
5357 l = [_ ('<h1>Templating Error</h1>\n '
54- '<p><b>%(exc_type)s</b>: %(exc_value)s</p>\n '
55- '<p class="help">Debugging information follows</p>'
56- ) % {'exc_type' : exc_info [0 ], 'exc_value' : exc_info [1 ]},
57- '<ol>' ,]
58+ '<p><b>%(exc_type)s</b>: %(exc_value)s</p>\n '
59+ '<p class="help">Debugging information follows</p>'
60+ ) % {'exc_type' : exc_info [0 ], 'exc_value' : exc_info [1 ]},
61+ '<ol>' , ]
5862 from roundup .cgi .PageTemplates .Expressions import TraversalError
5963 t = inspect .trace (context )
6064 t .reverse ()
@@ -66,11 +70,11 @@ def pt_html(context=5, i18n=None):
6670 s = []
6771 for name , info in ti .path :
6872 s .append (_ ('<li>"%(name)s" (%(info)s)</li>' )
69- % {'name' : name , 'info' : esc (repr (info ))})
73+ % {'name' : name , 'info' : esc (repr (info ))})
7074 s = '\n ' .join (s )
7175 l .append (_ ('<li>Looking for "%(name)s", '
72- 'current path:<ol>%(path)s</ol></li>'
73- ) % {'name' : ti .name , 'path' : s })
76+ 'current path:<ol>%(path)s</ol></li>'
77+ ) % {'name' : ti .name , 'path' : s })
7478 else :
7579 l .append (_ ('<li>In %s</li>' ) % esc (str (ti )))
7680 if '__traceback_supplement__' in locals :
@@ -82,7 +86,7 @@ def pt_html(context=5, i18n=None):
8286 if context ._v_errors :
8387 s = s + '<br>' + '<br>' .join (
8488 [esc (x ) for x in context ._v_errors ])
85- l .append ('<li>%s</li>' % s )
89+ l .append ('<li>%s</li>' % s )
8690 elif len (ts ) == 3 :
8791 supp , context , info = ts
8892 l .append (_ ('''
@@ -110,6 +114,7 @@ def pt_html(context=5, i18n=None):
110114 l .append ('<p> </p>' )
111115 return '\n ' .join (l )
112116
117+
113118def html (context = 5 , i18n = None ):
114119 _ = get_translator (i18n )
115120 etype , evalue = sys .exc_info ()[0 ], sys .exc_info ()[1 ]
@@ -122,26 +127,27 @@ def html(context=5, i18n=None):
122127 '#ffffff' , '#777777' , pyver )
123128
124129 head = head + (_ ('<p>A problem occurred while running a Python script. '
125- 'Here is the sequence of function calls leading up to '
126- 'the error, with the most recent (innermost) call first. '
127- 'The exception attributes are:' ))
130+ 'Here is the sequence of function calls leading up to '
131+ 'the error, with the most recent (innermost) call first. '
132+ 'The exception attributes are:' ))
128133
129134 indent = '<tt><small>%s</small> </tt>' % (' ' * 5 )
130135 traceback = []
131136 for frame , file , lnum , func , lines , index in inspect .trace (context ):
132137 if file is None :
133138 link = _ ("<file is None - probably inside <tt>eval</tt> "
134- "or <tt>exec</tt>>" )
139+ "or <tt>exec</tt>>" )
135140 else :
136141 file = os .path .abspath (file )
137142 link = '<a href="file:%s">%s</a>' % (file , pydoc .html .escape (file ))
138143 args , varargs , varkw , locals = inspect .getargvalues (frame )
139144 if func == '?' :
140145 call = ''
141146 else :
142- call = _ ('in <strong>%s</strong>' ) % func + inspect .formatargvalues (
143- args , varargs , varkw , locals ,
144- formatvalue = lambda value : '=' + pydoc .html .repr (value ))
147+ call = _ ('in <strong>%s</strong>' ) % \
148+ func + inspect .formatargvalues (
149+ args , varargs , varkw , locals ,
150+ formatvalue = lambda value : '=' + pydoc .html .repr (value ))
145151
146152 level = '''
147153<table width="100%%" bgcolor="#dddddd" cellspacing=0 cellpadding=2 border=0>
@@ -153,11 +159,13 @@ def html(context=5, i18n=None):
153159
154160 # do a file inspection
155161 names = []
162+
156163 def tokeneater (type , token , start , end , line , names = names ):
157164 if type == tokenize .NAME and token not in keyword .kwlist :
158165 if token not in names :
159166 names .append (token )
160167 if type == tokenize .NEWLINE : raise IndexError
168+
161169 def linereader (file = file , lnum = [lnum ]):
162170 line = s2b (linecache .getline (file , lnum [0 ]))
163171 lnum [0 ] = lnum [0 ] + 1
@@ -192,11 +200,11 @@ def linereader(file=file, lnum=[lnum]):
192200 else :
193201 value = _ ('<em>undefined</em>' )
194202 name = '<em>global</em> <strong>%s</strong>' % name
195- lvals .append ('%s = %s' % (name , value ))
203+ lvals .append ('%s = %s' % (name , value ))
196204 if lvals :
197205 lvals = ', ' .join (lvals )
198206 lvals = indent + '<small><font color="#909090">%s' \
199- '</font></small><br>' % lvals
207+ '</font></small><br>' % lvals
200208 else :
201209 lvals = ''
202210
@@ -226,6 +234,7 @@ def linereader(file=file, lnum=[lnum]):
226234
227235 return head + ' ' .join (attribs ) + ' ' .join (traceback ) + '<p> </p>'
228236
237+
229238def handler ():
230239 print (breaker ())
231240 print (html ())
0 commit comments