Commit 4c346558 authored by Fred Drake's avatar Fred Drake

Various cleanups for clarity.

parent 65f6c4f9
...@@ -14,8 +14,8 @@ __doc__='''Standard routines for handling extensions. ...@@ -14,8 +14,8 @@ __doc__='''Standard routines for handling extensions.
Extensions currently include external methods and pluggable brains. Extensions currently include external methods and pluggable brains.
$Id: Extensions.py,v 1.19 2002/08/14 21:31:40 mj Exp $''' $Id: Extensions.py,v 1.20 2003/02/10 18:26:03 fdrake Exp $'''
__version__='$Revision: 1.19 $'[11:-2] __version__='$Revision: 1.20 $'[11:-2]
import os, zlib, rotor, imp import os, zlib, rotor, imp
import Products import Products
...@@ -102,16 +102,15 @@ def getObject(module, name, reload=0, ...@@ -102,16 +102,15 @@ def getObject(module, name, reload=0,
# update the cache, then one will have simply worked a little # update the cache, then one will have simply worked a little
# harder than need be. So, in this case, we won't incur # harder than need be. So, in this case, we won't incur
# the expense of a lock. # the expense of a lock.
if modules.has_key(module): old = modules.get(module)
old=modules[module] if old is not None and name in old and not reload:
if old.has_key(name) and not reload: return old[name] return old[name]
else:
old=None
if module[-3:]=='.py': p=module[:-3] base, ext = os.path.splitext(module)
elif module[-4:]=='.pyp': p=module[:-4] if ext in ('py', 'pyp', 'pyc'):
elif module[-4:]=='.pyc': p=module[:-4] p = base
else: p=module else:
p = module
p=getPath('Extensions', p, suffixes=('','py','pyp','pyc')) p=getPath('Extensions', p, suffixes=('','py','pyp','pyc'))
if p is None: if p is None:
raise "Module Error", ( raise "Module Error", (
...@@ -120,14 +119,15 @@ def getObject(module, name, reload=0, ...@@ -120,14 +119,15 @@ def getObject(module, name, reload=0,
__traceback_info__=p, module __traceback_info__=p, module
if p[-4:]=='.pyc': base, ext = os.path.splitext(p)
if ext=='.pyc':
file = open(p, 'rb') file = open(p, 'rb')
binmod=imp.load_compiled('Extension', p, file) binmod=imp.load_compiled('Extension', p, file)
file.close() file.close()
m=binmod.__dict__ m=binmod.__dict__
elif p[-4:]=='.pyp': elif ext=='.pyp':
prod_id=module.split('.')[0] prod_id=module.split('.', 1)[0]
data=zlib.decompress( data=zlib.decompress(
rotor.newrotor(prod_id +' shshsh').decrypt(open(p,'rb').read()) rotor.newrotor(prod_id +' shshsh').decrypt(open(p,'rb').read())
) )
...@@ -143,18 +143,18 @@ def getObject(module, name, reload=0, ...@@ -143,18 +143,18 @@ def getObject(module, name, reload=0,
m={} m={}
exec execsrc in m exec execsrc in m
try: r=m[name] if old is not None:
old.update(m)
else:
modules[module] = m
try:
return m[name]
except KeyError: except KeyError:
raise 'Invalid Object Name', ( raise 'Invalid Object Name', (
"The specified object, <em>%s</em>, was not found in module, " "The specified object, <em>%s</em>, was not found in module, "
"<em>%s</em>." % (name, module)) "<em>%s</em>." % (name, module))
if old:
for k, v in m.items(): old[k]=v
modules[module]=m
return r
class NoBrains: pass class NoBrains: pass
def getBrain(module, class_name, reload=0): def getBrain(module, class_name, reload=0):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment