扭网实用程序
txwebutils的Python项目详细描述
txwebutils-用于twisted.web
的实用程序
什么是txwebutils
?在
txwebutils
是一个纯python库,包含twisted.web
web框架的各种实用函数和实现。它是将我的其他项目中的有用代码组合在一起的结果。在
特点
- 对
twisted.web.resource.Resource.render_*
方法的unicode字符串结果的支持。在 - 支持
twisted.web.resource.Resource.render_*
的延迟结果。在 - 获取unicode格式的URL参数的实用程序函数。在
- 使用
twisted.cred
的自定义跨站点身份验证实现。在
示例
# -*- coding: utf-8 -*-"""Example for @unicode_response.The @unicode_response decorator allows both unicode and/or deferred results in render_* methods."""fromtwisted.internetimportdeferfromtwisted.web.resourceimportResourcefromtxwebutilsimportunicode_responseclassUnicodeRespondingResource(Resource):""" This resource serves a unicode string on a GET request. @unicode_response tries its best to guess the encoding correctly. """@unicode_responsedefrender_GET(self,request):returnu"This is a unicode string: äöüß"classBinaryRespondingResource(Resource):""" This resource serves a binary string on a GET request. This shows that you can return whatever string type you desire. """@unicode_responsedefrender_GET(self,request):returnb"This is a binary string"classDeferredResultingResource(Resource)""" This resource serves a deferred which fires with a unicode string on a GET request. """@unicode_responsedefrender_GET(self,request):returndefer.succeed(u"This is a unicode string: äöüß")classInlineCallbacksResource(Resource)""" This resource uses 'twisted.internet.defer.inlineCallbacks' """@unicode_response@defer.inlineCallbacksdefrender_GET(self,request):s=yielddefer.succeed(u"This is a unicode string: äöüß")defer.returnValue(s)
- 项目
标签: