from wsgiref.util import setup_testing_defaults, request_uri
from wsgiref.simple_server import make_server # A relatively simple WSGI application. It's going to print out the
# environment dictionary after being updated by setup_testing_defaults
def simple_app(environ, start_response):
setup_testing_defaults(environ) status = '200 OK'
headers = [('Content-type', 'text/plain; charset=utf-8')] start_response(status, headers)
r_uri = request_uri(environ, include_query=True)
if 'test_dump' in r_uri:
return [("%s: %s\n" % (key, value)).encode('utf-8') for key, value in environ.items()]
elif 'uid' in r_uri: try:
uid = int(r_uri.split('/')[-1])
if uid > 0:
r_l = gen_r(uid)
return [("%s: %s\n" % (i, r_l[i])).encode('utf-8') for i in range(len(r_l))]
else:
return [('%s%s' % ('BAD-REQUEST ', r_uri)).encode('utf-8')]
except Exception as e:
return [('%s%s%s' % (e, ' retry...,please.... ', r_uri)).encode('utf-8')]
else:
return [('%s%s' % ('dev-ING- ', r_uri)).encode('utf-8')] with make_server('', 8000, simple_app) as httpd:
print("Serving on port 8000...")
httpd.serve_forever()

wsgiref — WSGI Utilities and Reference Implementation nginx的更多相关文章

  1. Hibernate Validator 6.0.9.Final - JSR 380 Reference Implementation: Reference Guide

    Preface Validating data is a common task that occurs throughout all application layers, from the pre ...

  2. django自带wsgi server vs 部署uwsgi+nginx后的性能对比

    一.下面先交代一下测试云主机 cpu: root@alexknight:/tmp/webbench-1.5# cat /proc/cpuinfo |grep model model : model n ...

  3. python常用函数 库 转

    可能经常用到的标准模块和第三方常用的50个库 本文由python培训班授课老师整理 数学计算:     numbers - Numeric abstract base classes     math ...

  4. Python教程大纲

    缘起:最近想在部门推Python语言,写这个blog主要就是个教程大纲,之前先列出一些资源:Python历史:http://www.docin.com/p-53019548.html          ...

  5. #######【Python】【基础知识】【标准库】目录及学习规划 ######

    下述参考Python DOC https://docs.python.org/zh-cn/3/library/index.html 概述 可用性注释 内置函数 内置常量 由 site 模块添加的常量 ...

  6. The Python Standard Library

    The Python Standard Library¶ While The Python Language Reference describes the exact syntax and sema ...

  7. nginx,wsgi,flask之间的关系

    之前看写flask 应用的一些疑问,百度上的答案解释的不错,这里记着以后可以看看Web 服务器层对于传统的客户端 - 服务器架构,客户端向服务器发送请求,服务器接收请求,处理请求,最后给客户端返回请求 ...

  8. 如何理解Nginx, WSGI, Flask之间的关系

    概览 之前对 Nginx,WSGI(或者 uWSGI,uwsgi),Flask(或者 Django),这几者的关系一存存在疑惑.通过查阅了些资料,总算把它们的关系理清了. 总括来说,客户端从发送一个 ...

  9. 如何理解Nginx, WSGI, Flask(Django)之间的关系

    如何理解Nginx, WSGI, Flask(Django)之间的关系 值得指出的是,WSGI 是一种协议,需要区分几个相近的名词: uwsgi 同 wsgi 一样也是一种协议,uWSGI服务器正是使 ...

随机推荐

  1. python基础知识10-描述器和装饰器

    课前的解答 1.vim怎么退出都知道吧,配置了pep8,所以说会出现退出的时候error,再退出一次就ok q:退出 w:保存 wq 保存退出 q!:强制退出 shift + zz:保存退出 x:保存 ...

  2. scrapy yield 回调函数不执行解决方案

    yield Request(url=parse.urljoin(response.url, p_url),callback=self.parse_detail) 回调函数不执行: 加上: dont_f ...

  3. 【C#】【数据结构】005-栈:顺序栈

    C#数据结构:顺序栈 1.自定义顺序栈结构: /// <summary> /// 顺序栈 /// </summary> /// <typeparam name=" ...

  4. manjaro xfce 18.0 踩坑记录

    manjaro xfce 18.0 踩坑记录 1 简介1.1 Manjaro Linux1.2 开发桌面环境2 自动打开 NumLock3 系统快照3.1 安装timeshift3.2 使用times ...

  5. Android开发——短信电话拦截/接听电话

    1.短信拦截 首先需要声明的是,Android4.4版本以上,如果想做到短信拦截,必须成为default sms,把所有短信相关的功能都包揽了,然后再做短信拦截.但这种做法,适配性和兼容性的工作是非常 ...

  6. 『NYIST』第八届河南省ACM竞赛训练赛[正式赛一]CF-236B. Easy Number Challenge

    B. Easy Number Challenge time limit per test 2 seconds memory limit per test 256 megabytes input sta ...

  7. FZU2206函数求解

    Problem 2206 函数求解 Accept: 154    Submit: 456 Time Limit: 1000 mSec    Memory Limit : 32768 KB  Probl ...

  8. LeetCode:不同路径&不同路径II

    不同路径一个机器人位于一个 m x n 网格的左上角 (起始点在下图中标记为“Start” ). 机器人每次只能向下或者向右移动一步.机器人试图达到网格的右下角(在下图中标记为“Finish”). 问 ...

  9. CF671D:Roads in Yusland

    n<=300000个点的树,给m<=300000条带权路径(ui,vi,保证vi是ui的祖先)求覆盖整棵树每条边的最小权和. 好题好姿势!直观的看到可以树形DP,f[i]表示把点i包括它爸 ...

  10. C++,C程序设计入门——《高质量程序设计第4章》

    1. 连接规范 1. extern “C” 2. 一部分采用C的连接规范 #ifdef __cplusplus extern "C" { #endif #ifdef __cplus ...