[Python编程(第4版)].(Programming.Python.4th.Edition).Mark.Lutz.文字版

(yzsuai) #1

Table 12-2. Common Internet-related standard modules


Python modules Utility
socket, ssl Network and IPC communications support (TCP/IP, UDP, etc.), plus SSL secure sockets
wrapper
cgi Server-side CGI script support: parse input stream, escape HTML text, and so on
urllib.request Fetch web pages from their addresses (URLs)
urllib.parse Parse URL string into components, escape URL text
http.client, ftplib,
nntplib

HTTP (web), FTP (file transfer), and NNTP (news) client protocol modules

http.cookies,
http.cookiejar

HTTP cookies support (data stored on clients by website request, server- and client-side
support)
poplib, imaplib, smtplib POP, IMAP (mail fetch), and SMTP (mail send) protocol modules
telnetlib Telnet protocol module
html.parser, xml.* Parse web page contents (HTML and XML documents)
xdrlib, socket Encode binary data portably for transmission
struct, pickle Encode Python objects as packed binary data or serialized byte strings for transmission
email.* Parse and compose email messages with headers, attachments, and encodings
mailbox Process on disk mailboxes and their messages
mimetypes Guess file content types from names and extensions from types
uu, binhex, base64,
binascii, quopri, email.*

Encode and decode binary (or other) data transmitted as text (automatic in email
package)
socketserver Framework for general Net servers
http.server Basic HTTP server implementation, with request handlers for simple and CGI-aware servers

We will meet many of the modules in this table in the next few chapters of this book,
but not all of them. Moreover, there are additional Internet modules in Python not
shown here. The modules demonstrated in this book will be representative, but as
always, be sure to see Python’s standard Library Reference Manual for more complete
and up-to-date lists and details.


More on Protocol Standards
If you want the full story on protocols and ports, at this writing you can find a com-
prehensive list of all ports reserved for protocols or registered as used by various com-
mon systems by searching the web pages maintained by the Internet Engineering Task
Force (IETF) and the Internet Assigned Numbers Authority (IANA). The IETF is the
organization responsible for maintaining web protocols and standards. The IANA is
the central coordinator for the assignment of unique parameter values for Internet pro-
tocols. Another standards body, the W3 (for WWW), also maintains relevant docu-
ments. See these web pages for more details:

786 | Chapter 12: Network Scripting

Free download pdf