免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1806 | 回复: 0
打印 上一主题 下一主题

用到的模块学习心得 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2009-04-08 11:35 |只看该作者 |倒序浏览
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
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP