Thanks for the report, Michael, this is certainly something for us to look into 
for the next release.

Martin

-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Michael Twomey
Sent: Friday, January 27, 2006 5:15 AM
To: [email protected]
Subject: [IronPython] Problems with exec

Hi,

I've started work on an ironpython implementation of the _socket
module so I can use standard python sockets. I was making good
progress until I hit a problem with socket.py's use of exec.

In the socket._socketobject class exec is used to create wrappers for
various methods in the socket class in _socket. When the code is run
you get an attributeerror because the exec statement hasn't set the
attributes on the class.

This example demonstrates the problem:

class MyRealObj(object):
    """The real object"""
    def foo(self):
        return "foo"

class MyObj(object):
    """The public wrapper"""
    def __init__(self):
        self.realobj = MyRealObj()

    #reproducing socket.py's exec statement
    _s = ("def %s(self, *args): return self.realobj.%s(*args)\n\n"
          "%s.__doc__ = MyRealObj.%s.__doc__\n")
    for _m in ["foo"]:
        exec _s % (_m, _m, _m, _m)
    del _m, _s

o = MyObj()
print o.foo()


Looking at it closer it appears that the foo method has been placed
into the module instead of the class, the socket module winds up with
the methods instead of the socket class. I suspect it's a case of
dealing with the locals a bit differently inside a class definition.

I'll have a go at fixing this but I'm still finding my way around the
ironpython code (I'm up to ops.cs and statements.cs).

cheers,
  Michael
_______________________________________________
users mailing list
[email protected]
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
_______________________________________________
users mailing list
[email protected]
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com

Reply via email to