Commits

Samuele Pedroni  committed a0f2470

tag revision known to work to run django

  • Participants
  • Parent commits b554e9d
  • Branches run-django

Comments (0)

Files changed (569)

File demo/sqlinj/populate.py

+# Populate the database for the SQL injection demo,
+# it creates a DBS directory in the current working dir.
+# Requires Gadfly on the python path, and a --allworkingmodules --oldstyle
+# pypy-c.
+# Passwords for the demo are just the reverse of user names.
+
+import md5
+import sys, os
+import random
+
+os.mkdir("DBS")
+
+import gadfly
+
+conn = gadfly.gadfly()
+conn.startup("db0", "DBS")
+
+names = ['bob', 'jamie', 'david', 'monica', 'rose', 'anna']
+
+def make_pwd(name):
+    rname = list(name)
+    rname.reverse()
+    rname = ''.join(rname)
+    return md5.new(rname).hexdigest()
+
+pwds = [make_pwd(name) for name in names]
+
+products = [('superglue', 10.0, 5),
+            ('pink wallpaper', 25.0, 20),
+            ('red wallpaper', 20.0, 20),
+            ('gray wallpaper', 15.0, 20),
+            ('white wallpaper', 15.0, 20),
+            ('green wallpaper', 20.0, 20) ]
+
+cursor = conn.cursor()
+cursor.execute("""create table purchases (pwd varchar, user varchar,
+                                          month integer, year integer,
+                                          product varchar,
+                                          qty integer,
+                                          amount float)
+               """)
+
+
+
+ins = "insert into purchases values (?,?,?,2007,?,?,?)"
+for i in range(15):
+    uid = random.randrange(0, len(names))
+    pwd = pwds[uid]
+    name = names[uid]
+    month = random.randrange(1, 13)
+    product, unitprice, maxqty = random.choice(products)
+    qty = random.randrange(1, maxqty)
+    data = (pwd, name, month, product, qty, qty*unitprice)
+    cursor.execute(ins, data)
+
+conn.commit()
+
+print "Done"

File demo/sqlinj/server.py

+"""SQL injection example
+
+   Needs gadfly (sf.net/projects/gadfly) to be on the python path.
+
+   Use populate.py to create the example db.
+
+   Passwords are the reverse of user names :).
+
+   Query is the number of a calendar month, purchases
+   for the user with the password since including that month
+   are shown.
+
+   Works with an --allworkingmodules --oldstyle pypy-c .
+"""
+
+import sys
+
+import gadfly
+
+import BaseHTTPServer
+import cgi
+import md5
+
+page="""
+<html>
+<head>
+<title>DEMO</title>
+</head>
+<body>
+<form method="get" action="/">
+<label for="pwd">Passwd</label>
+<input name="pwd" type="text" size="10"></input><br />
+<label for="query">Query</label>
+<input name="query" type="text" size="20"></input><br />
+<input type="submit">
+</form>
+
+<div>
+%s
+</div>
+</body>
+</html>
+"""
+
+table = """
+<table>
+<th>customer</th>
+<th>month</th>
+<th>year</th>
+<th>prod.</th>
+<th>qty</th>
+<th>amount</th>
+%s
+</table>
+"""
+
+row = "<tr>"+"<td>%s</td>"*6 +"</tr>"
+
+def do_query(query):
+    conn = gadfly.gadfly("db0", "DBS")
+    cursor = conn.cursor()
+    pwd = md5.new(query['pwd'][0]).hexdigest()
+    q = query['query'][0]
+
+    sel = ("""select user,month,year,product,qty,amount from purchases
+                      where pwd='%s' and month>=%s
+                   """ % (pwd, q))
+    cursor.execute(sel)
+    rows = []
+    for x in cursor.fetchall():
+        rows.append(row % x)
+    results = table % ('\n'.join(rows))
+    
+    conn.close()
+    return results
+    
+    
+
+class RequestHandler(BaseHTTPServer.BaseHTTPRequestHandler):
+    
+    def do_GET(self):
+        self.send_response(200, "OK")
+        self.end_headers()
+        parts = self.path.split('?')
+        if len(parts) > 1:
+            _, query = parts
+            query = cgi.parse_qs(query, strict_parsing=True)
+        else:
+            query = None
+
+        if query is not None:
+            results = do_query(query)
+        else:
+            results = "no query"
+
+        self.wfile.write(page % results)
+
+
+
+if __name__ == '__main__':
+    if len(sys.argv) > 1:
+        port = int(sys.argv[1])
+    else:
+        port = 8000
+    
+    server_address = ('', port)
+    httpd = BaseHTTPServer.HTTPServer(server_address, RequestHandler)
+    httpd.serve_forever()

File demo/sqlinj/tserver.py

