Hi Fred, Thanks for reporting the issue. I'll added a github issue for this.
https://github.com/webpy/webpy/issues/81 I think right way to fix it to write those extra classes manually. I don't think we should add a python24.py. Can you implement that and send a pull request? Anand 2011/7/7 Fred Ludlow <[email protected]>: > Hi all, > > I've been using web.py to make a RESTful JSON API for some web applications > I'm working on. So far it's been great, very nice intuitive API and doesn't > take much code to do what you want. > > I've come across a small bug with web.py on python 2.4 (which is what I'm > stuck with for the forseeable future). > > The following works fine: > > class Handler1(object): > def GET(): > raise web.Redirect('/someotherurl') > > but this: > > class Handler2(object): > def GET(): > raise web.Forbidden() > > fails with the message: > > TypeError: exceptions must be classes, instances, or strings (deprecated), > not Forbidden > > I'm pretty sure this is because in python 2.4 the Exception class is a > classic-style class, rather than a new-style class and Python 2.4 won't let > you raise a new-style class instance. Looking in web.webapi, some of the > status codes (Redirect, Found, SeeOther, Gone) are defined using the class > statement which gies you a classic-style class, and others (Forbidden, OK, > Created) are generated dynamically using type(name, bases, dict), which > gives a new-style class. > > I know I can just return an instance of web.Forbidden rather than raising > it, but this gets complicated once your GET function starts calling any > other methods (you have to check what they return, or use some kind of proxy > Exception class). I'm also using the handy mimerender package to decorate my > GETs, PUTs etc, and that expects GET to return a very specific type of > object (dict with something stored in 'message'), besides, conceptually, > raising an exception makes the most sense here. > > One way of fixing this would be to define the Forbidden class using the > class statement, but that involves some extra manual class definitions in > web.webapi, just to fix it for an old version of python. Perhaps a > web.python24 submodule that only gets imported if running 2.4 and overwrites > web.Forbidden, etc with classic-style classes might be the best way to do > it? If this sounds sensible I'd be happy to write it, or is there a better > way round the problem? > > Cheers, > > Fred > > -- > You received this message because you are subscribed to the Google Groups > "web.py" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]. > For more options, visit this group at > http://groups.google.com/group/webpy?hl=en. > -- You received this message because you are subscribed to the Google Groups "web.py" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/webpy?hl=en.
