互联网协议和支持¶
本章介绍的模块实现了互联网协议以及相关技术支持。 它们都是用 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
run()
_write()
_flush()
get_stdin()
get_stderr()
add_cgi_vars()
wsgi_multithread
wsgi_multiprocess
wsgi_run_once
os_environ
server_software
get_scheme()
setup_environ()
log_exception()
traceback_limit
error_output()
error_status
error_headers
error_body
wsgi_file_wrapper
sendfile()
origin_server
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 对象
- 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
--- 将 URL 解析为组件urllib.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 对象
- HTTPResponse 对象
- 例子
- HTTPMessage 对象
ftplib
--- FTP 协议客户端poplib
--- POP3 协议客户端imaplib
--- IMAP4 协议客户端IMAP4
error
abort
readonly
IMAP4_SSL
IMAP4_stream
Internaldate2tuple()
Int2AP()
ParseFlags()
Time2Internaldate()
- IMAP4 对象
append()
authenticate()
check()
close()
copy()
create()
delete()
deleteacl()
enable()
expunge()
fetch()
getacl()
getannotation()
getquota()
getquotaroot()
list()
login()
login_cram_md5()
logout()
lsub()
myrights()
namespace()
noop()
open()
partial()
proxyauth()
read()
readline()
recent()
rename()
response()
search()
select()
send()
setacl()
setannotation()
setquota()
shutdown()
socket()
sort()
starttls()
status()
store()
subscribe()
thread()
uid()
unsubscribe()
unselect()
xatom()
PROTOCOL_VERSION
debug
utf8_enabled
- IMAP4 示例
smtplib
--- SMTP 协议客户端uuid
--- UUID objects according to RFC 9562SafeUUID
UUID
bytes
bytes_le
fields
time_low
time_mid
time_hi_version
clock_seq_hi_variant
clock_seq_low
node
time
clock_seq
hex
int
urn
variant
version
is_safe
getnode()
uuid1()
uuid3()
uuid4()
uuid5()
uuid8()
NAMESPACE_DNS
NAMESPACE_URL
NAMESPACE_OID
NAMESPACE_X500
RESERVED_NCS
RFC_4122
RESERVED_MICROSOFT
RESERVED_FUTURE
- 命令行用法
- 示例
- 命令行示例
socketserver
--- 用于网络服务器的框架TCPServer
UDPServer
UnixStreamServer
UnixDatagramServer
- 服务器创建的说明
- Server 对象
BaseServer
fileno()
handle_request()
serve_forever()
service_actions()
shutdown()
server_close()
address_family
RequestHandlerClass
server_address
socket
allow_reuse_address
request_queue_size
socket_type
timeout
finish_request()
get_request()
handle_error()
handle_timeout()
process_request()
server_activate()
server_bind()
verify_request()
- 请求处理器对象
- 例子
http.server
--- HTTP 服务器HTTPServer
ThreadingHTTPServer
BaseHTTPRequestHandler
client_address
server
close_connection
requestline
command
path
request_version
headers
rfile
wfile
server_version
sys_version
error_message_format
error_content_type
protocol_version
MessageClass
responses
handle()
handle_one_request()
handle_expect_100()
send_error()
send_response()
send_header()
send_response_only()
end_headers()
flush_headers()
log_request()
log_error()
log_message()
version_string()
date_time_string()
log_date_time_string()
address_string()
SimpleHTTPRequestHandler
CGIHTTPRequestHandler
- 安全考量
http.cookies
--- HTTP 状态管理http.cookiejar
--- HTTP 客户端的 Cookie 处理LoadError
CookieJar
FileCookieJar
CookiePolicy
DefaultCookiePolicy
Cookie
- CookieJar 和 FileCookieJar 对象
- FileCookieJar 的子类及其与 Web 浏览器的协同
- CookiePolicy 对象
- DefaultCookiePolicy 对象
blocked_domains()
set_blocked_domains()
is_blocked()
allowed_domains()
set_allowed_domains()
is_not_allowed()
rfc2109_as_netscape
strict_domain
strict_rfc2965_unverifiable
strict_ns_unverifiable
strict_ns_domain
strict_ns_set_initial_dollar
strict_ns_set_path
DomainStrictNoDots
DomainStrictNonDomain
DomainRFC2965Match
DomainLiberal
DomainStrict
- Cookie 对象
- 例子
xmlrpc
--- XMLRPC 服务端与客户端模块xmlrpc.client
--- XML-RPC 客户端访问xmlrpc.server
--- 基本 XML-RPC 服务器ipaddress
--- IPv4/IPv6 操作库- 方便的工厂函数
- IP 地址
- IP网络的定义
- 前缀、网络掩码和主机掩码
- 网络对象
IPv4Network
version
max_prefixlen
is_multicast
is_private
is_unspecified
is_reserved
is_loopback
is_link_local
network_address
broadcast_address
hostmask
netmask
with_prefixlen
compressed
exploded
with_netmask
with_hostmask
num_addresses
prefixlen
hosts()
overlaps()
address_exclude()
subnets()
supernet()
subnet_of()
supernet_of()
compare_networks()
IPv6Network
version
max_prefixlen
is_multicast
is_private
is_unspecified
is_reserved
is_loopback
is_link_local
network_address
broadcast_address
hostmask
netmask
with_prefixlen
compressed
exploded
with_netmask
with_hostmask
num_addresses
prefixlen
hosts()
overlaps()
address_exclude()
subnets()
supernet()
subnet_of()
supernet_of()
compare_networks()
is_site_local
- 运算符
- 接口对象
- 其他模块级别函数
- 自定义异常