+"""SQL injection example with holes fixed using the taint space.
+
+   Needs gadfly (sf.net/projects/gadfly) to be on the python path.
+
+   Use populate.py to create the example db.
+
+   Passwords are the reverse of user names :).
+
+   Query is the number of a calendar month, purchases
+   for the user with the password since including that month
+   are shown.
+
+   Works with a -otaint --allworkingmodules --oldstyle pypy-c .
+"""
+
+import sys
+import __pypy__
+
+import gadfly
+
+import BaseHTTPServer
+import cgi
+import md5
+
+page="""
+<html>
+<head>
+<title>DEMO</title>
+</head>
+<body>
+<form method="get" action="/">
+<label for="pwd">Passwd</label>
+<input name="pwd" type="text" size="10"></input><br />
+<label for="query">Query</label>
+<input name="query" type="text" size="20"></input><br />
+<input type="submit">
+</form>
+
+<div>
+%s
+</div>
+</body>
+</html>
+"""
+
+table = """
+<table>
+<th>customer</th>
+<th>month</th>
+<th>year</th>
+<th>prod.</th>
+<th>qty</th>
+<th>amount</th>
+%s
+</table>
+"""
+
+row = "<tr>"+"<td>%s</td>"*6 +"</tr>"
+
+def do_query(query):
+    conn = gadfly.gadfly("db0", "DBS")
+    cursor = conn.cursor()
+
+    pwd = pypymagic.untaint(str, query['pwd'][0])
+    pwd = md5.new(pwd).hexdigest()
+
+    q = pypymagic.untaint(str, query['query'][0])
+    if not q.isdigit():
+        return "Wrong query!"
+    
+    sel = ("""select user,month,year,product,qty,amount from purchases
+                      where pwd='%s' and month>=%s
+                   """ % (pwd, q))
+    cursor.execute(sel)
+    rows = []
+    for x in cursor.fetchall():
+        rows.append(row % x)
+    results = table % ('\n'.join(rows))
+    
+    conn.close()
+    return results
+    
+    
+
+class RequestHandler(BaseHTTPServer.BaseHTTPRequestHandler):
+    
+    def do_GET(self):
+        self.send_response(200, "OK")
+        self.end_headers()
+        parts = self.path.split('?')
+        if len(parts) > 1:
+            _, query = parts
+            query = cgi.parse_qs(query, strict_parsing=True)
+        else:
+            query = None
+
+        if query is not None:
+            query = pypymagic.taint(query)
+            results = do_query(query)
+        else:
+            results = "no query"
+
+        self.wfile.write(page % results)
+
+
+
+if __name__ == '__main__':
+    if len(sys.argv) > 1:
+        port = int(sys.argv[1])
+    else:
+        port = 8000
+    
+    server_address = ('', port)
+    httpd = BaseHTTPServer.HTTPServer(server_address, RequestHandler)
+    httpd.serve_forever()

File lib-python/conftest.py

 from pypy.tool.pytest import appsupport 
 from pypy.tool.pytest.confpath import pypydir, libpythondir, \
                                       regrtestdir, modregrtestdir, testresultdir
+from pypy.tool.pytest.result import Result, ResultFromMime
+
+pypyexecpath = pypydir.join('bin', 'pypy-c')
 
 dist_rsync_roots = ['.', '../pypy', '../py']
     
 # Interfacing/Integrating with py.test's collection process 
 #
 
+# XXX no nice way to implement a --listpassing py.test option?! 
+#option = py.test.addoptions("compliance testing options", 
+#    py.test.Option('-L', '--listpassing', action="store", default=None, 
+#                   type="string", dest="listpassing", 
+#                   help="just display the list of expected-to-pass tests.")
+
 Option = py.test.config.Option 
 option = py.test.config.addoptions("compliance testing options", 
+    Option('-C', '--compiled', action="store_true", 
+           default=False, dest="use_compiled", 
+           help="use a compiled version of pypy"),
+    Option('--compiled-pypy', action="store", type="string", dest="pypy_executable",
+           default=str(pypyexecpath),
+           help="to use together with -C to specify the path to the "
+                "compiled version of pypy, by default expected in pypy/bin/pypy-c"),
+    Option('-E', '--extracttests', action="store_true", 
+           default=False, dest="extracttests", 
+           help="try to extract single tests and run them via py.test/PyPy"), 
     Option('-T', '--timeout', action="store", type="string", 
            default="100mp", dest="timeout", 
            help="fail a test module after the given timeout. "
                 "specify in seconds or 'NUMmp' aka Mega-Pystones"),
-    Option('--pypy', action="store", type="string",
-           dest="pypy",  help="use given pypy executable to run lib-python tests. "
-                              "This will run the tests directly (i.e. not through py.py)")
+    Option('--resultdir', action="store", type="string", 
+           default=None, dest="resultdir", 
+           help="directory under which to store results in USER@HOST subdirs",
+           ),
     )
 
 def gettimeout(): 
         return seconds 
     return float(timeout) 
 
