[Python-checkins] python/dist/src/Doc/lib liburllib2.tex,1.6.8.1,1.6.8.2

fdrake@users.sourceforge.net fdrake@users.sourceforge.net
Fri, 25 Apr 2003 08:29:25 -0700


Update of /cvsroot/python/python/dist/src/Doc/lib
In directory sc8-pr-cvs1:/tmp/cvs-serv740

Modified Files:
      Tag: release22-maint
	liburllib2.tex 
Log Message:
Add modified versions of the examples from Sean Reifschneider
(SF patch #545480).


Index: liburllib2.tex
===================================================================
RCS file: /cvsroot/python/python/dist/src/Doc/lib/liburllib2.tex,v
retrieving revision 1.6.8.1
retrieving revision 1.6.8.2
diff -C2 -d -r1.6.8.1 -r1.6.8.2
*** liburllib2.tex	25 Apr 2003 05:31:43 -0000	1.6.8.1
--- liburllib2.tex	25 Apr 2003 15:29:22 -0000	1.6.8.2
***************
*** 602,603 ****
--- 602,639 ----
  Raise a \exception{URLError} exception.
  \end{methoddesc}
+ 
+ 
+ \subsection{Examples \label{urllib2-examples}}
+ 
+ This example gets the python.org main page and displays the first 100
+ bytes of it:
+ 
+ \begin{verbatim}
+ >>> import urllib2
+ >>> f = urllib2.urlopen('http://www.python.org/')
+ >>> print f.read(100)
+ <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
+ <?xml-stylesheet href="./css/ht2html
+ \end{verbatim}
+ 
+ Here we are sending a data-stream to the stdin of a CGI and reading
+ the data it returns to us:
+ 
+ \begin{verbatim}
+ >>> import urllib2
+ >>> req = urllib2.Request(url='https://localhost/cgi-bin/test.cgi',
+ ...                       data='This data is passed to stdin of the CGI')
+ >>> f = urllib2.urlopen(req)
+ >>> print f.read()
+ Got Data: "This data is passed to stdin of the CGI"
+ \end{verbatim}
+ 
+ The code for the sample CGI used in the above example is:
+ 
+ \begin{verbatim}
+ #!/usr/bin/env python
+ import sys
+ data = sys.stdin.read()
+ print 'Content-type: text-plain\n\nGot Data: "%s"' %
+ data
+ \end{verbatim}