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

(yzsuai) #1

scripts should do automatically to be able to handle all possible cases well;
urllib.parse.unquote can undo these escapes if needed:


C:\...\PP4E\Internet\Other> python
>>> import urllib.parse
>>> urllib.parse.quote('C++')
'c%2B%2B'

Again, don’t work too hard at understanding these last few commands; we will revisit
URLs and URL escapes in Chapter 15, while exploring server-side scripting in Python.
I will also explain there why the C++ result came back with other oddities like
<<—HTML escapes for <<, generated by the tool cgi.escape in the script on the
server that produces the reply, and usually undone by HTML parsers including Py-
thon’s html.parser module we’ll meet in Chapter 19:


>>> import cgi
>>> cgi.escape('<<')
'<<'

Also in Chapter 15, we’ll meet urllib support for proxies, and its support for client-
side cookies. We’ll discuss the related HTTPS concept in Chapter 16—HTTP trans-
missions over secure sockets, supported by urllib.request on the client side if SSL
support is compiled into your Python. For now, it’s time to wrap up our look at the
Web, and the Internet at large, from the client side of the fence.


Other Client-Side Scripting Options


In this chapter, we focused on client-side interfaces to standard protocols that run over
sockets, but as suggested in an earlier footnote, client-side programming can take other
forms, too. We outlined many of these at the start of Chapter 12—web service protocols
(including SOAP and XML-RPC); Rich Internet Application toolkits (including Flex,
Silverlight, and pyjamas); cross-language framework integration (including Java
and .NET); and more.


As mentioned, most of these serve to extend the functionality of web browsers, and so
ultimately run on top of the HTTP protocol we explored in this chapter. For instance:



  • The Jython system, a compiler that supports Python-coded Java applets—general-
    purpose programs downloaded from a server and run locally on the client when
    accessed or referenced by a URL, which extend the functionality of web browsers
    and interactions.

  • Similarly, RIAs provide AJAX communication and widget toolkits that allow Java-
    Script to implement user interaction within web browsers, which is more dynamic
    and rich than HTML and web browsers otherwise support.

  • In Chapter 19, we’ll also study Python’s support for XML—structured text that is
    used as the data transfer medium of client/server dialogs in web service protocols
    such as XML-RPC, which transfer XML-encoded objects over HTTP, and are


1002 | Chapter 13: Client-Side Scripting

Free download pdf