+def callex(space, func, *args, **kwargs): 
+    try: 
+        return func(*args, **kwargs) 
+    except OperationError, e: 
+        ilevelinfo = py.code.ExceptionInfo()
+        if e.match(space, space.w_KeyboardInterrupt): 
+            raise KeyboardInterrupt 
+        appexcinfo = appsupport.AppExceptionInfo(space, e) 
+        if appexcinfo.traceback: 
+            print "appexcinfo.traceback:"
+            py.std.pprint.pprint(appexcinfo.traceback)
+            raise py.test.collect.Item.Failed(excinfo=appexcinfo) 
+        raise py.test.collect.Item.Failed(excinfo=ilevelinfo) 
+
+#
+# compliance modules where we invoke test_main() usually call into 
+# test_support.(run_suite|run_doctests) 
+# we intercept those calls and use the provided information 
+# for our collection process.  This allows us to run all the 
+# tests one by one. 
+#
+
+app = ApplevelClass('''
+    #NOT_RPYTHON  
+
+    import unittest 
+    from test import test_support   
+    import sys
+
+    def getmethods(suite_or_class): 
+        """ flatten out suites down to TestCase instances/methods. """ 
+        if isinstance(suite_or_class, unittest.TestCase): 
+            res = [suite_or_class]
+        elif isinstance(suite_or_class, unittest.TestSuite): 
+            res = []
+            for x in suite_or_class._tests: 
+                res.extend(getmethods(x))
+        elif isinstance(suite_or_class, list): 
+            res = []
+            for x in suite_or_class: 
+                res.extend(getmethods(x))
+        else: 
+            raise TypeError, "expected TestSuite or TestClass, got %r"  %(suite_or_class) 
+        return res 
+
+    #
+    # exported API 
+    #
+
+    def intercept_test_support(): 
+        """ intercept calls to test_support.run_doctest and run_suite. 
+            Return doctestmodules, suites which will hold collected
+            items from these test_support invocations. 
+        """
+        suites = []
+        doctestmodules = []
+        def hack_run_doctest(module, verbose=None): 
+            doctestmodules.append(module) 
+        test_support.run_doctest = hack_run_doctest 
+
+        def hack_run_suite(suite, testclass=None): 
+            suites.append(suite) 
+        test_support.run_suite = hack_run_suite 
+        return suites, doctestmodules 
+
+    def collect_intercepted(suites, doctestmodules): 
+        namemethodlist = []
+        for method in getmethods(suites): 
+            name = (method.__class__.__name__ + '.' + 
+                    method._TestCase__testMethodName)
+            namemethodlist.append((name, method))
+        doctestlist = []
+        for mod in doctestmodules: 
+            doctestlist.append((mod.__name__, mod))
+        return namemethodlist, doctestlist 
+
+    def run_testcase_method(method): 
+        result = method.defaultTestResult() 
+        method.run(result)
+        if result.errors:
+            assert len(result.errors)
+            print result.errors[0][1]
+        if result.failures:
+            assert len(result.failures)
+            print result.failures[0][1]
+        if result.failures or result.errors:
+            return 1
+
+    def set_argv(filename): 
+        sys.argv[:] = ['python', filename]
+''') 
+
+intercept_test_support = app.interphook('intercept_test_support')
+collect_intercepted = app.interphook('collect_intercepted')
+run_testcase_method = app.interphook('run_testcase_method')
+set_argv = app.interphook('set_argv')
+
+def start_intercept(space): 
+    w_suites, w_doctestmodules = space.unpacktuple(intercept_test_support(space))
+    return w_suites, w_doctestmodules 
+
+def collect_intercept(space, w_suites, w_doctestmodules): 
+    w_result = callex(space, collect_intercepted, space, w_suites, w_doctestmodules)
+    w_namemethods, w_doctestlist = space.unpacktuple(w_result) 
+    return w_namemethods, w_doctestlist 
+
+class SimpleRunItem(py.test.collect.Item): 
+    """ Run a module file and compare its output 
+        to the expected output in the output/ directory. 
+    """ 
+    def call_capture(self, space, func, *args): 
+        regrtest = self.parent.regrtest 
+        oldsysout = sys.stdout 
+        sys.stdout = capturesysout = py.std.cStringIO.StringIO() 
+        try: 
+            try: 
+                res = regrtest.run_file(space) 
+            except: 
+                print capturesysout.getvalue()
+                raise 
+            else: 
+                return res, capturesysout.getvalue()
+        finally: 
+            sys.stdout = oldsysout 
+        
+    def run(self): 
+        # XXX integrate this into InterceptedRunModule
+        #     but we want a py.test refactoring towards
+        #     more autonomy of colitems regarding 
+        #     their representations 
+        regrtest = self.parent.regrtest
+        space = gettestobjspace(usemodules=[])
+        res, output = self.call_capture(space, regrtest.run_file, space)
+
+        outputpath = regrtest.getoutputpath() 
+        if outputpath: 
+            # we want to compare outputs 
+            # regrtest itself prepends the test_name to the captured output
+            result = outputpath.purebasename + "\n" + output 
+            expected = outputpath.read(mode='r') 
+            if result != expected: 
+                reportdiff(expected, result) 
+                py.test.fail("output check failed: %s" % (self.fspath.basename,))
+        if output: 
+            print output, 
+
+#
+class InterceptedRunModule(py.test.collect.Module): 
+    """ special handling for tests with a proper 'def test_main(): '
+        definition invoking test_support.run_suite or run_unittest 
+        (XXX add support for test_support.run_doctest). 
+    """ 
+    def __init__(self, name, parent, regrtest): 
+        super(InterceptedRunModule, self).__init__(name, parent)
+        self.regrtest = regrtest
+        self.fspath = regrtest.getfspath()
+
+    def _prepare(self): 
+        if hasattr(self, 'name2item'): 
+            return
+        self.name2item = {}
+        space = gettestobjspace(usemodules=self.regrtest.usemodules)
+        if self.regrtest.dumbtest or self.regrtest.getoutputpath(): 
+            self.name2item['output'] = SimpleRunItem('output', self) 
+            return 
+
+        tup = start_intercept(space) 
+        self.regrtest.run_file(space)
+        w_namemethods, w_doctestlist = collect_intercept(space, *tup) 
+
+        # setup {name -> wrapped testcase method}
+        for w_item in space.unpackiterable(w_namemethods): 
+            w_name, w_method = space.unpacktuple(w_item) 
+            name = space.str_w(w_name) 
+            testitem = AppTestCaseMethod(name, parent=self, w_method=w_method) 
+            self.name2item[name] = testitem
+
+        # setup {name -> wrapped doctest module}
+        for w_item in space.unpackiterable(w_doctestlist): 
+            w_name, w_module = space.unpacktuple(w_item) 
+            name = space.str_w(w_name) 
+            testitem = AppDocTestModule(name, parent=self, w_module=w_module)
+            self.name2item[name] = testitem 
+       
+    def run(self): 
+        self._prepare() 
+        keys = self.name2item.keys()
+        keys.sort(lambda x,y: cmp(x.lower(), y.lower()))
+        return keys 
+
+    def join(self, name): 
+        self._prepare() 
+        try: 
+            return self.name2item[name]
+        except KeyError: 
+            pass
+
+class AppDocTestModule(py.test.collect.Item): 
+    def __init__(self, name, parent, w_module): 
+        super(AppDocTestModule, self).__init__(name, parent) 
+        self.w_module = w_module 
+
+    def run(self): 
+        py.test.skip("application level doctest modules not supported yet.")
+    
+class AppTestCaseMethod(py.test.collect.Item): 
+    def __init__(self, name, parent, w_method): 
+        super(AppTestCaseMethod, self).__init__(name, parent) 
+        self.space = gettestobjspace() 
+        self.w_method = w_method 
+
+    def run(self):      
+        space = self.space
+        filename = str(self.fspath) 
+        callex(space, set_argv, space, space.wrap(filename))
+        #space.call_function(self.w_method)
+        w_res = callex(space, run_testcase_method, space, self.w_method) 
+        if space.is_true(w_res):
+            raise AssertionError(
+        "testcase instance invociation raised errors, see stdoudt")
+
 # ________________________________________________________________________
 #
 # classification of all tests files (this is ongoing work) 
 class RegrTest: 
     """ Regression Test Declaration.""" 
     def __init__(self, basename, enabled=False, dumbtest=False,
-                                 core=False,
+                                 oldstyle=False, core=False,
                                  compiler=None, 
                                  usemodules = ''): 
         self.basename = basename 
         self.enabled = enabled 
         self.dumbtest = dumbtest 
