[IronPython] CherryPy on IronPython up but not running

Predrag Radovic predrg at gmail.com
Tue May 9 01:51:21 CEST 2006


Hello Seo,

I tried to start CherryPy 2.1.0 on the Windows with .NET 2.0 runtime and
IronPython 1.0 Beta 6. After tweaking here and there, adding few stub
modules (like datetime, sha, zlib) and using your excellent socket.py
replacement module, the most basic example (tut01_helloworld.py) works but
has to be modified.

First major problem is that IronPython apparently doesn't support assigning
attributes to (un)bounded methods. For example,

>>> class A:
...   def f(self): pass
...   f.test = 123
...
>>> A.f
<unbound method A.f>
>>> A.f.test
Traceback (most recent call last):
  File , line 0, in input##5
AttributeError: 'instancemethod' object has no attribute 'test'
>>> a=A()
>>> a.f
<bound method instance.f of <__main__.A instance at 0x000000000000002B>>
>>> a.f.test
Traceback (most recent call last):
  File , line 0, in input##8
AttributeError: 'instancemethod' object has no attribute 'test'

This is working in CPython:

>>> class A:
...   def f(self): pass
...   f.test = 123
...
>>> A.f
<unbound method A.f>
>>> A.f.test
123
>>> a=A()
>>> a.f
<bound method A.f of <__main__.A instance at 0x008F1A58>>
>>> a.f.test
123
>>>

This is how I modified tut01_helloworld.py. I doubt this is feasible
approach for other already developed code which uses CherryPy.

class Index:
  def __call__(self):
    print 'Index',self # we don't have access and any idea of existance of
HelloWorld... another problem I guess
    return "<html><body>Hello world!</body></html>\n\n"

class HelloWorld:
    """ Sample request handler class. """

    index = Index()

    #def index(self):
    #    # CherryPy will call this method for the root URI ("/") and send
    #    # its return value to the client. Because this is tutorial
    #    # lesson number 01, we'll just send something really simple.
    #    # How about...
    #    return "Hello world!\n\n"

    # Expose the index method through the web. CherryPy will never
    # publish methods that don't have the exposed attribute set to True.
    index.exposed = True
 
Solution for the second problem is easy, in your socket.py:

def makefile(self, mode='r', bufsize=-1):
        stream = NetworkStream(self.socket)
        return file(stream) # -> file(stream, mode+'b') # it must be binary
because '\r's will be duplicated in the HTTP response

Hope this helps a bit,
Predrag




More information about the Ironpython-users mailing list