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. solrJ 查询参数

    一. Query参数 1. CoreQueryParam查询的参数 1) q: 查询字符串,必须的. 2) q.op: 覆盖schema.xml的defaultOperator(有空格时用" ...

  2. pwnable.kr cmd2之write up

    来看一下源代码: #include <stdio.h> #include <string.h> int filter(char* cmd){ ; r += strstr(cmd ...

  3. 数据结构实验6:C++实现二叉树类

    实验6 学号:     姓名:      专业:   6.1 实验目的 掌握二叉树的动态链表存储结构及表示. 掌握二叉树的三种遍历算法(递归和非递归两类). 运用二叉树三种遍历的方法求解有关问题. 6 ...

  4. idea 神键

    http://blog.csdn.net/dc_726/article/details/42784275 idea 中几个十分酸爽的快捷键.

  5. jquery怎么获得ul中li的个数

  6. Computer (树形DP)

    A school bought the first computer some time ago(so this computer's id is 1). During the recent year ...

  7. 杭电ACM省赛集训队选拔赛之热身赛-How Many Tables,并查集模板题~~

    How Many Tables Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  8. Linux Bash对拍

    代码: #!/bin/bash while true; do ./rand > input //数据生成器 ./test < input > output //测试程序 ./std ...

  9. codeforces #301 div2

    A:简单题 每次判断向上转快,还是向下转快即可 #include <cstdio> #include <cstring> #include <iostream> # ...

  10. poj1091:跳蚤【容斥原理】

    题目大意:中文题就不翻译了 思路:假设跳蚤选择X1个第一张卡片,X2个第二张卡片...Xn个第n张卡片,Xn+1张写着m的卡片,那么就可以列出方程:a1*X1+a2*X2+…+an*Xn+m*X(n+ ...