+        # we have to determine the value of oldstyle
+        # lazily because at RegrTest() call time the command
+        # line options haven't been parsed!
+        self._oldstyle = oldstyle 
         self._usemodules = usemodules.split()
         self._compiler = compiler 
         self.core = core
 
+    def oldstyle(self): 
+        return self._oldstyle #or pypy_option.oldstyle 
+    oldstyle = property(oldstyle)
+
     def usemodules(self):
         return self._usemodules #+ pypy_option.usemodules
     usemodules = property(usemodules)
         return self._compiler #or pypy_option.compiler 
     compiler = property(compiler)
 
+    def getoptions(self): 
+        l = []
+        for name in 'oldstyle', 'core': 
+            if getattr(self, name): 
+                l.append(name)
+        for name in self.usemodules: 
+            l.append(name)
+        return l 
+
     def ismodified(self): 
         return modregrtestdir.join(self.basename).check() 
 
         self._prepare(space)
         fspath = self.getfspath()
         assert fspath.check()
-        modname = fspath.purebasename 
-        space.appexec([], '''():
-            from test import %(modname)s
-            m = %(modname)s
-            if hasattr(m, 'test_main'):
-                m.test_main()
-        ''' % locals())
+        if self.oldstyle: 
+            space.enable_old_style_classes_as_default_metaclass() 
+        try: 
+            modname = fspath.purebasename 
+            space.appexec([], '''():
+                from test import %(modname)s
+                m = %(modname)s
+                if hasattr(m, 'test_main'):
+                    m.test_main()
+            ''' % locals())
+        finally: 
+            space.enable_new_style_classes_as_default_metaclass() 
 
 testmap = [
     RegrTest('test___all__.py', enabled=True, core=True),
     RegrTest('test_cgi.py', enabled=True),
     RegrTest('test_charmapcodec.py', enabled=True, core=True),
     RegrTest('test_cl.py', enabled=False, dumbtest=1),
-    RegrTest('test_class.py', enabled=True, core=True),
+    RegrTest('test_class.py', enabled=True, oldstyle=True, core=True),
     RegrTest('test_cmath.py', enabled=True, dumbtest=1, core=True),
     RegrTest('test_codeccallbacks.py', enabled=True, core=True),
     RegrTest('test_codecencodings_cn.py', enabled=False),
     RegrTest('test_codecmaps_tw.py', enabled=False),
     RegrTest('test_codecs.py', enabled=True, core=True),
     RegrTest('test_codeop.py', enabled=True, core=True),
-    RegrTest('test_coercion.py', enabled=True, core=True),
+    RegrTest('test_coercion.py', enabled=True, oldstyle=True, core=True),
     
     RegrTest('test_colorsys.py', enabled=True),
     RegrTest('test_commands.py', enabled=True),
-    RegrTest('test_compare.py', enabled=True, core=True),
+    RegrTest('test_compare.py', enabled=True, oldstyle=True, core=True),
     RegrTest('test_compile.py', enabled=True, core=True),
     RegrTest('test_compiler.py', enabled=True, core=False), # this test tests the compiler package from stdlib
     RegrTest('test_complex.py', enabled=True, core=True),
     RegrTest('test_decimal.py', enabled=True),
     RegrTest('test_decorators.py', enabled=True, core=True),
     RegrTest('test_deque.py', enabled=True, core=True),
-    RegrTest('test_descr.py', enabled=True, core=True, usemodules='_weakref'),
-    RegrTest('test_descrtut.py', enabled=True, core=True),
+    RegrTest('test_descr.py', enabled=True, core=True, oldstyle=True, usemodules='_weakref'),
+    RegrTest('test_descrtut.py', enabled=True, core=True, oldstyle=True),
     RegrTest('test_dict.py', enabled=True, core=True),
 
     RegrTest('test_difflib.py', enabled=True, dumbtest=1),
 
     RegrTest('test_gl.py', enabled=False, dumbtest=1),
     RegrTest('test_glob.py', enabled=True, core=True),
-    RegrTest('test_global.py', enabled=True, core=True),
+    RegrTest('test_global.py', enabled=True, core=True, compiler='ast'),
     RegrTest('test_grammar.py', enabled=True, core=True),
     RegrTest('test_grp.py', enabled=False),
         #rev 10840: ImportError: grp
 
     RegrTest('test_gzip.py', enabled=False, dumbtest=1),
     RegrTest('test_hash.py', enabled=True, core=True),
-    RegrTest('test_hashlib.py', enabled=True, core=True),
-        # test_hashlib comes from 2.5 
-    
     RegrTest('test_heapq.py', enabled=True, core=True),
     RegrTest('test_hexoct.py', enabled=True, core=True),
     RegrTest('test_hmac.py', enabled=True),
     RegrTest('test_multifile.py', enabled=True),
     RegrTest('test_mutants.py', enabled=True, dumbtest=1, core="possibly"),
     RegrTest('test_netrc.py', enabled=True),
-    RegrTest('test_new.py', enabled=True, core=True),
+    RegrTest('test_new.py', enabled=True, core=True, oldstyle=True),
     RegrTest('test_nis.py', enabled=False),
     RegrTest('test_normalization.py', enabled=False),
     RegrTest('test_ntpath.py', enabled=True, dumbtest=1),
     RegrTest('test_re.py', enabled=True, core=True),
 
     RegrTest('test_regex.py', enabled=False),
-    RegrTest('test_repr.py', enabled=True, core=True),
+    RegrTest('test_repr.py', enabled=True, oldstyle=True, core=True),
         #rev 10840: 6 of 12 tests fail. Always minor stuff like
         #'<function object at 0x40db3e0c>' != '<built-in function hash>'
 
                 cache[x.basename] = x
         return cache.get(name, None)
         
-    def collect(self): 
-        l = []
-        for x in testmap:
-            name = x.basename
-            regrtest = self.get(name)
-            if regrtest is not None: 
-                #if option.extracttests:  
-                #    l.append(InterceptedRunModule(name, self, regrtest))
-                #else:
-                l.append(RunFileExternal(name, parent=self, regrtest=regrtest))
-        return l 
+    def run(self): 
+        return [x.basename for x in testmap]
+
+    def join(self, name): 
+        regrtest = self.get(name) 
+        if regrtest is not None: 
+            if not option.extracttests:  
+                return RunFileExternal(name, parent=self, regrtest=regrtest) 
+            else: 
+                return InterceptedRunModule(name, self, regrtest) 
 
 Directory = RegrDirectory
 
+
+def getrev(path): 
+    try: 
+        return py.path.svnwc(pypydir).info().rev
+    except (KeyboardInterrupt, SystemExit):
+        raise
+    except:
+        # on windows people not always have 'svn' in their path
+        # but there are also other kinds of problems that
+        # could occur and we just default to revision
+        # "unknown" for them
+        return 'unknown'  
+
+def getexecutable(_cache={}):
+    execpath = py.path.local(option.pypy_executable)
+    if not _cache:
+        text = execpath.sysexec('-c', 
+            'import sys; '
+            'print sys.version; '
+            'print sys.pypy_svn_url; '
+            'print sys.pypy_translation_info; ')
+        lines = [line.strip() for line in text.split('\n')]
+        assert len(lines) == 4 and lines[3] == ''
+        assert lines[2].startswith('{') and lines[2].endswith('}')
+        info = eval(lines[2])
+        info['version'] = lines[0]
+        info['rev'] = eval(lines[1])[1]
+        _cache.update(info)
+    return execpath, _cache
+
 class RunFileExternal(py.test.collect.Module): 
     def __init__(self, name, parent, regrtest): 
         super(RunFileExternal, self).__init__(name, parent) 
         self.regrtest = regrtest 
         self.fspath = regrtest.getfspath()
 
-    def collect(self): 
+    def tryiter(self, stopitems=()): 
+        # shortcut pre-counting of items 
+        return []
+
+    def run(self): 
         if self.regrtest.ismodified(): 
-            name = 'modified'
+            return ['modified']
+        return ['unmodified']
+
+    def join(self, name): 
+        return ReallyRunFileExternal(name, parent=self) 
+
+
+def ensuretestresultdir():
+    resultdir = option.resultdir
+    default_place = False
+    if resultdir is not None:
+        resultdir = py.path.local(option.resultdir)
+    else:
+        if option.use_compiled:
+            return None
+        default_place = True
+        resultdir = testresultdir
+        
+    if not resultdir.check(dir=1):
+        if default_place:
+            py.test.skip("""'testresult' directory not found.
+                 To run tests in reporting mode (without -E), you first have to
+                 check it out as follows: 
+                 svn co http://codespeak.net/svn/pypy/testresult %s""" % (
+                testresultdir, ))
         else:
-            name = 'unmodified'
-        return [ReallyRunFileExternal(name, parent=self)] 
+            py.test.skip("'%s' test result dir not found" % resultdir)
+    return resultdir 
 
 #
 # testmethod: 
 import getpass
 
 class ReallyRunFileExternal(py.test.collect.Item): 
+    _resultcache = None
+    def _haskeyword(self, keyword): 
+        if keyword == 'core': 
+            return self.parent.regrtest.core 
+        if keyword not in ('error', 'ok', 'timeout'): 
+            return super(ReallyRunFileExternal, self).haskeyword(keyword)
+        if self._resultcache is None: 
+            from pypy.tool.pytest.overview import ResultCache
+            self.__class__._resultcache = rc = ResultCache() 
+            rc.parselatest()
+        result = self._resultcache.getlatestrelevant(self.fspath.purebasename)
+        if not result: return False
+        if keyword == 'timeout': return result.istimeout()
+        if keyword == 'error': return result.iserror()
+        if keyword == 'ok': return result.isok()
+        assert False, "should not be there" 
+
     def getinvocation(self, regrtest): 
         fspath = regrtest.getfspath() 
         python = sys.executable 
         regr_script = pypydir.join('tool', 'pytest', 
                                    'run-script', 'regrverbose.py')
         
+        if option.use_compiled:
+            execpath, info = getexecutable()        
         pypy_options = []
+        if regrtest.oldstyle: 
+            if (option.use_compiled and
+                not info.get('objspace.std.oldstyle', False)):
+                py.test.skip("old-style classes not available with this pypy-c")
+            pypy_options.append('--oldstyle') 
+        if regrtest.compiler:
+            pypy_options.append('--compiler=%s' % regrtest.compiler)
         pypy_options.extend(
             ['--withmod-%s' % mod for mod in regrtest.usemodules])
         sopt = " ".join(pypy_options) 
             regrrun_verbosity = '0'
         
         TIMEOUT = gettimeout()
-        if option.pypy:
-            execpath = py.path.local(option.pypy)
-            if not execpath.check():
-                execpath = py.path.local.sysfind(option.pypy)
-            if not execpath:
-                raise LookupError("could not find executable %r" %(option.pypy,))
+        if option.use_compiled:
             cmd = "%s %s %s %s" %(
                 execpath, 
                 regrrun, regrrun_verbosity, fspath.purebasename)
                 regrrun, regrrun_verbosity, fspath.purebasename)
         return cmd 
 
