From 53e5b71bbcaad150b21dad00bf2d15653b8edb13 Mon Sep 17 00:00:00 2001 From: Fred Drake Date: Fri, 25 Apr 2003 15:27:33 +0000 Subject: Add modified versions of the examples from Sean Reifschneider (SF patch #545480). --- Doc/lib/liburllib2.tex | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/Doc/lib/liburllib2.tex b/Doc/lib/liburllib2.tex index 9f279df..7b47f9b 100644 --- a/Doc/lib/liburllib2.tex +++ b/Doc/lib/liburllib2.tex @@ -601,3 +601,39 @@ Open the gopher resource indicated by \var{req}. \begin{methoddesc}[UnknownHandler]{unknown_open}{} 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) + +>> 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} -- cgit v0.12