Thu, 15 Jan 2015 15:59:08 +0100
Implement a real Private Browsing Mode condition by changing the API/ABI;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.
michael@0 | 1 | # This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 2 | # License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 3 | # file, You can obtain one at http://mozilla.org/MPL/2.0/. |
michael@0 | 4 | |
michael@0 | 5 | """Store the results. |
michael@0 | 6 | |
michael@0 | 7 | Use a db, but we could do better""" |
michael@0 | 8 | |
michael@0 | 9 | import shelve |
michael@0 | 10 | import string |
michael@0 | 11 | |
michael@0 | 12 | class results: |
michael@0 | 13 | def __init__(self, id): |
michael@0 | 14 | self.id = id |
michael@0 | 15 | self.d = shelve.open("data/"+id+".db") |
michael@0 | 16 | |
michael@0 | 17 | def get_tester(self, path): |
michael@0 | 18 | import BaseTest |
michael@0 | 19 | |
michael@0 | 20 | try: |
michael@0 | 21 | fname = path+"tester.py" |
michael@0 | 22 | text = open(fname).read() |
michael@0 | 23 | # Thanks to markh, for showing me how to do this |
michael@0 | 24 | # Python Is Cool. |
michael@0 | 25 | codeob = compile(text, fname, "exec") |
michael@0 | 26 | namespace = { 'BaseTester': BaseTest.tester } |
michael@0 | 27 | exec codeob in namespace, namespace |
michael@0 | 28 | tester = namespace['tester']() |
michael@0 | 29 | except IOError: |
michael@0 | 30 | tester = BaseTest.tester() |
michael@0 | 31 | |
michael@0 | 32 | if self.d.has_key(path): |
michael@0 | 33 | tester.__dict__ = self.d[path] |
michael@0 | 34 | else: |
michael@0 | 35 | tester.parse_config(open(path+"config")) |
michael@0 | 36 | |
michael@0 | 37 | return tester |
michael@0 | 38 | |
michael@0 | 39 | def set_tester(self, path, test): |
michael@0 | 40 | self.d[path] = test.__dict__ |
michael@0 | 41 | |
michael@0 | 42 | def write_report(self, file): |
michael@0 | 43 | for i in self.d.keys(): |
michael@0 | 44 | file.write("%s: " % (i)) |
michael@0 | 45 | tester = self.get_tester(i) |
michael@0 | 46 | res, detail = tester.result() |
michael@0 | 47 | if res: |
michael@0 | 48 | file.write("Pass!\n") |
michael@0 | 49 | else: |
michael@0 | 50 | file.write("Fail: %s\n" % (detail)) |
michael@0 | 51 | |
michael@0 | 52 | def __del__(self): |
michael@0 | 53 | self.d.close() |