[Python-Dev] Unexpected rexec behavior due to _sre

Charles G Waldman cgw@fnal.gov
Tue, 12 Sep 2000 13:47:31 -0500 (CDT)


Python 1.5.2 (#3, Feb 11 2000, 15:30:14)  [GCC 2.7.2.3.f.1] on linux2
Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
>>> import rexec
>>> r = rexec.RExec()
>>> r.r_exec("import re")
>>> 

Python 2.0b1 (#2, Sep  8 2000, 12:10:17) 
[GCC 2.95.2 19991024 (release)] on linux2
Type "copyright", "credits" or "license" for more information.
>>> import rexec
>>> r=rexec.RExec()
>>> r.r_exec("import re")

Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "/usr/lib/python2.0/rexec.py", line 253, in r_exec
    exec code in m.__dict__
  File "<string>", line 1, in ?
  File "/usr/lib/python2.0/rexec.py", line 264, in r_import
    return self.importer.import_module(mname, globals, locals, fromlist)
  File "/usr/lib/python2.0/ihooks.py", line 396, in import_module
    q, tail = self.find_head_package(parent, name)
  File "/usr/lib/python2.0/ihooks.py", line 432, in find_head_package
    q = self.import_it(head, qname, parent)
  File "/usr/lib/python2.0/ihooks.py", line 485, in import_it
    m = self.loader.load_module(fqname, stuff)
  File "/usr/lib/python2.0/ihooks.py", line 324, in load_module
    exec code in m.__dict__
  File "/usr/lib/python2.0/re.py", line 28, in ?
    from sre import *
  File "/usr/lib/python2.0/rexec.py", line 264, in r_import
    return self.importer.import_module(mname, globals, locals, fromlist)
  File "/usr/lib/python2.0/ihooks.py", line 396, in import_module
    q, tail = self.find_head_package(parent, name)
  File "/usr/lib/python2.0/ihooks.py", line 432, in find_head_package
    q = self.import_it(head, qname, parent)
  File "/usr/lib/python2.0/ihooks.py", line 485, in import_it
    m = self.loader.load_module(fqname, stuff)
  File "/usr/lib/python2.0/ihooks.py", line 324, in load_module
    exec code in m.__dict__
  File "/usr/lib/python2.0/sre.py", line 19, in ?
    import sre_compile
  File "/usr/lib/python2.0/rexec.py", line 264, in r_import
    return self.importer.import_module(mname, globals, locals, fromlist)
  File "/usr/lib/python2.0/ihooks.py", line 396, in import_module
    q, tail = self.find_head_package(parent, name)
  File "/usr/lib/python2.0/ihooks.py", line 432, in find_head_package
    q = self.import_it(head, qname, parent)
  File "/usr/lib/python2.0/ihooks.py", line 485, in import_it
    m = self.loader.load_module(fqname, stuff)
  File "/usr/lib/python2.0/ihooks.py", line 324, in load_module
    exec code in m.__dict__
  File "/usr/lib/python2.0/sre_compile.py", line 11, in ?
    import _sre
  File "/usr/lib/python2.0/rexec.py", line 264, in r_import
    return self.importer.import_module(mname, globals, locals, fromlist)
  File "/usr/lib/python2.0/ihooks.py", line 396, in import_module
    q, tail = self.find_head_package(parent, name)
  File "/usr/lib/python2.0/ihooks.py", line 439, in find_head_package
    raise ImportError, "No module named " + qname
ImportError: No module named _sre

Of course I can work around this by doing:

>>> r.ok_builtin_modules += '_sre',
>>> r.r_exec("import re")          

But I really shouldn't have to do this, right?  _sre is supposed to be
a low-level implementation detail.  I think I should still be able to 
"import re" in an restricted environment without having to be aware of
_sre.