Created
October 26, 2011 14:51
-
-
Save jamesgecko/1316583 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from twisted.web.server import Site | |
| from twisted.web.resource import Resource, IResource | |
| from twisted.internet import reactor, task | |
| class Customer(Resource): | |
| def __init__(self, customer_id=100): | |
| Resource.__init__(self, customer_id) | |
| self.customer_id = customer_id | |
| def render_GET(self, request): | |
| return 'hello %s' % str(self.customer_id) | |
| class Customers(Resource): | |
| def getChild(self, path, request): | |
| return Customer(path) | |
| class Root(Resource): | |
| def __init__(self): | |
| Resource.__init__(self) | |
| def getChildWithDefault(self, path, request): | |
| authenticated = False | |
| if authenticated: | |
| Resource.getChildWithDefault(self, path, request) | |
| else: | |
| empty_resource = IResource(self) | |
| request.setResponseCode(401) | |
| print dir(request) | |
| request.write('error<br> ') | |
| if not request.finished: | |
| pass | |
| #request.finish() | |
| return empty_resource | |
| def render_GET(self, request): | |
| return 'get' | |
| def main(): | |
| root = Root() | |
| root.putChild('customer', Customers()) | |
| factory = Site(root) | |
| reactor.listenTCP(80, factory) | |
| reactor.run() | |
| if __name__ == '__main__': | |
| main() | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| http://localhost/ | |
| error | |
| get | |
| http://localhost/foo | |
| error | |
| get | |
| http://localhost/customer/100 | |
| error | |
| error | |
| get | |
| http://localhost/foo/foo/foo/foo | |
| error | |
| error | |
| error | |
| error | |
| get |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment