Chinaunix首页 | 论坛 | 博客
  • 博客访问: 26278707
  • 博文数量: 2065
  • 博客积分: 10377
  • 博客等级: 上将
  • 技术积分: 21525
  • 用 户 组: 普通用户
  • 注册时间: 2008-11-04 17:50
文章分类

全部博文(2065)

文章存档

2012年(2)

2011年(19)

2010年(1160)

2009年(969)

2008年(153)

分类: Python/Ruby

2009-04-08 11:35:51

1.BaseHTTPServer
这个模块定义了两个类用来实现 HTTP 服务器(WEB服务器)。通常本模块不会直接使用
第一个类,HTTPServer 是一个 SocketServer.TCPServer 的子集。他创建并监听 HTTP 套接字,分配 requests 到处理器(handler)。编码创建并运行这个服务器看起来像这样:

def run(server_class=BaseHTTPServer.HTTPServer,
handler_class=BaseHTTPServer.BaseHTTPRequestHandler):
server_address = (”, 8000)
httpd = server_class(server_address, handler_class)
httpd.serve_forever()

这个类在 HTTP 请求到达时处理它。实际上它自身并不能对任何 HTTP 请求作出响应,他必须存在派生类用来处理每一个请求方法(例如 GET 或者 POST)。BaseHTTPRequestHandler 为子集提供许多类变量、实例变量和方法。

《通过派生类去处理来自客户端的POST与GET请求的》

class BaseHTTPRequestHandler( request, client_address, server)
This class is used to handle the HTTP requests that arrive at the server. By itself, it cannot respond to any actual HTTP requests; it must be subclassed to handle each request method (e.g. GET or POST). BaseHTTPRequestHandler provides a number of class and instance variables, and methods for use by subclasses.
这个类的功能就是:处理来自于客户端的请求操作。包括GET或POST的操作的!
本身是不能正确地进行处理请求操作的。必须要通过其子类进行重写它!
struct的功能:This can be used in handling binary data stored in files or from network connections, among other sources.
This module performs conversions between Python values and C structs represented as Python strings.
4.3 struct -- Interpret strings as packed binary data
pack( fmt, v1, v2, ...)
Return a string containing the values v1, v2, ... packed according to the given format. The arguments must match the values required by the format exactly.
1.OS模块
14.1 os -- Miscellaneous operating system interfaces
name
The name of the operating system dependent module imported. The following names have currently been registered: 'posix', 'nt', 'mac', 'os2', 'ce', 'java', 'riscos'.
例如:print os.name  打印出来 nt





阅读(902) | 评论(0) | 转发(0) |
0

上一篇:PHP面向对象基础

下一篇:IIS事件日志

给主人留下些什么吧!~~