配合
http://www.python.org/dev/peps/pep-0333/
http://pythonpaste.org/deploy/
看下面的example(从网络上改造而来,出处URL也搞忘记的),很快会对python的paste如何组织wsgi有一个简单的了解,
pastedeploylab.ini
[DEFAULT]
key1=value1
key2=value2
key3=values
[composite:pdl]
use=egg:Paste#urlmap
/:root
/calc:calc
[filter:logrequest]
username = root
password = root123
paste.filter_factory = pastedeploylab:LogFilter.factory
[filter:testrequest]
username = admin
password = admin
paste.filter_factory = pastedeploylab:TestFilter.factory
[app:calculator]
description = This is an "+-*/" Calculator
paste.app_factory = pastedeploylab:Calculator.factory
[app:showversion]
version = 1.0.0
paste.app_factory = pastedeploylab:ShowVersion.factory
[pipeline:root]
pipeline = logrequest testrequest showversion
[pipeline:calc]
pipeline = logrequest calculator
pastedeployed.py
import os
import webob
from webob import Request
from webob import Response
from paste.deploy import loadapp
from wsgiref.simple_server import make_server
#Filter
class LogFilter():
def __init__(self,app):
self.app = app
def __call__(self,environ,start_response):
print "filter:LogFilter is called."
return self.app(environ,start_response)
@classmethod
def factory(cls, global_conf, **kwargs):
print "in LogFilter.factory", global_conf, kwargs
return LogFilter
class TestFilter():
def __init__(self,app):
self.app = app
def __call__(self,environ,start_response):
print "filter:TestFilter is called."
return self.app(environ,start_response)
@classmethod
def factory(cls, global_conf, **kwargs):
print "in TestFilter.factory", global_conf, kwargs
return TestFilter
class ShowVersion():
def __init__(self):
pass
def __call__(self,environ,start_response):
start_response("200 OK",[("Content-type", "text/plain")])
return ["Paste Deploy LAB: Version = 1.0.0",]
@classmethod
def factory(cls,global_conf,**kwargs):
print
print "in ShowVersion.factory:"
print "global_conf=", global_conf
print "kwargs =", kwargs
return ShowVersion()
class Calculator():
def __init__(self):
pass
def __call__(self,environ,start_response):
req = Request(environ)
res = Response()
res.status = "200 OK"
res.content_type = "text/plain"
# get operands
operator = req.GET.get("operator", None)
operand1 = req.GET.get("operand1", None)
operand2 = req.GET.get("operand2", None)
print req.GET
opnd1 = int(operand1)
opnd2 = int(operand2)
if operator == u'plus':
opnd1 = opnd1 + opnd2
elif operator == u'minus':
opnd1 = opnd1 - opnd2
elif operator == u'star':
opnd1 = opnd1 * opnd2
elif operator == u'slash':
opnd1 = opnd1 / opnd2
res.body = "%s /nRESULT= %d" % (str(req.GET) , opnd1)
return res(environ,start_response)
@classmethod
def factory(cls,global_conf,**kwargs):
print "in Calculator.factory", global_conf, kwargs
return Calculator()
if __name__ == '__main__':
configfile="pastedeploylab.ini"
appname="pdl"
wsgi_app = loadapp("config:%s" % os.path.abspath(configfile), appname)
server = make_server('localhost',8989,wsgi_app)
server.serve_forever()
分享到:
相关推荐
官方离线安装包,亲测可用
官方离线安装包,亲测可用
主要介绍了PIL图像处理模块paste方法简单使用详解,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
官方离线安装包,亲测可用。使用rpm -ivh [rpm完整包名] 进行安装
主要介绍了python图片指定区域替换img.paste函数的使用,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
python库,解压后可用。 资源全名:Paste-0.9.6-py2.3.egg
python库,解压后可用。 资源全名:Paste-1.0.1-py2.4.egg
Paste
python库。 资源全名:minitage.paste-1.3.162.zip
我先下载了anaconda安装,然后在里面打开Jupyter notebook,里面有一行说到Copy/paste this URL into your browser when you connect for the first time, to login with a token: http://........。
python库。 资源全名:minitage.paste-0.0.1-alpha37.zip
python库。 资源全名:minitage.paste-0.0.1-alpha32.zip
可以用js给页面中的元素绑定paste事件的方法,当用户鼠标在该元素上或者该元素处于focus状态,绑定到paste事件的方法就运行了。 绑定的元素不一定是input,普通的div也是可以绑定的,如果是给docume
资源分类:Python库 所属语言:Python 资源全名:minitage.paste-1.3.119.zip 资源来源:官方 安装方法:https://lanzao.blog.csdn.net/article/details/101784059
18更新最新版,Paste for Mac 中文破解版,下载解压zip文件,dmg文件双击安装无需注册码即可使用
A real-time lightweight object detector ...Copy the contents of the file deploy.prototx and paste it into http://ethereon.github.io/netscope/#/editor. Then Use Shift+Enter to update the visualization.
离线安装包,亲测可用
python库。 资源全名:django_paste-1.0.0-py3-none-any.whl
3.Config.ini配置项说明: DiskSize:磁盘大小(B) BlockSize:磁盘每块大小(B) HeaderSize:文件系统大小(B) BitMapSize:位图大小(B) 4.本程序完成以下功能 A.创建文件 B.创建文件夹 C.打开 D.编辑 E....