[Python-checkins] r52261 - sandbox/trunk/import_in_py/importer.py

brett.cannon python-checkins at python.org
Tue Oct 10 01:57:54 CEST 2006


Author: brett.cannon
Date: Tue Oct 10 01:57:54 2006
New Revision: 52261

Modified:
   sandbox/trunk/import_in_py/importer.py
Log:
Add handling of 'handles' for the bytecode handler.


Modified: sandbox/trunk/import_in_py/importer.py
==============================================================================
--- sandbox/trunk/import_in_py/importer.py	(original)
+++ sandbox/trunk/import_in_py/importer.py	Tue Oct 10 01:57:54 2006
@@ -186,16 +186,18 @@
 class PyBytecodeHandler(object):
 
     """Handler for importing .pyc/.pyo modules."""
-
-    # XXX 'handles' should be a property that returns based on whether -O was
-    # specified when running the interpreter.
-    handles = 'pyc'
     
     # XXX Should probably add a handle_string() method to PySourceHandler() so
     # that if the .pyc is outdated it can easily use PySourceHandler to do the
     # import for it and then write out the new .pyc .
     # XXX Writing out a new .pyc should be made optional.
 
+    def _handles(self):
+        """Return either 'pyc' or 'pyo' based on __debug__."""
+        return 'pyc' if __debug__ else 'pyo'
+        
+    handles = property(_handles)
+
     def handle_file(self, module, fullname, path, file_path):
         """Import the Python bytecode file at 'path' and use it to initialize
         'module'."""


More information about the Python-checkins mailing list