recursive __getattr__ under rexec

Richard West rwest at opti.cgi.net
Thu Oct 25 22:20:23 EDT 2001


I'm trying to get xml support running in a restricted execution
environment.  I've run into a perplexing problem in the minidom
module.  Seems as though the __getattr__ is calling itself..  This
doesn't seem to be the normal behavior under a non-restricted
execution environment.  I'm running Python 2.1.1.  Here's my test
code:


import sys
import rexec
import string

def main():
    code = string.join([
        """import string""",
        """import xml.dom.minidom""",
        """test_xml = string.join([""",
        """    '<?xml version="1.0"?>',""",
        """    '<test>',""",
        """    '<user>test</user>',""",
        """    '<pass>password</pass>',""",
        """    '<tests>',""",
        """    '    <atest>123</atest>',""",
        """    '    <atest>456</atest>',""",
        """    '</tests>',""",
        """    '</test>',""",
        """    ],'\\n')""",
        """dom = xml.dom.minidom.parseString(test_xml)""",
        ],'\n')
    r = test_rexec()
    r.r_exec(code)


class test_rexec(rexec.RExec):
    ok_sys_names = (
        'ps1', 'ps2', 'copyright', 'version',
        'platform', 'exit', 'maxint', 'stdout',
        'stderr')

    def load_dynamic(self, name, filename, file):
        if sys.modules.has_key(name):
            src = sys.modules[name]
        else:
            import imp
            src = imp.load_dynamic(name, filename, file)
        dst = self.copy_except(src, [])
        return dst


main()



Here's the traceback:

Traceback (most recent call last):
  File "test3.py", line 43, in ?
    main()
  File "test3.py", line 24, in main
    r.r_exec(code)
  File "rexec.py", line 264, in r_exec
    exec code in m.__dict__
  File "<string>", line 14, in ?
  File "/usr/local/lib/python2.1/xml/dom/minidom.py", line 915, in
parseString
    return _doparse(pulldom.parseString, args, kwargs)
  File "/usr/local/lib/python2.1/xml/dom/minidom.py", line 902, in
_doparse
    toktype, rootNode = events.getEvent()
  File "/usr/local/lib/python2.1/xml/dom/pulldom.py", line 234, in
getEvent
    self.parser.feed(buf)
  File "/usr/local/lib/python2.1/xml/sax/expatreader.py", line 87, in
feed
    self._parser.Parse(data, isFinal)
  File "/usr/local/lib/python2.1/xml/sax/expatreader.py", line 178, in
start_element_ns
    AttributesNSImpl(newattrs, {}))
  File "/usr/local/lib/python2.1/xml/dom/pulldom.py", line 75, in
startElementNS
    node = self.buildDocument(None, localname)
  File "/usr/local/lib/python2.1/xml/dom/pulldom.py", line 174, in
buildDocument
    return node.firstChild
  File "/usr/local/lib/python2.1/xml/dom/minidom.py", line 58, in
__getattr__
    if self.__dict__.has_key("inGetAttr"):
  File "/usr/local/lib/python2.1/xml/dom/minidom.py", line 56, in
__getattr__
    raise AttributeError, key
AttributeError: __dict__



The test code works just fine outside of the restricted execution
environment.  Have I missed something obvious?


-Richard





More information about the Python-list mailing list