[pypy-svn] r55877 - in pypy/dist/pypy/lib: . app_test

arigo at codespeak.net arigo at codespeak.net
Mon Jun 16 13:54:57 CEST 2008


Author: arigo
Date: Mon Jun 16 13:54:55 2008
New Revision: 55877

Modified:
   pypy/dist/pypy/lib/app_test/test_imp_extra.py
   pypy/dist/pypy/lib/imp.py
Log:
Fix the testing of imp.py.


Modified: pypy/dist/pypy/lib/app_test/test_imp_extra.py
==============================================================================
--- pypy/dist/pypy/lib/app_test/test_imp_extra.py	(original)
+++ pypy/dist/pypy/lib/app_test/test_imp_extra.py	Mon Jun 16 13:54:55 2008
@@ -44,15 +44,12 @@
     return fn
 
 def _pyc_file():
-    # XXX quick hack
-    # (that's the bytecode for the module containing only 'marker=42')
+    import marshal
+    co = compile("marker=42", "x.py", "exec")
     f = open('@TEST.pyc', 'wb')
-    f.write('m\xf2\r\n\xd6\x85\x0cCc\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00'
-            '\x00\x00@\x00\x00\x00s\n\x00\x00\x00d\x00\x00Z\x00\x00d\x01\x00'
-            'S(\x02\x00\x00\x00i*\x00\x00\x00N(\x01\x00\x00\x00t\x06\x00\x00'
-            '\x00marker(\x01\x00\x00\x00R\x00\x00\x00\x00(\x00\x00\x00\x00('
-            '\x00\x00\x00\x00t\x04\x00\x00\x00x.pyt\x01\x00\x00\x00?\x01\x00'
-            '\x00\x00s\x00\x00\x00\x00')
+    f.write(imp.get_magic())
+    f.write('\x00\x00\x00\x00')
+    marshal.dump(co, f)
     f.close()
     return '@TEST.pyc'
 

Modified: pypy/dist/pypy/lib/imp.py
==============================================================================
--- pypy/dist/pypy/lib/imp.py	(original)
+++ pypy/dist/pypy/lib/imp.py	Mon Jun 16 13:54:55 2008
@@ -19,10 +19,16 @@
 import new
 import sys, os
 
-def get_magic():
-    """Return the magic number for .pyc or .pyo files."""
-    import struct
-    return struct.pack('L', sys._magic())
+# PyPy-specific interface
+try:
+    from sys import _magic as _get_magic_as_int
+    def get_magic():
+        """Return the magic number for .pyc or .pyo files."""
+        import struct
+        return struct.pack('L', _get_magic_as_int())
+except ImportError:
+    # XXX CPython testing hack: delegate to the real imp.get_magic
+    get_magic = __import__('imp').get_magic
 
 def get_suffixes():
     """Return a list of (suffix, mode, type) tuples describing the files



More information about the Pypy-commit mailing list