comparison blast2html.py @ 74:03e044b5bcc2 py2.6

fix escaping of javascript literals
author Jan Kanis <jan.code@jankanis.nl>
date Wed, 18 Jun 2014 16:58:25 +0200
parents 67b1a319c6dc
children 4d2c25baf5a3
comparison
equal deleted inserted replaced
73:67b1a319c6dc 74:03e044b5bcc2
171 171
172 172
173 # javascript escape filter based on Django's, from https://github.com/dsissitka/khan-website/blob/master/templatefilters.py#L112-139 173 # javascript escape filter based on Django's, from https://github.com/dsissitka/khan-website/blob/master/templatefilters.py#L112-139
174 # I've removed the html escapes, since html escaping is already being performed by the template engine. 174 # I've removed the html escapes, since html escaping is already being performed by the template engine.
175 175
176 # The r'\u0027' syntax doesn't work the way we need to in python 2.6 with unicode_literals
176 _base_js_escapes = ( 177 _base_js_escapes = (
177 ('\\', r'\u005C'), 178 ('\\', '\\u005C'),
178 ('\'', r'\u0027'), 179 ('\'', '\\u0027'),
179 ('"', r'\u0022'), 180 ('"', '\\u0022'),
180 # ('>', r'\u003E'), 181 # ('>', '\\u003E'),
181 # ('<', r'\u003C'), 182 # ('<', '\\u003C'),
182 # ('&', r'\u0026'), 183 # ('&', '\\u0026'),
183 # ('=', r'\u003D'), 184 # ('=', '\\u003D'),
184 # ('-', r'\u002D'), 185 # ('-', '\\u002D'),
185 # (';', r'\u003B'), 186 # (';', '\\u003B'),
186 # (u'\u2028', r'\u2028'), 187 (u'\u2028', '\\u2028'),
187 # (u'\u2029', r'\u2029') 188 (u'\u2029', '\\u2029')
188 ) 189 )
189 190
190 # Escape every ASCII character with a value less than 32. This is 191 # Escape every ASCII character with a value less than 32. This is
191 # needed a.o. to prevent html parsers from jumping out of javascript 192 # needed a.o. to prevent html parsers from jumping out of javascript
192 # parsing mode. 193 # parsing mode.
335 ident = "{0:.0%}".format(float(min(hsp.Hsp_identity / blastxml_len(hsp) for hsp in hsps))), 336 ident = "{0:.0%}".format(float(min(hsp.Hsp_identity / blastxml_len(hsp) for hsp in hsps))),
336 accession = hit.Hit_accession) 337 accession = hit.Hit_accession)
337 338
338 339
339 def main(): 340 def main():
340 #import pdb; pdb.set_trace()
341 default_template = path.join(path.dirname(__file__), 'blast2html.html.jinja') 341 default_template = path.join(path.dirname(__file__), 'blast2html.html.jinja')
342 342
343 parser = argparse.ArgumentParser(description="Convert a BLAST XML result into a nicely readable html page", 343 parser = argparse.ArgumentParser(description="Convert a BLAST XML result into a nicely readable html page",
344 usage="{0} [-i] INPUT [-o OUTPUT]".format(sys.argv[0])) 344 usage="{0} [-i] INPUT [-o OUTPUT]".format(sys.argv[0]))
345 input_group = parser.add_mutually_exclusive_group(required=True) 345 input_group = parser.add_mutually_exclusive_group(required=True)