Python——Baseequestandler class (Interesting found in python‘s document)

class BaseHTTPRequestHandler(socketserver.StreamRequestHandler)

HTTP request handler base class.
 |  
 |  The following explanation of HTTP serves to guide you through the
 |  code as well as to expose any misunderstandings I may have about
 |  HTTP (so you don‘t need to read the code to figure out I‘m wrong
 |  :-).
 |  
 |  HTTP (HyperText Transfer Protocol) is an extensible protocol on
 |  top of a reliable stream transport (e.g. TCP/IP).  The protocol
 |  recognizes three parts to a request:
 |  
 |  1. One line identifying the request type and path
 |  2. An optional set of RFC-822-style headers
 |  3. An optional data part
 |  
 |  The headers and data are separated by a blank line.
 |  
 |  The first line of the request has the form
 |  
 |  <command> <path> <version>
 |  
 |  where <command> is a (case-sensitive) keyword such as GET or POST,
 |  <path> is a string containing path information for the request,
 |  and <version> should be the string "HTTP/1.0" or "HTTP/1.1".
 |  <path> is encoded using the URL encoding scheme (using %xx to signify
 |  the ASCII character with hex code xx).
 |  
 |  The specification specifies that lines are separated by CRLF but
 |  for compatibility with the widest range of clients recommends
 |  servers also handle LF.  Similarly, whitespace in the request line
 |  is treated sensibly (allowing multiple spaces between components
 |  and allowing trailing whitespace).
 |  
 |  Similarly, for output, lines ought to be separated by CRLF pairs
 |  but most clients grok LF characters just fine.
 |  
 |  If the first line of the request has the form

|  <command> <path>
 |  
 |  (i.e. <version> is left out) then this is assumed to be an HTTP
 |  0.9 request; this form has no optional headers and data part and
 |  the reply consists of just the data.
 |  
 |  The reply form of the HTTP 1.x protocol again has three parts:
 |  
 |  1. One line giving the response code
 |  2. An optional set of RFC-822-style headers
 |  3. The data
 |  
 |  Again, the headers and data are separated by a blank line.
 |  
 |  The response code line has the form
 |  
 |  <version> <responsecode> <responsestring>
 |  
 |  where <version> is the protocol version ("HTTP/1.0" or "HTTP/1.1"),
 |  <responsecode> is a 3-digit response code indicating success or
 |  failure of the request, and <responsestring> is an optional
 |  human-readable string explaining what the response code means.
 |  
 |  This server parses the request and the headers, and then calls a
 |  function specific to the request type (<command>).  Specifically,
 |  a request SPAM will be handled by a method do_SPAM().  If no
 |  such method exists the server sends an error response to the
 |  client.  If it exists, it is called with no arguments:
 |  
 |  do_SPAM()
 |  
 |  Note that the request name is case sensitive (i.e. SPAM and spam
 |  are different requests).
 
 |  The various request details are stored in instance variables:
 |  
 |  - client_address is the client IP address in the form (host,
 |  port);
 |  
 |  - command, path and version are the broken-down request line;
 |  
 |  - headers is an instance of email.message.Message (or a derived
 |  class) containing the header information;
 |  
 |  - rfile is a file object open for reading positioned at the
 |  start of the optional input data part;
 |  
 |  - wfile is a file object open for writing.
 |  
 |  IT IS IMPORTANT TO ADHERE TO THE PROTOCOL FOR WRITING!
 |  
 |  The first thing to be written must be the response line.  Then
 |  follow 0 or more header lines, then a blank line, and then the
 |  actual data (if any).  The meaning of the header lines depends on
 |  the command executed by the server; in most cases, when data is
 |  returned, there should be at least one header line of the form
 |  
 |  Content-type: <type>/<subtype>
 |  
 |  where <type> and <subtype> should be registered MIME types,
 |  e.g. "text/html" or "text/plain".
 |  
 |  Method resolution order:
 |      BaseHTTPRequestHandler
 |      socketserver.StreamRequestHandler
 |      socketserver.BaseRequestHandler
 |      builtins.object

时间: 2024-10-25 05:34:33

Python——Baseequestandler class (Interesting found in python‘s document)的相关文章

&lt;转&gt;Python 参数知识(变量前加星号的意义)

