viewer, we could replace the hyperlink to the script languages-src.py in
language.html, with a URL of this form (I included both for illustration):
http://localhost/cgi-bin/getfile.py?filename=cgi-bin\languages.py
Subtle thing: notice that the query parameter in this URL and others in this book use
a backslash as the Windows directory separator. On Windows, and using both the local
Python web server of Example 15-1 and Internet Explorer, we can also use the two
URL-escaped forms at the start of the following, but the literal forward slash of the last
in following fails (in URL escapes, %5C is \ and %2F is /):
http://localhost/cgi-bin/getfile.py?filename=cgi-bin%5Clanguages.py OK too
http://localhost/cgi-bin/getfile.py?filename=cgi-bin%2Flanguages.py OK too
http://localhost/cgi-bin/getfile.py?filename=cgi-bin/languages.py fails
This reflects a change since the prior edition of this book (which used the last of these
for portability), and may or may not be ideal behavior (though like working directory
contexts, this is one of a set of server and platform differences you’re likely to encounter
when working on the Web). It seems to stem from the fact that the urllib.parse mod-
ule’s quote considers / safe, but quote_plus no longer does. If you care about URL
portability in this context, the second of the preceding forms may be better, though
arguably cryptic to remember if you have to type it manually (escaping tools can au-
tomate this). If not, you may have to double-up on backslashes to avoid clashes with
other string escapes, because of the way URL parameter data is handled; see the links
to this script in Example 15-20 for an example involving \f.
Figure 15-28. Generic source code viewer page
Transferring Files to Clients and Servers | 1213