[Zodb-checkins] CVS: Zope3/lib/python/Persistence - Module.py:1.19
Jeremy Hylton
jeremy@zope.com
Fri, 20 Sep 2002 15:52:27 -0400
Update of /cvs-repository/Zope3/lib/python/Persistence
In directory cvs.zope.org:/tmp/cvs-serv9728
Modified Files:
Module.py
Log Message:
Add support for relative imports from modules in packages.
XXX I'm not sure this is complete, but it's getting there.
=== Zope3/lib/python/Persistence/Module.py 1.18 => 1.19 ===
--- Zope3/lib/python/Persistence/Module.py:1.18 Fri Sep 20 15:22:30 2002
+++ Zope3/lib/python/Persistence/Module.py Fri Sep 20 15:52:25 2002
@@ -56,10 +56,6 @@
state["__builtins__"] = __builtin__
self.__dict__.update(state)
-# TODO for persistent packages:
-# handle package-local imports
-# handle from package import submodule
-
class PersistentPackage(PersistentModule):
# XXX Is it okay that these packages don't have __path__?
@@ -180,7 +176,14 @@
__builtin__.__import__ = self._saved_import
def _import(self, registry, name, parent, fromlist):
- mod = registry.findModule(name)
+ mod = None
+ if parent is not None:
+ fullname = "%s.%s" % (parent, name)
+ mod = registry.findModule(fullname)
+ if mod is None:
+ parent = None
+ if mod is None: # no parent or didn't find in parent
+ mod = registry.findModule(name)
if mod is None:
return None
if fromlist:
@@ -191,7 +194,10 @@
i = name.find(".")
if i == -1:
return mod
- top = registry.findModule(name[:i])
+ name = name[:i]
+ if parent:
+ name = "%s.%s" % (parent, name)
+ top = registry.findModule(name)
assert top is not None, "No package for module %s" % name
return top