-    def runtest(self): 
+    def run(self): 
         """ invoke a subprocess running the test file via PyPy. 
             record its output into the 'result/user@host' subdirectory. 
             (we might want to create subdirectories for 
             i am afraid. 
         """ 
         regrtest = self.parent.regrtest
-        exit_status, test_stdout, test_stderr = self.getresult(regrtest) 
-        if exit_status:
+        result = self.getresult(regrtest) 
+        testresultdir = ensuretestresultdir()
+        if testresultdir is not None:
+            resultdir = testresultdir.join(result['userhost'])
+            assert resultdir.ensure(dir=1)
+
+            fn = resultdir.join(regrtest.basename).new(ext='.txt') 
+            if result.istimeout(): 
+                if fn.check(file=1): 
+                    try: 
+                        oldresult = ResultFromMime(fn)
+                    except TypeError: 
+                        pass
+                    else: 
+                        if not oldresult.istimeout(): 
+                            py.test.skip("timed out, not overwriting "
+                                         "more interesting non-timeout outcome")
+            
+            fn.write(result.repr_mimemessage().as_string(unixfrom=False))
+            
+        if result['exit-status']:  
              time.sleep(0.5)   # time for a Ctrl-C to reach us :-)
-             print >>sys.stdout, test_stdout
-             print >>sys.stderr, test_stderr
+             print >>sys.stdout, result.getnamedtext('stdout') 
+             print >>sys.stderr, result.getnamedtext('stderr') 
              py.test.fail("running test failed, see stderr output below") 
 
     def getstatusouterr(self, cmd): 
