互联网协议和支持¶
本章介绍的模块实现了互联网协议以及相关技术支持。 它们都是用 Python 实现的。 这些模块大多需要依赖于系统的模块 socket
作为前提,该模块在大多数流行系统平台上都受到支持。 下面是一份概览:
webbrowser
--- 方便的 Web 浏览器控制工具wsgiref
--- WSGI 工具和参考实现wsgiref.util
-- WSGI 环境工具wsgiref.headers
-- WSGI 响应标头工具wsgiref.simple_server
-- 一个简单的 WSGI HTTP 服务器wsgiref.validate
--- WSGI 一致性检查器wsgiref.handlers
-- 服务器/网关基类CGIHandler
IISCGIHandler
BaseCGIHandler
SimpleHandler
BaseHandler
BaseHandler.run()
BaseHandler._write()
BaseHandler._flush()
BaseHandler.get_stdin()
BaseHandler.get_stderr()
BaseHandler.add_cgi_vars()
BaseHandler.wsgi_multithread
BaseHandler.wsgi_multiprocess
BaseHandler.wsgi_run_once
BaseHandler.os_environ
BaseHandler.server_software
BaseHandler.get_scheme()
BaseHandler.setup_environ()
BaseHandler.log_exception()
BaseHandler.traceback_limit
BaseHandler.error_output()
BaseHandler.error_status
BaseHandler.error_headers
BaseHandler.error_body
BaseHandler.wsgi_file_wrapper
BaseHandler.sendfile()
BaseHandler.origin_server
BaseHandler.http_version
read_environ()
wsgiref.types
-- 用于静态类型检查的 WSGI 类型- 例子
urllib
--- URL 处理模块urllib.request
--- 用于打开 URL 的可扩展库urlopen()
install_opener()
build_opener()
pathname2url()
url2pathname()
getproxies()
Request
OpenerDirector
BaseHandler
HTTPDefaultErrorHandler
HTTPRedirectHandler
HTTPCookieProcessor
ProxyHandler
HTTPPasswordMgr
HTTPPasswordMgrWithDefaultRealm
HTTPPasswordMgrWithPriorAuth
AbstractBasicAuthHandler
HTTPBasicAuthHandler
ProxyBasicAuthHandler
AbstractDigestAuthHandler
HTTPDigestAuthHandler
ProxyDigestAuthHandler
HTTPHandler
HTTPSHandler
FileHandler
DataHandler
FTPHandler
CacheFTPHandler
UnknownHandler
HTTPErrorProcessor
- Request 对象
Request.full_url
Request.type
Request.host
Request.origin_req_host
Request.selector
Request.data
Request.unverifiable
Request.method
Request.get_method()
Request.add_header()
Request.add_unredirected_header()
Request.has_header()
Request.remove_header()
Request.get_full_url()
Request.set_proxy()
Request.get_header()
Request.header_items()
- OpenerDirector 对象
- BaseHandler 对象
- HTTPRedirectHandler 对象
- HTTPCookieProcessor 对象
- ProxyHandler 对象
- HTTPPasswordMgr 对象
- HTTPPasswordMgrWithPriorAuth 对象
- AbstractBasicAuthHandler 对象
- HTTPBasicAuthHandler 对象
- ProxyBasicAuthHandler 对象
- AbstractDigestAuthHandler 对象
- HTTPDigestAuthHandler 对象
- ProxyDigestAuthHandler 对象
- HTTPHandler 对象
- HTTPSHandler 对象
- FileHandler 对象
- DataHandler 对象
- FTPHandler 对象
- CacheFTPHandler 对象
- UnknownHandler 对象
- HTTPErrorProcessor 对象
- 例子
- 已停用的接口
urllib.request
的限制
urllib.response
--- urllib 使用的 Response 类urllib.parse
用于解析 URLurllib.error
--- urllib.request 引发的异常类urllib.robotparser
--- robots.txt 语法分析程序http
--- HTTP 模块http.client
--- HTTP 协议客户端HTTPConnection
HTTPSConnection
HTTPResponse
parse_headers()
HTTPException
NotConnected
InvalidURL
UnknownProtocol
UnknownTransferEncoding
UnimplementedFileMode
IncompleteRead
ImproperConnectionState
CannotSendRequest
CannotSendHeader
ResponseNotReady
BadStatusLine
LineTooLong
RemoteDisconnected
HTTP_PORT
HTTPS_PORT
responses
- HTTPConnection 对象
HTTPConnection.request()
HTTPConnection.getresponse()
HTTPConnection.set_debuglevel()
HTTPConnection.set_tunnel()
HTTPConnection.get_proxy_response_headers()
HTTPConnection.connect()
HTTPConnection.close()
HTTPConnection.blocksize
HTTPConnection.putrequest()
HTTPConnection.putheader()
HTTPConnection.endheaders()
HTTPConnection.send()
- HTTPResponse 对象
HTTPResponse.read()
HTTPResponse.readinto()
HTTPResponse.getheader()
HTTPResponse.getheaders()
HTTPResponse.fileno()
HTTPResponse.msg
HTTPResponse.version
HTTPResponse.url
HTTPResponse.headers
HTTPResponse.status
HTTPResponse.reason
HTTPResponse.debuglevel
HTTPResponse.closed
HTTPResponse.geturl()
HTTPResponse.info()
HTTPResponse.getcode()
- 例子
- HTTPMessage 对象
ftplib
--- FTP 协议客户端FTP
error_reply
error_temp
error_perm
error_proto
all_errors
- FTP 对象
FTP.set_debuglevel()
FTP.connect()
FTP.getwelcome()
FTP.login()
FTP.abort()
FTP.sendcmd()
FTP.voidcmd()
FTP.retrbinary()
FTP.retrlines()
FTP.set_pasv()
FTP.storbinary()
FTP.storlines()
FTP.transfercmd()
FTP.ntransfercmd()
FTP.mlsd()
FTP.nlst()
FTP.dir()
FTP.rename()
FTP.delete()
FTP.cwd()
FTP.mkd()
FTP.pwd()
FTP.rmd()
FTP.size()
FTP.quit()
FTP.close()
- FTP_TLS 对象
poplib
--- POP3 协议客户端imaplib
--- IMAP4 协议客户端IMAP4
IMAP4_SSL
IMAP4_stream
Internaldate2tuple()
Int2AP()
ParseFlags()
Time2Internaldate()
- IMAP4 对象
IMAP4.append()
IMAP4.authenticate()
IMAP4.check()
IMAP4.close()
IMAP4.copy()
IMAP4.create()
IMAP4.delete()
IMAP4.deleteacl()
IMAP4.enable()
IMAP4.expunge()
IMAP4.fetch()
IMAP4.getacl()
IMAP4.getannotation()
IMAP4.getquota()
IMAP4.getquotaroot()
IMAP4.list()
IMAP4.login()
IMAP4.login_cram_md5()
IMAP4.logout()
IMAP4.lsub()
IMAP4.myrights()
IMAP4.namespace()
IMAP4.noop()
IMAP4.open()
IMAP4.partial()
IMAP4.proxyauth()
IMAP4.read()
IMAP4.readline()
IMAP4.recent()
IMAP4.rename()
IMAP4.response()
IMAP4.search()
IMAP4.select()
IMAP4.send()
IMAP4.setacl()
IMAP4.setannotation()
IMAP4.setquota()
IMAP4.shutdown()
IMAP4.socket()
IMAP4.sort()
IMAP4.starttls()
IMAP4.status()
IMAP4.store()
IMAP4.subscribe()
IMAP4.thread()
IMAP4.uid()
IMAP4.unsubscribe()
IMAP4.unselect()
IMAP4.xatom()
IMAP4.PROTOCOL_VERSION
IMAP4.debug
IMAP4.utf8_enabled
- IMAP4 示例
smtplib
--- SMTP 协议客户端uuid
--- RFC 4122 定义的UUID对象socketserver
--- 用于网络服务器的框架TCPServer
UDPServer
UnixStreamServer
UnixDatagramServer
- 服务器创建的说明
- Server 对象
BaseServer
BaseServer.fileno()
BaseServer.handle_request()
BaseServer.serve_forever()
BaseServer.service_actions()
BaseServer.shutdown()
BaseServer.server_close()
BaseServer.address_family
BaseServer.RequestHandlerClass
BaseServer.server_address
BaseServer.socket
BaseServer.allow_reuse_address
BaseServer.request_queue_size
BaseServer.socket_type
BaseServer.timeout
BaseServer.finish_request()
BaseServer.get_request()
BaseServer.handle_error()
BaseServer.handle_timeout()
BaseServer.process_request()
BaseServer.server_activate()
BaseServer.server_bind()
BaseServer.verify_request()
- 请求处理句柄对象
- 例子
http.server
--- HTTP 服务器HTTPServer
ThreadingHTTPServer
BaseHTTPRequestHandler
BaseHTTPRequestHandler.client_address
BaseHTTPRequestHandler.server
BaseHTTPRequestHandler.close_connection
BaseHTTPRequestHandler.requestline
BaseHTTPRequestHandler.command
BaseHTTPRequestHandler.path
BaseHTTPRequestHandler.request_version
BaseHTTPRequestHandler.headers
BaseHTTPRequestHandler.rfile
BaseHTTPRequestHandler.wfile
BaseHTTPRequestHandler.server_version
BaseHTTPRequestHandler.sys_version
BaseHTTPRequestHandler.error_message_format
BaseHTTPRequestHandler.error_content_type
BaseHTTPRequestHandler.protocol_version
BaseHTTPRequestHandler.MessageClass
BaseHTTPRequestHandler.responses
BaseHTTPRequestHandler.handle()
BaseHTTPRequestHandler.handle_one_request()
BaseHTTPRequestHandler.handle_expect_100()
BaseHTTPRequestHandler.send_error()
BaseHTTPRequestHandler.send_response()
BaseHTTPRequestHandler.send_header()
BaseHTTPRequestHandler.send_response_only()
BaseHTTPRequestHandler.end_headers()
BaseHTTPRequestHandler.flush_headers()
BaseHTTPRequestHandler.log_request()
BaseHTTPRequestHandler.log_error()
BaseHTTPRequestHandler.log_message()
BaseHTTPRequestHandler.version_string()
BaseHTTPRequestHandler.date_time_string()
BaseHTTPRequestHandler.log_date_time_string()
BaseHTTPRequestHandler.address_string()
SimpleHTTPRequestHandler
CGIHTTPRequestHandler
- 安全考量
http.cookies
--- HTTP状态管理http.cookiejar
—— HTTP 客户端的 Cookie 处理LoadError
CookieJar
FileCookieJar
CookiePolicy
DefaultCookiePolicy
Cookie
- CookieJar 和 FileCookieJar 对象
CookieJar.add_cookie_header()
CookieJar.extract_cookies()
CookieJar.set_policy()
CookieJar.make_cookies()
CookieJar.set_cookie_if_ok()
CookieJar.set_cookie()
CookieJar.clear()
CookieJar.clear_session_cookies()
FileCookieJar.save()
FileCookieJar.load()
FileCookieJar.revert()
FileCookieJar.filename
FileCookieJar.delayload
- FileCookieJar 的子类及其与 Web 浏览器的协同
- CookiePolicy 对象
- DefaultCookiePolicy 对象
DefaultCookiePolicy.blocked_domains()
DefaultCookiePolicy.set_blocked_domains()
DefaultCookiePolicy.is_blocked()
DefaultCookiePolicy.allowed_domains()
DefaultCookiePolicy.set_allowed_domains()
DefaultCookiePolicy.is_not_allowed()
DefaultCookiePolicy.rfc2109_as_netscape
DefaultCookiePolicy.strict_domain
DefaultCookiePolicy.strict_rfc2965_unverifiable
DefaultCookiePolicy.strict_ns_unverifiable
DefaultCookiePolicy.strict_ns_domain
DefaultCookiePolicy.strict_ns_set_initial_dollar
DefaultCookiePolicy.strict_ns_set_path
DefaultCookiePolicy.DomainStrictNoDots
DefaultCookiePolicy.DomainStrictNonDomain
DefaultCookiePolicy.DomainRFC2965Match
DefaultCookiePolicy.DomainLiberal
DefaultCookiePolicy.DomainStrict
- Cookie 对象
Cookie.version
Cookie.name
Cookie.value
Cookie.port
Cookie.path
Cookie.secure
Cookie.expires
Cookie.discard
Cookie.comment
Cookie.comment_url
Cookie.rfc2109
Cookie.port_specified
Cookie.domain_specified
Cookie.domain_initial_dot
Cookie.has_nonstandard_attr()
Cookie.get_nonstandard_attr()
Cookie.set_nonstandard_attr()
Cookie.is_expired()
- 例子
xmlrpc
--- XMLRPC 服务端与客户端模块xmlrpc.client
--- XML-RPC 客户端访问xmlrpc.server
--- 基本 XML-RPC 服务器ipaddress
--- IPv4/IPv6 操作库- 方便的工厂函数
- IP 地址
- 地址对象
IPv4Address
IPv4Address.version
IPv4Address.max_prefixlen
IPv4Address.compressed
IPv4Address.exploded
IPv4Address.packed
IPv4Address.reverse_pointer
IPv4Address.is_multicast
IPv4Address.is_private
IPv4Address.is_global
IPv4Address.is_unspecified
IPv4Address.is_reserved
IPv4Address.is_loopback
IPv4Address.is_link_local
IPv4Address.ipv6_mapped
IPv4Address.__format__()
IPv6Address
IPv6Address.compressed
IPv6Address.exploded
IPv6Address.packed
IPv6Address.reverse_pointer
IPv6Address.version
IPv6Address.max_prefixlen
IPv6Address.is_multicast
IPv6Address.is_private
IPv6Address.is_global
IPv6Address.is_unspecified
IPv6Address.is_reserved
IPv6Address.is_loopback
IPv6Address.is_link_local
IPv6Address.is_site_local
IPv6Address.ipv4_mapped
IPv6Address.scope_id
IPv6Address.sixtofour
IPv6Address.teredo
IPv6Address.__format__()
- 转换字符串和整数
- 运算符
- 地址对象
- IP网络的定义
- 前缀、网络掩码和主机掩码
- 网络对象
IPv4Network
IPv4Network.version
IPv4Network.max_prefixlen
IPv4Network.is_multicast
IPv4Network.is_private
IPv4Network.is_unspecified
IPv4Network.is_reserved
IPv4Network.is_loopback
IPv4Network.is_link_local
IPv4Network.network_address
IPv4Network.broadcast_address
IPv4Network.hostmask
IPv4Network.netmask
IPv4Network.with_prefixlen
IPv4Network.compressed
IPv4Network.exploded
IPv4Network.with_netmask
IPv4Network.with_hostmask
IPv4Network.num_addresses
IPv4Network.prefixlen
IPv4Network.hosts()
IPv4Network.overlaps()
IPv4Network.address_exclude()
IPv4Network.subnets()
IPv4Network.supernet()
IPv4Network.subnet_of()
IPv4Network.supernet_of()
IPv4Network.compare_networks()
IPv6Network
IPv6Network.version
IPv6Network.max_prefixlen
IPv6Network.is_multicast
IPv6Network.is_private
IPv6Network.is_unspecified
IPv6Network.is_reserved
IPv6Network.is_loopback
IPv6Network.is_link_local
IPv6Network.network_address
IPv6Network.broadcast_address
IPv6Network.hostmask
IPv6Network.netmask
IPv6Network.with_prefixlen
IPv6Network.compressed
IPv6Network.exploded
IPv6Network.with_netmask
IPv6Network.with_hostmask
IPv6Network.num_addresses
IPv6Network.prefixlen
IPv6Network.hosts()
IPv6Network.overlaps()
IPv6Network.address_exclude()
IPv6Network.subnets()
IPv6Network.supernet()
IPv6Network.subnet_of()
IPv6Network.supernet_of()
IPv6Network.compare_networks()
IPv6Network.is_site_local
- 运算符
- 接口对象
- 其他模块级别函数
- 自定义异常