Utilities for twisted web
Project description
txwebutils - utilities for twisted.web
What is txwebutils
?
txwebutils
is a pure-python library containing various utility functions and implementations for the twisted.web
web framework. It is the result of combining useful code from my various other projects.
Features
- support for unicode string results for
twisted.web.resource.Resource.render_*
methods. - support for deferreds results for
twisted.web.resource.Resource.render_*
. - utility functions to get the URL parameters in unicode.
- A custom cross-site authentication implementation using
twisted.cred
.
Examples
# -*- coding: utf-8 -*-
"""
Example for @unicode_response.
The @unicode_response decorator allows both unicode and/or deferred results in render_* methods.
"""
from twisted.internet import defer
from twisted.web.resource import Resource
from txwebutils import unicode_response
class UnicodeRespondingResource(Resource):
"""
This resource serves a unicode string on a GET request.
@unicode_response tries its best to guess the encoding correctly.
"""
@unicode_response
def render_GET(self, request):
return u"This is a unicode string: äöüß"
class BinaryRespondingResource(Resource):
"""
This resource serves a binary string on a GET request.
This shows that you can return whatever string type you desire.
"""
@unicode_response
def render_GET(self, request):
return b"This is a binary string"
class DeferredResultingResource(Resource)
"""
This resource serves a deferred which fires with a unicode string on a GET request.
"""
@unicode_response
def render_GET(self, request):
return defer.succeed(u"This is a unicode string: äöüß")
class InlineCallbacksResource(Resource)
"""
This resource uses 'twisted.internet.defer.inlineCallbacks'
"""
@unicode_response
@defer.inlineCallbacks
def render_GET(self, request):
s = yield defer.succeed(u"This is a unicode string: äöüß")
defer.returnValue(s)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
txwebutils-0.0.1.tar.gz
(13.5 kB
view hashes)
Built Distribution
txwebutils-0.0.1-py2-none-any.whl
(17.3 kB
view hashes)
Close
Hashes for txwebutils-0.0.1-py2-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 06bf813f7b2a8886d47ba126bfb2e55a262f7bcd454935052c3586e51eceae9b |
|
MD5 | ee5b6aa947d555c93984ff2162e66e1a |
|
BLAKE2b-256 | 2cae5d4ca8a13fade3ca4baaadc098694a0f85595930f1c872c3705f168be489 |