-        tempdir = py.test.ensuretemp(self.fspath.basename)
-        stdout = tempdir.join(self.fspath.basename) + '.out'
-        stderr = tempdir.join(self.fspath.basename) + '.err'
-        if sys.platform == 'win32':
-            status = os.system("%s >%s 2>%s" %(cmd, stdout, stderr))
-            if status>=0:
-                status = status
+        tempdir = py.path.local.mkdtemp() 
+        try: 
+            stdout = tempdir.join(self.fspath.basename) + '.out'
+            stderr = tempdir.join(self.fspath.basename) + '.err'
+            if sys.platform == 'win32':
+                status = os.system("%s >%s 2>%s" %(cmd, stdout, stderr))
+                if status>=0:
+                    status = status
+                else:
+                    status = 'abnormal termination 0x%x' % status
             else:
-                status = 'abnormal termination 0x%x' % status
-        else:
-            status = os.system("%s >>%s 2>>%s" %(cmd, stdout, stderr))
-            if os.WIFEXITED(status):
-                status = os.WEXITSTATUS(status)
-            else:
-                status = 'abnormal termination 0x%x' % status
-        return status, stdout.read(mode='rU'), stderr.read(mode='rU')
+                status = os.system("%s >>%s 2>>%s" %(cmd, stdout, stderr))
+                if os.WIFEXITED(status):
+                    status = os.WEXITSTATUS(status)
+                else:
+                    status = 'abnormal termination 0x%x' % status
+            return status, stdout.read(mode='rU'), stderr.read(mode='rU')
+        finally: 
+            tempdir.remove()
 
     def getresult(self, regrtest): 
         cmd = self.getinvocation(regrtest) 
+        result = Result()
+        fspath = regrtest.getfspath() 
+        result['fspath'] = str(fspath) 
+        result['pypy-revision'] = getrev(pypydir) 
+        if option.use_compiled:
+            execpath, info = getexecutable()
+            result['pypy-revision'] = info['rev']
+            result['executable'] = execpath.basename
+            for key, value in info.items():
+                if key == 'rev':
+                    continue
+                result['executable-%s' % key] = str(value)
+        else:
+            result['executable'] = 'py.py'
+        result['options'] = regrtest.getoptions() 
+        result['timeout'] = gettimeout()
+        result['startdate'] = time.ctime()
+        starttime = time.time() 
+
+        # really run the test in a sub process
         exit_status, test_stdout, test_stderr = self.getstatusouterr(cmd) 
+
         timedout = test_stderr.rfind(26*"=" + "timedout" + 26*"=") != -1 
         if not timedout: 
             timedout = test_stderr.rfind("KeyboardInterrupt") != -1
+        result['execution-time'] = time.time() - starttime
+        result.addnamedtext('stdout', test_stdout)
+        result.addnamedtext('stderr', test_stderr)
+
         outcome = 'OK'
         expectedpath = regrtest.getoutputpath()
         if not exit_status: 
                     exit_status = 2  
                     res, out, err = py.io.StdCapture.call(reportdiff, expected, test_stdout)
                     outcome = 'ERROUT' 
-                    test_stderr += ("-" * 80 + "\n") + out
+                    result.addnamedtext('reportdiff', out)
             else:
                 if 'FAIL' in test_stdout or 'ERROR' in test_stderr:
                     outcome = 'FAIL'
