在 OpenStack 中, 针对web应用, 有三种方法来写单元測试 1) 使用webob生成模拟的request from __future__ import print_function import webob import testtools def hello_world(env, start_response): if env['PATH_INFO'] ! class WsgiAppTestCase(testtools.TestCase): def test_hello_world_with_webob(self): resp = webob.Request.blank('/').get_response(hello_world) print("resp=%s" % (resp)) self.assertEqual
Pyramid中的request对象和response对象是基于WebOb包的(WebOb包是一个python库,对 WSGI 的request和response进行了封装)。 所以,传递给视图的request对象是pyramid.request.Request的一个实例,而pyramid.request.Request是 webob.Request的子类。 返回的response对象是pyramid.request.Response的一个实例,而pyramid.request.Response是 webob.Response的子类。
WebOb 可以帮助您编写更清晰、更简洁的 WSGI 应用程序。使用 WebOb 可以构建一个简单的 Web 应用程序,而无需使用 Django 或其他全功能框架。E. 如果您需要一个简单的 Web 应用程序,并且您不想使用全功能框架,那么可以使用 WSGI 和轻量级框架,例如 Werkzeug 和 Jinja2,或 WebOb,或 raw WSGI。G.
bin/env/python #coding=utf-8 from routes import Mapper from routes import middleware import webob.dec ','delete_many':'POST'}) self.route = middleware.RoutesMiddleware(self.dispatch,map) @webob.dec.wsgify def __call__(self,req): return self.route @staticmethod @webob.dec.wsgify 是webob为WSGI应用程序提供的一个装饰器,作用是将一个函数转换成一个WSGI应用。 参考资料 http://tumblr.wachang.net/post/38149417931/python-paste-webob-3 2)routes.middleware.RoutesMiddleware
本次主要依赖于两个库: WebOb库,用于封装wsgi的environ参数。 re库,使用正则表达式匹配URL中的路径。
If we try to audit __call__(), we can # run into troubles due to the @webob.dec.wsgify = context.project_id)): msg = _("Malformed request url") return Fault(webob.exc.HTTPBadRequest
一个类能够被调用就必须实现自身的call方法,所以接下来是查看Routers类的call方法的代码: class Routers(object): @wsgify(RequestClass=webob.Request (2) _dispatch方法 class Router(object); @staticmethod @wsgify(RequestClass=webob.Request 中虚拟机创建的相关内容作为例子,接着part two讲,查看Controller类的call方法: class Controller(object): @wsgify(RequestClass=webob.Request
import webob from webob import exc from nova.api.openstack import common from nova.api.openstack.compute.schemas
classPasteTest(object): @classmethod def factory(cls, global_config, **local_config): returncls() @webob.dec.wsgify (RequestClass=wsgi.Request) def _call_(self,req): response = webob.Response() response.body = "Hello 当然,限于多方面原因,这里并未讲解WSGI、webob、router等知识,大家可以参阅其他资料学习。如何扩展Neutron ML2资源,期待我们能在下一篇见面。
源码 06. web微型框架 前言 python web微型框架 实现功能: 解析请求和产生响应(基于WebOb
$ pip check pyramid 1.5.2 requires WebOb, which is not installed. 10.
$ pip check pyramid 1.5.2 requires WebOb, which is not installed. 10.
继续安装 Python 模块,安装完后进入 anki-sync-server 目录: $ pip3 install webob $ cd ..
建议使用 Werkzeug 和 WebOb 分别作为模块化的 WSGI 组件和请求/响应对象。如果需要模板,可以使用 Django Templates。
test_haproxy(int(args[1])) 三、服务端 # coding: utf-8 import random import eventlet from eventlet import wsgi from webob
3、实现一个简单的 WSGI Server 4、实现“高并发”的WSGI Server 5、第一次路由:PasteDeploy 6、PasteDeploy 使用说明 7、webob.dec.wsgify 7. webob.dec.wsgify 装饰器 经过了 PasteDeploy 的路由调度,我们找到了 nova.api.openstack.compute:APIRouterV21.factory 这个 而负责扒掉这层外衣的,就是其头上的装饰器 @webob.dec.wsgify ,wsgify 是一个类,其 __call__ 源码实现如下: ?
, PasteDeploy, pyparsing, pyramid, pyramid-chameleon, repoze.lru, six, translationstring, venusian, WebOb
TurboGears:TurboGears由Repoze,WebOb和Genshi等几个组件组成,并且基于MVC架构。这对于快速,高效的Web应用程序开发很有用,而且更易于维护。
The full-stack framework utilizes segments, for example, Genshi, Repoze, SQLAlchemy, and WebOb to effectively
TurboGears TurboGears是在几个著名的Python项目上构建起来的一个框架,如SQLAlchemy,WebOb,Repoze,Genshi。