網路協定 (Internet protocols) 及支援¶
這個章節講述的模組實作了網路協定及相關技術的支援;他們全都是用 Python 實作的。這裡的大多數模組都需要相依於系統的模組 socket
,目前普遍的平台都支援該模組。 以下為概述:
webbrowser
--- Convenient web-browser controllerwsgiref
--- 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
--- 用來開啟 URLs 的可擴充函式庫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 Objects
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 物件
- Examples
- Legacy interface
urllib.request
Restrictions
urllib.response
--- Response classes used by urlliburllib.parse
--- Parse URLs into componentsurllib.error
--- urllib.request 引發的例外類別urllib.robotparser
--- robots.txt 的剖析器http
--- HTTP 模組http.client
--- HTTP protocol clientHTTPConnection
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 protocol clientimaplib
--- IMAP4 protocol clientIMAP4
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 protocol clientuuid
--- RFC 4122 定義的 UUID 物件socketserver
--- A framework for network serversTCPServer
UDPServer
UnixStreamServer
UnixDatagramServer
- Server Creation Notes
- Server Objects
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()
- Request Handler Objects
- 範例
http.server
--- HTTP serversHTTPServer
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
- Security Considerations
http.cookies
--- HTTP state managementCookieError
BaseCookie
SimpleCookie
- Cookie 物件
- Morsel 物件
Morsel
Morsel.expires
Morsel.path
Morsel.comment
Morsel.domain
Morsel.secure
Morsel.version
Morsel.httponly
Morsel.samesite
Morsel.value
Morsel.coded_value
Morsel.key
Morsel.set()
Morsel.isReservedKey()
Morsel.output()
Morsel.js_output()
Morsel.OutputString()
Morsel.update()
Morsel.copy()
Morsel.setdefault()
- 範例
http.cookiejar
--- Cookie handling for HTTP clientsLoadError
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 subclasses and co-operation with web browsers
- 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 client accessxmlrpc.server
--- Basic XML-RPC serversipaddress
--- IPv4/IPv6 manipulation library- Convenience factory functions
- IP Addresses
- Address objects
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.__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__()
- Conversion to Strings and Integers
- Operators
- Address objects
- IP Network definitions
- Prefix, net mask and host mask
- Network objects
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
- Operators
- Interface objects
- Other Module Level Functions
- Custom Exceptions