-                    exit_status = 2  
         elif timedout: 
             outcome = "T/O"    
         else: 
             outcome = "ERR"
         
-        return exit_status, test_stdout, test_stderr
+        result['exit-status'] = exit_status 
+        result['outcome'] = outcome 
+        return result
 
-    def _keywords(self):
-        lst = list(py.test.collect.Item._keywords(self))
-        regrtest = self.parent.regrtest
-        if regrtest.core:
-            lst.append('core')
-        return lst
 
 #
 # Sanity check  (could be done more nicely too)

File lib-python/modified-2.4.1/test/test_dbm.py

-#! /usr/bin/env python
-"""Test script for the dbm module
-   Roger E. Masse
-"""
-import os
-import random
-import dbm
-from dbm import error
-from test.test_support import verbose, verify, TestSkipped
-
-# make filename unique to allow multiple concurrent tests
-# and to minimize the likelihood of a problem from an old file
-filename = '/tmp/delete_me_' + str(random.random())[-6:]
-
-def cleanup():
-    for suffix in ['', '.pag', '.dir', '.db']:
-        try:
-            os.unlink(filename + suffix)
-        except OSError, (errno, strerror):
-            # if we can't delete the file because of permissions,
-            # nothing will work, so skip the test
-            if errno == 1:
-                raise TestSkipped, 'unable to remove: ' + filename + suffix
-
-def test_keys():
-    d = dbm.open(filename, 'c')
-    verify(d.keys() == [])
-    d['a'] = 'b'
-    d['12345678910'] = '019237410982340912840198242'
-    verify(d.keys() == ['12345678910', 'a'])
-    verify(d.get('a') == 'b')
-    verify(d.get('b', None) == None)
-    try:
-        d.get('b')
-    except KeyError, e:
-        pass
-    try:
-        d['b']
-    except KeyError,e :
-        pass
-
-    if d.has_key('a'):
-        if verbose:
-            print 'Test dbm keys: ', d.keys()
-
-    d.close()
-    try:
-        d.keys()
-    except dbm.error:
-        pass
-
-def test_modes():
-    d = dbm.open(filename, 'r')
-    d.close()
-    d = dbm.open(filename, 'rw')
-    d.close()
-    d = dbm.open(filename, 'w')
-    d.close()
-    d = dbm.open(filename, 'n')
-    d.close()
-
-cleanup()
-try:
-    test_keys()
-    test_modes()
-except:
-    cleanup()
-    raise
-
-cleanup()

File lib-python/modified-2.4.1/test/test_hashlib.py

