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

(yzsuai) #1
the distributed extension to COM, DCOM, offers additional options for distrib-
uting applications over networks.

Other tools
Other tools serve more specific roles. Among this crowd are mod_python—a system
which optimizes the execution of Python server-scripts in the Apache web
server; Twisted—an asynchronous, event-driven, networking framework written
in Python, with support for a large number of network protocols and with precoded
implementations of common network servers; HTMLgen—a lightweight tool that
allows HTML code to be generated from a tree of Python objects that describes a
web page; and Python Server Pages (PSP)—a server-side templating technology
that embeds Python code inside HTML, runs it with request context to render part
of a reply page, and is strongly reminiscent of PHP, ASP, and JSP.


As you might expect given the prominence of the Web, there are more Internet tools
for Python than we have space to discuss here. For more on this front, see the PyPI
website at http://python.org/, or visit your favorite web search engine (some of which
are implemented using Python’s Internet tools themselves).


Again, the goal of this book is to cover the fundamentals in an in-depth way, so that
you’ll have the context needed to use tools like some of those above well, when you’re
ready to graduate to more comprehensive solutions. As we’ll see, the basic model of
CGI scripting we’ll meet here illustrates the mechanisms underlying all web develop-
ment, whether it’s implemented by bare-bones scripts, or advanced frameworks.


Because we must walk before we can run well, though, let’s start at the bottom here,
and get a handle on what the Internet really is. The Internet today rests upon a rich
software stack; while tools can hide some of its complexity, programming it skillfully
still requires knowledge of all its layers. As we’ll see, deploying Python on the Web,
especially with higher-order web frameworks like those listed above, is only possible
because we truly are “surfing on the shoulders of giants.”


Plumbing the Internet


Unless you’ve been living in a cave for the last decade or two, you are probably already
familiar with the Internet, at least from a user’s perspective. Functionally, we use it as
a communication and information medium, by exchanging email, browsing web pages,
transferring files, and so on. Technically, the Internet consists of many layers of ab-
straction and devices—from the actual wires used to send bits across the world to the
web browser that grabs and renders those bits into text, graphics, and audio on your
computer.


In this book, we are primarily concerned with the programmer’s interface to the Inter-
net. This, too, consists of multiple layers: sockets, which are programmable interfaces
to the low-level connections between machines, and standard protocols, which add


780 | Chapter 12: Network Scripting

Free download pdf