- 论坛徽章:
- 0
|
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 interfacesname
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
本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u2/84280/showart_1893533.html |
|