3030from . import capi
3131
3232from lxml .html import (
33- tostring , fragment_fromstring as parse , builder as E
33+ tostring , fragment_fromstring as parse , builder as E
3434)
3535
3636from pygments import highlight
4141from itertools import islice
4242
4343
44- def open (filename , mode = 'r' ):
44+ def open (filename , mode = 'r' ): # pylint:disable=redefined-builtin
4545 """All files are treated as UTF-8, unless explicitly binary."""
46- from io import open
46+ import io
4747 if 'b' in mode :
48- return open (filename , mode )
48+ return io . open (filename , mode )
4949 else :
50- return open (filename , mode , encoding = 'UTF-8' )
50+ return io . open (filename , mode , encoding = 'UTF-8' )
5151
5252
5353class HtmlPage (object ):
@@ -106,12 +106,12 @@ def code(self):
106106 """generate the contents of the #code section"""
107107 # Get ready to use Pygments:
108108 formatter = CodeHtmlFormatter (
109- style = 'default' ,
110- cssclass = 'source' ,
111- linenostart = self .data ['function' ]['lines' ][0 ],
109+ style = 'default' ,
110+ cssclass = 'source' ,
111+ linenostart = self .data ['function' ]['lines' ][0 ],
112112 )
113113
114- #<link rel="stylesheet", href="pygments_c.css", type="text/css">
114+ # <link rel="stylesheet", href="pygments_c.css", type="text/css">
115115 open ('pygments_c.css' , 'w' ).write (formatter .get_style_defs ())
116116
117117 # Use pygments to convert it all to HTML:
@@ -127,7 +127,6 @@ def code(self):
127127
128128 return code
129129
130-
131130 def header (self ):
132131 """Make the header bar of the webpage"""
133132
@@ -183,7 +182,7 @@ def header(self):
183182 ),
184183 ),
185184 ),
186- )
185+ )
187186
188187 def states (self ):
189188 """Return an ordered-list of states, for each report."""
@@ -213,7 +212,7 @@ def states(self):
213212
214213 for note in report ['notes' ]:
215214 line = note ['location' ][0 ]['line' ]
216- note = E .P ({'class' :'note' }, note ['message' ])
215+ note = E .P ({'class' : 'note' }, note ['message' ])
217216
218217 # Put this note on the last matching state, if possible
219218 for ann in reversed (tuple (annotations )):
@@ -223,13 +222,11 @@ def states(self):
223222 break
224223 elif line > annline :
225224 ann .addnext (
226- E .LI ({'data-line' : str (line )}, note )
225+ E .LI ({'data-line' : str (line )}, note )
227226 )
228227 break
229228 else :
230- annotations .insert (0 ,
231- E .LI ({'data-line' : str (line )}, note )
232- )
229+ annotations .insert (0 , E .LI ({'data-line' : str (line )}, note ))
233230
234231 yield annotations , report ['message' ]
235232
@@ -240,38 +237,40 @@ def body(self):
240237
241238 for i , (state_html , state_problem ) in enumerate (self .states (), 1 ):
242239 reports .append (
243- E .LI (
244- E .ATTR (id = "state{0}" .format (i )),
245- E .DIV (
246- E .CLASS ('source' ),
247- E .E .header (
248- E .DIV (
249- E .CLASS ('error' ),
250- state_problem ,
251- ),
252- E .DIV (
253- E .CLASS ('report-count' ),
254- E .H3 ('Report' ),
255- str (i ),
256- ),
240+ E .LI (
241+ E .ATTR (id = "state{0}" .format (i )),
242+ E .DIV (
243+ E .CLASS ('source' ),
244+ E .E .header (
245+ E .DIV (
246+ E .CLASS ('error' ),
247+ state_problem ,
248+ ),
249+ E .DIV (
250+ E .CLASS ('report-count' ),
251+ E .H3 ('Report' ),
252+ str (i ),
257253 ),
258- deepcopy (code ),
259254 ),
260- state_html ,
255+ deepcopy ( code ) ,
261256 ),
257+ state_html ,
258+ ),
262259 )
263260
264261 return E .BODY (
265262 self .header (),
266263 reports ,
267264 )
268265
266+
269267def data_uri (mimetype , filename ):
270268 """represent a file as a data uri"""
271269 data = open (join (HERE , filename ), 'rb' ).read ()
272270 data = data .encode ('base64' ).replace ('\n ' , '' )
273271 return 'data:%s;base64,%s' % (mimetype , data )
274272
273+
275274def file_contents (filename ):
276275 """Add a leading newline to make the first line show up in the right spot.
277276 """
@@ -283,7 +282,7 @@ class CodeHtmlFormatter(HtmlFormatter):
283282
284283 def wrap (self , source , outfile ):
285284 yield 0 , '<table data-first-line="%s">' % (
286- self .linenostart ,
285+ self .linenostart ,
287286 )
288287 for i , line in source :
289288 if i == 1 :
@@ -295,6 +294,7 @@ def wrap(self, source, outfile):
295294 yield i , line
296295 yield 0 , '</table>'
297296
297+
298298def main (argv ):
299299 """our entry point"""
300300 if len (argv ) < 3 :
0 commit comments