[Python-checkins] r52370 - sandbox/trunk/import_in_py/importer.py
brett.cannon
python-checkins at python.org
Tue Oct 17 23:54:50 CEST 2006
Author: brett.cannon
Date: Tue Oct 17 23:54:50 2006
New Revision: 52370
Modified:
sandbox/trunk/import_in_py/importer.py
Log:
Remove notes on simple DB and zipimport rewrite. It's a waste of time to use
PyPycBaseHandler and friends since they are geared towards the situation where
bytecode regeneration is a possibility.
For simple situations like zipimport or a DB that only has source or bytecode
it is easier to just either inline reading the source/bytecode and making the
code object or a simple handler that just takes in a string and just does the
compile/exec step immediately.
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 17 23:54:50 2006
@@ -57,65 +57,43 @@
+ get_code_from_source()
- Handle transforming source to pure Python source.
- Return code object and timestamp.
-
-zipimport use-case:
-* Importer
- + Check if .py or .pyc file exists for module in zip file.
-* Loader
- + Read .py or .pyc file into a StringIO instance.
- + Set 'name' attribute to zip file plus file name.
-* Use PyPycFileHandler
-
-
+
sqlite3 importer use-case:
-* Simple way (only support just bytecode or source)
- + DB
- - For source just a column for module name and another containing the
- source.
- - For bytecode, a column for module name, another containing .pyc
- output.
- + Importer
- - Query DB to see if module name is there.
- + Loader
- - Read entry in DB for module into a StringIO instance.
- - Set 'name' attribute on StringIO instance to be DB path plus module name.
- + Use the py/pyc file handler set for just source or bytecode.
-* Feature-rich way
- + DB
- - Module name.
- - Source code.
- - Marshalled code of the source.
- * Set to NULL when source code is modified, which removes need of
- storing the bytecode's timestamp.
- - Magic number for bytecode.
- + Importer
- - Query DB to see if module is listed.
- - Whether it is in bytecode or source form is irrelevant.
- + Loader
- - See if bytecode is in DB; if so then have that used, otherwise source.
- - Pass in tuple of DB instance and requested module.
- + Subclass PyPycBaseHandler
- - Have both source and bytecode opaque objects be a tuple of the DB
- instance and the module name that is being handled.
- - get_bytecode()
- * Reads DB and returns magic number, 0 for timestamp, and bytecode.
- * Timestamp is unneeded as existence of bytecode implicitly means
- that it is not outdated.
- - find_source()
- * Can return same tuple as passed into handle_code().
- - verify_timestamp()
- * ``return True``.
- - get_code_from_source()
- * Get source from DB.
- * compile.
- * return code object and 0 for timestamp.
- - write_bytecode()
- * Get marshalled string from code object.
- * Write marshalled string to DB.
- * Write current magic number to DB.
- - get_location()
- * Return the path to the DB and the module name.
- * Could even return SQL statement to get module if one cared.
++ DB
+ - Module name.
+ - Source code.
+ - Marshalled code of the source.
+ * Set to NULL when source code is modified, which removes need of
+ storing the bytecode's timestamp.
+ - Magic number for bytecode.
++ Importer
+ - Query DB to see if module is listed.
+ - Whether it is in bytecode or source form is irrelevant.
++ Loader
+ - See if bytecode is in DB; if so then have that used, otherwise source.
+ - Pass in tuple of DB instance and requested module.
++ Subclass PyPycBaseHandler
+ - Have both source and bytecode opaque objects be a tuple of the DB
+ instance and the module name that is being handled.
+ - get_bytecode()
+ * Reads DB and returns magic number, 0 for timestamp, and bytecode.
+ * Timestamp is unneeded as existence of bytecode implicitly means
+ that it is not outdated.
+ - find_source()
+ * Can return same tuple as passed into handle_code().
+ - verify_timestamp()
+ * ``return True``.
+ - get_code_from_source()
+ * Get source from DB.
+ * compile.
+ * return code object and 0 for timestamp.
+ - write_bytecode()
+ * Get marshalled string from code object.
+ * Write marshalled string to DB.
+ * Write current magic number to DB.
+ - get_location()
+ * Return the path to the DB and the module name.
+ * Could even return SQL statement to get module if one cared.
"""
from __future__ import with_statement
@@ -546,4 +524,4 @@
with contextlib.closing(source_file):
source_location = self.get_location(source_file)
bytecode_location = self.get_location(bytecode_file)
- py_compile.compile(source_location, bytecode_location, doraise=True)
\ No newline at end of file
+ py_compile.compile(source_location, bytecode_location, doraise=True)
More information about the Python-checkins
mailing list