def remote_retrieve_code(self, name):
# XXX codeValidator: can we somehow get the client's address it is sent to?
# XXX this code is ugly. And duplicated in protocol.py remoteInvocation.
if Pyro.config.PYRO_MOBILE_CODE and self.codeValidator(name,None,None):
Log.msg("ObjBase","supplying code: ",name)
try:
importmodule=new.module("pyro-server-import")
try:
exec "import " + name in importmodule.__dict__
except ImportError:
Log.error("ObjBase","Client wanted a non-existing module:", name)
raise PyroError("Client wanted a non-existing module", name)
m=eval("importmodule."+name)
# try to load the module's compiled source, or the real .py source if that fails.
# note that the source code (.py) is opened with universal newline mode
(filebase,ext)=os.path.splitext(m.__file__)
if ext.startswith(".PY"):
exts = ( (".PYO","rb"), (".PYC","rb"), (".PY","rU") ) # uppercase
else:
exts = ( (".pyo","rb"), (".pyc","rb"), (".py","rU") ) # lowercase
for ext,mode in exts:
try:
m=open(filebase+ext, mode).read()
return m # supply the module to the client!
except:
pass
Log.error("ObjBase","cannot read module source code for module:", name)
raise PyroError("cannot read module source code")
finally:
del importmodule
else:
Log.error("ObjBase","attempt to retrieve code denied:", name)
raise PyroError("attempt to retrieve code denied")
评论列表
文章目录