-# Test hashlib module
-#
-# $Id: test_hashlib.py 39316 2005-08-21 18:45:59Z greg $
-#
-#  Copyright (C) 2005   Gregory P. Smith (greg@electricrain.com)
-#  Licensed to PSF under a Contributor Agreement.
-#
-
-import hashlib
-import unittest
-from test import test_support
-
-
-def hexstr(s):
-    import string
-    h = string.hexdigits
-    r = ''
-    for c in s:
-        i = ord(c)
-        r = r + h[(i >> 4) & 0xF] + h[i & 0xF]
-    return r
-
-
-class HashLibTestCase(unittest.TestCase):
-    supported_hash_names = ( 'md5', 'MD5', 'sha1', 'SHA1',
-                             'sha224', 'SHA224', 'sha256', 'SHA256',
-                             'sha384', 'SHA384', 'sha512', 'SHA512' )
-
-    def test_unknown_hash(self):
-        try:
-            hashlib.new('spam spam spam spam spam')
-        except ValueError:
-            pass
-        else:
-            self.assert_(0 == "hashlib didn't reject bogus hash name")
-
-    def test_hexdigest(self):
-        for name in self.supported_hash_names:
-            h = hashlib.new(name)
-            self.assert_(hexstr(h.digest()) == h.hexdigest())
-
-
-    def test_large_update(self):
-        aas = 'a' * 128
-        bees = 'b' * 127
-        cees = 'c' * 126
-
-        for name in self.supported_hash_names:
-            m1 = hashlib.new(name)
-            m1.update(aas)
-            m1.update(bees)
-            m1.update(cees)
-
-            m2 = hashlib.new(name)
-            m2.update(aas + bees + cees)
-            self.assertEqual(m1.digest(), m2.digest())
-
-
-    def check(self, name, data, digest):
-        # test the direct constructors
-        computed = getattr(hashlib, name)(data).hexdigest()
-        self.assert_(computed == digest)
-        # test the general new() interface
-        computed = hashlib.new(name, data).hexdigest()
-        self.assert_(computed == digest)
-
-
-    def test_case_md5_0(self):
-        self.check('md5', '', 'd41d8cd98f00b204e9800998ecf8427e')
-
-    def test_case_md5_1(self):
-        self.check('md5', 'abc', '900150983cd24fb0d6963f7d28e17f72')
-
-    def test_case_md5_2(self):
-        self.check('md5', 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789',
-                   'd174ab98d277d9f5a5611c2c9f419d9f')
-
-
-    # use the three examples from Federal Information Processing Standards
-    # Publication 180-1, Secure Hash Standard,  1995 April 17
-    # http://www.itl.nist.gov/div897/pubs/fip180-1.htm
-
-    def test_case_sha1_0(self):
-        self.check('sha1', "",
-                   "da39a3ee5e6b4b0d3255bfef95601890afd80709")
-
-    def test_case_sha1_1(self):
-        self.check('sha1', "abc",
-                   "a9993e364706816aba3e25717850c26c9cd0d89d")
-
-    def test_case_sha1_2(self):
-        self.check('sha1', "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq",
-                   "84983e441c3bd26ebaae4aa1f95129e5e54670f1")
-
-    def test_case_sha1_3(self):
-        self.check('sha1', "a" * 1000000,
-                   "34aa973cd4c4daa4f61eeb2bdbad27316534016f")
-
-
-    # use the examples from Federal Information Processing Standards
-    # Publication 180-2, Secure Hash Standard,  2002 August 1
-    # http://csrc.nist.gov/publications/fips/fips180-2/fips180-2.pdf
-
-    def test_case_sha224_0(self):
-        self.check('sha224', "",
-          "d14a028c2a3a2bc9476102bb288234c415a2b01f828ea62ac5b3e42f")
-
-    def test_case_sha224_1(self):
-        self.check('sha224', "abc",
-          "23097d223405d8228642a477bda255b32aadbce4bda0b3f7e36c9da7")
-
-    def test_case_sha224_2(self):
-        self.check('sha224',
-          "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq",
-          "75388b16512776cc5dba5da1fd890150b0c6455cb4f58b1952522525")
-
-    def test_case_sha224_3(self):
-        self.check('sha224', "a" * 1000000,
-          "20794655980c91d8bbb4c1ea97618a4bf03f42581948b2ee4ee7ad67")
-
-
-    def test_case_sha256_0(self):
-        self.check('sha256', "",
-          "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855")
-
-    def test_case_sha256_1(self):
-        self.check('sha256', "abc",
-          "ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad")
-
-    def test_case_sha256_2(self):
-        self.check('sha256',
-          "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq",
-          "248d6a61d20638b8e5c026930c3e6039a33ce45964ff2167f6ecedd419db06c1")
-
-    def test_case_sha256_3(self):
-        self.check('sha256', "a" * 1000000,
-          "cdc76e5c9914fb9281a1c7e284d73e67f1809a48a497200e046d39ccc7112cd0")
-
-
-    def test_case_sha384_0(self):
-        self.check('sha384', "",
-          "38b060a751ac96384cd9327eb1b1e36a21fdb71114be07434c0cc7bf63f6e1da"+
-          "274edebfe76f65fbd51ad2f14898b95b")
-
-    def test_case_sha384_1(self):
-        self.check('sha384', "abc",
-          "cb00753f45a35e8bb5a03d699ac65007272c32ab0eded1631a8b605a43ff5bed"+
-          "8086072ba1e7cc2358baeca134c825a7")
-
-    def test_case_sha384_2(self):
-        self.check('sha384',
-                   "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmn"+
-                   "hijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu",
-          "09330c33f71147e83d192fc782cd1b4753111b173b3b05d22fa08086e3b0f712"+
-          "fcc7c71a557e2db966c3e9fa91746039")
-
-    def test_case_sha384_3(self):
-        self.check('sha384', "a" * 1000000,
-          "9d0e1809716474cb086e834e310a4a1ced149e9c00f248527972cec5704c2a5b"+
-          "07b8b3dc38ecc4ebae97ddd87f3d8985")
-
-
-    def test_case_sha512_0(self):
-        self.check('sha512', "",
-          "cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce"+
-          "47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e")
-
-    def test_case_sha512_1(self):
-        self.check('sha512', "abc",
-          "ddaf35a193617abacc417349ae20413112e6fa4e89a97ea20a9eeee64b55d39a"+
-          "2192992a274fc1a836ba3c23a3feebbd454d4423643ce80e2a9ac94fa54ca49f")
-
-    def test_case_sha512_2(self):
-        self.check('sha512',
-                   "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmn"+
-                   "hijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu",
-          "8e959b75dae313da8cf4f72814fc143f8f7779c6eb9f7fa17299aeadb6889018"+
-          "501d289e4900f7e4331b99dec4b5433ac7d329eeb6dd26545e96e55b874be909")
-
-    def test_case_sha512_3(self):
-        self.check('sha512', "a" * 1000000,
-          "e718483d0ce769644e2e42c7bc15b4638e1f98b13b2044285632a803afa973eb"+
-          "de0ff244877ea60a4cb0432ce577c31beb009c5c2c49aa2e4eadb217ad8cc09b")
-
-
-def test_main():
-    test_support.run_unittest(HashLibTestCase)
-
-
-if __name__ == "__main__":
-    test_main()

File lib-python/modified-2.4.1/test/test_repr.py

         eq(r(n), expected)
 
     def test_instance(self):
+        # Disabled for PyPy because it relies on oldstyle class behaviour.
+        # Running the test under oldstyle results in many more other problems
+        # though.
         eq = self.assertEquals
         i1 = ClassWithRepr("a")
         eq(r(i1), repr(i1))
         # Functions
         eq(repr(hash), '<built-in function hash>')
         # Methods
-        self.failUnless('method' in repr(''.split))
-        self.failUnless('str' in repr(''.split))
-        self.failUnless('split' in repr(''.split))
+        self.failUnless(repr(''.split).find(
+            "bound method str.split of '' at 0x") > -1)
 
     def test_xrange(self):
         import warnings
     def test_descriptors(self):
         eq = self.assertEquals
         # method descriptors
-        self.assert_('method' in repr(dict.items))
-        self.assert_('dict' in repr(dict.items))
-        self.assert_('items' in repr(dict.items))
+        eq(repr(dict.items), "<unbound method dict.items>")
         # XXX member descriptors
         # XXX attribute descriptors
         # XXX slot descriptors
                 os.remove(p)
         del sys.path[0]
 
-    def test_module(self):
+    def DONOTtest_module(self):
+        # PyPy really doesn't (want to) do these complex module reprs.
         eq = self.assertEquals
         touch(os.path.join(self.subpkgname, self.pkgname + os.extsep + 'py'))
         from areallylongpackageandmodulenametotestreprtruncation.areallylongpackageandmodulenametotestreprtruncation import areallylongpackageandmodulenametotestreprtruncation

File lib-python/modified-2.4.1/types.py