csdn上的牛人就是多,加油 —————————————————————————— 过量的参数 在运行时知道一个函数有什么参数,通常是不可能的.另一个情况是一个函数能操作很多对象.更有甚者,调用自身的函数变成一种api提供给可用的应用. 对于这些情况,python提供了两种特别的方法来定义函数的参数,允许函数接受过量的参数,不用显式声明参数.这些“额外”的参数下一步再解释. 注意args和kwargs只是python的约定.任何函数参数,你可以自己喜欢的方式命名,但是最好和python标准的惯用

python之路(sed,函数,三元运算)

python之路(sed,函数,三元运算) 一.sed集合 1.set无序,不重复序列 2.创建 1 se = {11,22,33,33,44} 2 list() #只要是一个类加上()自动执行 list __init__ 3 list = [11,22] 4 5 s1 = set(list) 6 print(s1) 7 8 #创建集合 9 s1 = {11,22} 10 s2 = set('可循环的') 11 12 #操作集合 13 s = set() 14 print(s) 15 s.add

Python之禅(原文、中文翻译、解释)

The Zen of Python, by Tim Peters Beautiful is better than ugly. Explicit is better than implicit. Simple is better than complex. Complex is better than complicated. Flat is better than nested. Sparse is better than dense. Readability counts. Special

Python练习题8(替换相同的字符串并输出):输入两个字母串,将两个字母串都包含的字母用&#39;_&#39;替换后,输出两个字母串的剩余部分 (不能为空串,区别大小写,只能包含字母)

方法一:检查输入是否为空串,循环字母串,相同的则替换,然后再用replace()方法去除,输出想要的结果 1 def str_replace(messages1,messages2): 2 if messages1.strip() == '' or messages2.strip() == '' : #检验输入不能为空串 3 tips = "输入字母串有空串,不合法" 4 return tips 5 6 if not messages1.encode('UTF-8').strip().

python学习笔记(模块、包、标准库)

模块 前面有简单介绍如何使用import从外部模块获取函数并且为自己的程序所用: >>> import math>>> math.sin(0)0.0>>> 模块是程序 任何python程序都可以作为模块导入.假设写如下程序,并且将它保存为以F:\python\myDemo\hello.py print 'hello,world' 下面通过python解释器调用: >>> import sys>>> sys.path.

python bottle框架(WEB开发、运维开发)教程

教程目录 一:python基础(略,基础还是自己看书学吧) 二:bottle基础 python bottle web框架简介 python bottle 框架环境安装 python bottle 框架基础教程:路由(url定义) python bottle 框架基础教程:HTTP 请求方法 python bottle 框架基础教程:模板使用 python bottle 框架基础教程:模板语法 python bottle 框架基础教程:模板继承 python bottle 框架基础教程:静态资源

Python实现HMM(隐马尔可夫模型)

1. 前言 隐马尔科夫HMM模型是一类重要的机器学习方法,其主要用于序列数据的分析,广泛应用于语音识别.文本翻译.序列预测.中文分词等多个领域.虽然近年来,由于RNN等深度学习方法的发展,HMM模型逐渐变得不怎么流行了,但并不意味着完全退出应用领域,甚至在一些轻量级的任务中仍有应用.本系列博客将详细剖析隐马尔科夫链HMM模型,同以往网络上绝大多数教程不同,本系列博客将更深入地分析HMM,不仅包括估计序列隐状态的维特比算法(HMM解码问题).前向后向算法等,而且还着重的分析HMM的EM训练过程,并

以股票RSI指标为例,学习Python发送邮件功能(含RSI指标确定卖点策略)

本人之前写过若干“给程序员加财商”的系列文,目的是通过股票案例讲述Python知识点,让大家在学习Python的同时还能掌握相关的股票知识,所谓一举两得. 在之前的系列文里,大家能看到K线,均线,成交量的案例,在本文里,大家能看到通过RSI案例讲述Python邮件编程的知识点,在后继系列文里,大家还能看到MACD,BIAS,KDJ等指标相关案例. 1  RSI指标的原理和算法描述 相对强弱指标(RSI)是通过比较某个时段内单股价格的涨跌幅度来判断多空双方的强弱程度,以此来预测未来走势.从数值上看

Python 环境搭建(Win 安装以及Mac OS 安装)

千里之行始于足下,今天我们先来学习 Python 环境搭建. 注意:本系列教程基于 Python 3.X Python 环境搭建 Win 安装 打开 Python 官网 https://www.python.org/downloads/选择最新版本下载,或者直接打开对应的版本python-374(https://www.python.org/downloads/release/python-374/). 打开页面会看到有一个列表,如下图: x86是32位,x86-64是64位. 可以通过下面3种