1212# See the License for the specific language governing permissions and
1313# limitations under the License.
1414
15- """
16- Sample application that demonstrates different ways of fetching
17- URLS on App Engine
15+ """Sample application that demonstrates different ways of fetching
16+ URLS on App Engine.
1817"""
1918
2019import logging
2120import urllib
2221
23- # [START urllib2-imports ]
22+ # [START gae_urlfetch_snippets_imports_urllib2 ]
2423import urllib2
24+ # [END gae_urlfetch_snippets_imports_urllib2]
2525
26- # [END urllib2-imports]
27-
28- # [START urlfetch-imports]
26+ # [START gae_urlfetch_snippets_imports_urlfetch]
2927from google .appengine .api import urlfetch
28+ # [END gae_urlfetch_snippets_imports_urlfetch]
3029
31- # [END urlfetch-imports]
3230import webapp2
3331
3432
3533class UrlLibFetchHandler (webapp2 .RequestHandler ):
36- """Demonstrates an HTTP query using urllib2"""
34+ """Demonstrates an HTTP query using urllib2. """
3735
3836 def get (self ):
39- # [START urllib-get ]
37+ # [START gae_urlfetch_snippets_urllib2_get ]
4038 url = "http://www.google.com/humans.txt"
4139 try :
4240 result = urllib2 .urlopen (url )
4341 self .response .write (result .read ())
4442 except urllib2 .URLError :
4543 logging .exception ("Caught exception fetching url" )
46- # [END urllib-get ]
44+ # [END gae_urlfetch_snippets_urllib2_get ]
4745
4846
4947class UrlFetchHandler (webapp2 .RequestHandler ):
50- """Demonstrates an HTTP query using urlfetch"""
48+ """Demonstrates an HTTP query using urlfetch. """
5149
5250 def get (self ):
53- # [START urlfetch-get ]
51+ # [START gae_urlfetch_snippets_urlfetch_get ]
5452 url = "http://www.google.com/humans.txt"
5553 try :
5654 result = urlfetch .fetch (url )
@@ -60,19 +58,19 @@ def get(self):
6058 self .response .status_code = result .status_code
6159 except urlfetch .Error :
6260 logging .exception ("Caught exception fetching url" )
63- # [END urlfetch-get ]
61+ # [END gae_urlfetch_snippets_urlfetch_get ]
6462
6563
6664class UrlPostHandler (webapp2 .RequestHandler ):
67- """Demonstrates an HTTP POST form query using urlfetch"""
65+ """Demonstrates an HTTP POST form query using urlfetch. """
6866
6967 form_fields = {
7068 "first_name" : "Albert" ,
7169 "last_name" : "Johnson" ,
7270 }
7371
7472 def get (self ):
75- # [START urlfetch-post ]
73+ # [START gae_urlfetch_snippets_urlfetch_post ]
7674 try :
7775 form_data = urllib .urlencode (UrlPostHandler .form_fields )
7876 headers = {"Content-Type" : "application/x-www-form-urlencoded" }
@@ -85,11 +83,11 @@ def get(self):
8583 self .response .write (result .content )
8684 except urlfetch .Error :
8785 logging .exception ("Caught exception fetching url" )
88- # [END urlfetch-post ]
86+ # [END gae_urlfetch_snippets_urlfetch_post ]
8987
9088
9189class SubmitHandler (webapp2 .RequestHandler ):
92- """Handler that receives UrlPostHandler POST request"""
90+ """Handler that receives UrlPostHandler POST request. """
9391
9492 def post (self ):
9593 self .response .out .write ((self .request .get ("first_name" )))
0 commit comments