Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/steiza/txroutes
Provides routes-like dispatching for twisted.web.server
https://github.com/steiza/txroutes
Last synced: 3 months ago
JSON representation
Provides routes-like dispatching for twisted.web.server
- Host: GitHub
- URL: https://github.com/steiza/txroutes
- Owner: steiza
- License: mit
- Created: 2010-11-15T01:56:13.000Z (about 14 years ago)
- Default Branch: main
- Last Pushed: 2022-03-28T22:10:16.000Z (almost 3 years ago)
- Last Synced: 2023-03-11T11:47:21.972Z (almost 2 years ago)
- Language: Python
- Homepage:
- Size: 10.7 KB
- Stars: 10
- Watchers: 3
- Forks: 10
- Open Issues: 0
-
Metadata Files:
- Readme: README.rst
- License: LICENSE
Awesome Lists containing this project
README
Note
====This is a legacy project! For the most up-to-date version check out: https://github.com/olark/txroutes
txroutes
========txroutes provides routes-like dispatching for twisted.web.server (it actually
depends upon the Python routes codebase).Frequently, it's much easier to describe your website layout using routes
instead of Resource from twisted.web.resource. This small library lets you
dispatch with routes in your twisted.web application.Usage
-----Here is an example of how to use txroutes::
from twisted.internet import reactor, task
from twisted.web.server import Site, NOT_DONE_YETfrom txroutes import Dispatcher
# Create a Controller
class Controller(object):def index(self, request):
return 'Hello World!'def docs(self, request, item):
return 'Docs for %s' % item.encode('utf8')def post_data(self, request):
return 'OK'def deferred_example(self, request):
request.write('Wait a tic...')
task.deferLater(reactor, 5, lambda: request.finish())return NOT_DONE_YET
c = Controller()
dispatcher = Dispatcher()
dispatcher.connect(name='index', route='/', controller=c, action='index')
dispatcher.connect(name='docs', route='/docs/{item}', controller=c,
action='docs')dispatcher.connect(name='data', route='/data', controller=c,
action='post_data', conditions=dict(method=['POST']))dispatcher.connect(name='deferred_example', route='/wait', controller=c,
action='deferred_example')factory = Site(dispatcher)
reactor.listenTCP(8000, factory)
reactor.run()License
-------
txroutes is released under the `MIT License`____ http://opensource.org/licenses/MIT
Additional Information
----------------------
- Python routes: http://routes.groovie.org/
- Using twisted.web.resources: http://twistedmatrix.com/documents/current/web/howto/web-in-60/dynamic-dispatch.html