Exemplo n.º 1
0
 def test_decimal_places(self):
     cases = [(0, '0'), (-1, '-1'), (0.012, '0.01'), (0.016, '0.02')
             , (ufloat(0,0), r'$0.0 \pm 0.0$'), (ufloat(10,0), r'$10.0 \pm 0.0$')
             , (ufloat(0.12, 0.012), r'$0.12 \pm 0.01$'), (ufloat(0.12, 0.016), r'$0.12 \pm 0.02$')
             , (ufloat(-0.12, 0.016), r'$-0.12 \pm 0.02$')]
     for test_case, result in cases:
         self.assertEqual(display_num(test_case, decimal_places=2), result)
Exemplo n.º 2
0
 def test_ufloat(self):
     cases = [(ufloat(0,0), r'$0.0 \pm 0.0$'), (ufloat(10,0), r'$10.0 \pm 0.0$')
             , (ufloat(10.0,0.1), r'$10.0 \pm 0.1$')
             , (ufloat(100.0,0.1), r'$100 \pm 0$')
             , (ufloat(1.0,1.5e-10), r'$1.0 \pm 0.0$')
             , (ufloat(10.0,0.01), r'$10.0 \pm 0.0$')]
     for test_case, result in cases:
         self.assertEqual(display_num(test_case), result)
Exemplo n.º 3
0
 def test_small(self):
     cases = [(0,'0'),(-1,'-1'),(1,'1'), (137.0, '137'), (1234, r'1\,230'),
     	(10010101, r'10\,000\,000'), (12.3, '12.3'), (-12.3, '-12.3')]
     for test_case, result in cases:
         self.assertEqual(display_num(test_case), result)
Exemplo n.º 4
0
def by_pages(vulndict, by):
    bypagestring = '\n[Back to all vulnerabilities](all)\n\n'  # Can't be the empty string or empty pages will cause errors
    for key, vulns in list(vulndict.items()):
        bypagestring += "##[{key}](by/{by}/{key})\n\n".format(key=key, by=by)
        vstring = "[Back to all {by}s](by/{by})\n\n#{key}\n\n".format(key=key, by=by)
        if 'manufacturer' == by and key != 'all':
            preamblestring = '\n{key} is affected by [vulnerabilities that affect all Android manufacturers](by/manufacturer/all) in addition to those listed below.\n'.format(key=key)
            if key in manufacturer_scores:
                preamblestring += '\n{key} has a [FUM score](/) of {score}.\n'.format(key=key,score=display_num(manufacturer_scores[key]))
            bypagestring += preamblestring
            vstring +=  preamblestring
        num_vulns = len(vulns)
        for vuln in vulns:
            vulnstring = str(vuln) + '\n'
            vstring += vulnstring
            if num_vulns < max_vulns_per_key:
                bypagestring += vulnstring
            else:
                bypagestring += '* [{name}](/vulnerabilities/{urlname})\n'.format(name=vuln.name, urlname=vuln.urlname)
        p = Page("by/{by}/{key}.md".format(
            key=key, by=by), virtual=vstring, title=key)
        pages.append(p)
    p = Page("by/{by}/index.md".format(by=by),
             virtual=bypagestring, title="By {by}".format(by=by))
    pages.append(p)
Exemplo n.º 5
0
def score_table(files, remove):
    scores = OrderedDict()
    for filename in files:
        if not os.path.isfile(filename):
            continue
        with open(filename) as csvfile:
            csvreader = csv.reader(csvfile)
            for row in csvreader:
                try:
                    key = row[0]
                    if not key in remove:
                        scores[key] = float(row[7])
                except ValueError:
                    pass # Ignore headers
    table = '<table class="five" ><tbody>\n'
    annotation = ''
    for index, (key, value) in enumerate(scores.items()):
        if index == 0:
            annotation = '(best)'
        elif index == len(scores) - 1:
            annotation = '(worst)'
        else:
            annotation = ''
        table += '<tr><td style="padding-right:4px;">{key}</td>  <td>{value}&nbsp;<i>{annotation}</i></td></tr>\n'.format(key=link_manufacturer(key).replace(' ', '&nbsp;'), value=display_num(value), annotation=annotation)
    table += '</tbody></table>\n'
    return table