[IronPython] CherryPy 3 on top of IronPython 1.0... kind of working

Sylvain Hellegouarch sh at defuze.org
Wed Sep 6 00:18:03 CEST 2006


First congratulations for the fantastic work you have done with IronPython.

Tested against:
IP 1.0 (binaries)
CP 3 (recent svn trunk)
Python 2.4.3
.NET 2 on Windows XP (yeah my Linux system broke down...)

Tonight I was trying to run CherryPy 3 [1](which will reach its first 
beta really soon but which is already extremely stable) with IronPython 
1.0 and it kind of worked. I say kind of because of the following reasons:

1. It won't work from without hacking CherryPy's code. Considering the 
fact CP does some internal stuff using not (yet?) supported CPython 
functionnalities it is not a surprise.
    a. First string.encode('hex') is not implemented so:

 >>> import sys
 >>> sys.path.append('c:\python24\lib')
 >>> import os
 >>> os.urandom(20).encode('hex')
Traceback (most recent call last):
  File , line 0, in <stdin>##46
  File , line 0, in Encode##48
LookupError: unknown encoding: hex

The session module of CherryPy uses by default that method to generate 
fairly decent random IDs. There is a fallback by using:

sha.new('%s' % random.random()).hexdigest()

instead. It works fine when you fetch Seo Sanghyeon's sha.py module from 

   b. Next CherryPy uses in some areas the inspect module as follow:
 >>> import inspect
 >>> def f(): pass
 >>> inspect.getargspec(f)[0]
Traceback (most recent call last):
  File , line 0, in <stdin>##84
  File c:\python24\lib\inspect.py, line 678, in getargspec
  File c:\python24\lib\inspect.py, line 616, in getargs
  File , line 0, in get_Code##86

That exception was not catched by CP, after added it to _cptools.py it 
worked better :)

   c. CherryPy uses the signal module which is not part of IP. I simply 
modified the import as follow in _cpengine.py
    import signal
    signal = None

  d. CP uses the logging module from the CPython stdlib which does not 
seem to work properly in IP because it uses the _getframe function.
I simply commented out two lines in _cplogging.py to not access the 
logging module. To keep a trace of the request I just print them to 
stdout. :)

  e. Finally because the default IP socket implementation does not 
support makefile, I had to use Seo's socket.py module in lieu. To avoid 
collision and because I did not want to recompile IP, I modified the 
import from _cpwsgiserver.py as follow:

import ipsocket as socket

ipsocket is just the name of the file under which I saved Seo's module. 
Could be Alf.py if you wanted to :)

2. After all those modification, I was able to start up the server like 
import sys
# contains CherryPy
# misc is just a directory containing Seo's module sha.py, ipsocket.py 
and ssl.py
import cherrypy
class Root:
    def index(self):
        return "Hello"
    # this could be set as a decorator @cherrypy.expose but this won't 
work I think from IP
    index.exposed = True

[05/Sep/2006:23:00:11] HTTP Serving HTTP on http://localhost:8080/

3. Now the fun part.
The server does show it received and treats requests from Firefox 1.5, 
InternetExplorer 6 and httplib2 [3] a Python module for HTTP  requests 
handling  from CPython. However only in IE and httplib2 I was able to 
view/read the response content. Fx was hanging with no real reason, 
whether I used network.http.pipelining or not.

So here we are, it kind of worked but it's far from being smooth yet. 
It's better than a few months ago however and there is less issues. 
Maybe this email will help fixing some issues and improve the situation 
even more. I would be very interested in making this work as I intend to 
run my little Atom Publishing Protocol implementation in Python using CP 
through IP.

You can download the files from:

Simply add the directory you will unzip to sys.path

- Sylvain

[1]: http://svn.cherrypy.org/trunk/
[2]: http://sparcs.kaist.ac.kr/~tinuviel/fepy/lib/
[3]: http://bitworking.org/projects/httplib2/

More information about the Ironpython-users mailing list