[Twisted-Python] factory class has no __class__ attribute!

L. Daniel Burr ldanielburr at mac.com
Thu Mar 1 08:53:20 MST 2007


Hi John,

On Thu, 01 Mar 2007 09:37:41 -0600, John Pote <johnpote at jptechnical.co.uk>  
wrote:

[SNIP]

> source code
> import sys
> from twisted.web import http
>
> class httpRequests(http.Request):
>     pages = {
>         '/':    '<h1>Home</h1>Home page',
>         '/test':'<h1>Test</h1>Test page',
>         }
>     def process(s):
>         if s.pages.has_key(s.path):
>             s.write(s.pages[s.path])
>         else:
>             s.setResponseCode(http.NOT_FOUND)
>             s.write("<h1>Not Found!</h1>Sorry, no such page.")
>         s.finish()
>
>
> class httpProtocol(http.HTTPChannel):
>     requestFactory = httpRequests
>
> class myhttpFactory(http.HTTPFactory):
>     protocol = httpProtocol
>
>
> if __name__ == "__main__":
>     from twisted.internet import reactor
>     from twisted._version import version
>     print "twisted ver:"+version.short()
>     print "python ver:"+sys.version
>
>     reactor.listenTCP(8000, myhttpFactory)
                               ^^^^^^^^^^^^^
You have to pass an *instance* of myhttpFactory,
not the class itself.

Hope this helps,

L. Daniel Burr




More information about the Twisted-Python mailing list