1919# based systems like Eventlet.
2020
2121#### Main Code
22-
2322from __future__ import absolute_import
2423from __future__ import print_function
2524import sys , os , datetime
@@ -67,10 +66,10 @@ def main(argv):
6766 # of `urllib2`. Otherwise, import the stdlib version of `urllib2`.
6867 #
6968 # The reason for the funky import syntax is that Python imports
70- # are scoped to functions, and we need to make it global.
69+ # are scoped to functions, and we need to make it global.
7170 # In a real application, you would only import one of these.
7271 if is_async :
73- urllib2 = __import__ ('eventlet.green' , globals (), locals (),
72+ urllib2 = __import__ ('eventlet.green' , globals (), locals (),
7473 ['urllib2' ], - 1 ).urllib2
7574 else :
7675 urllib2 = __import__ ("urllib2" , globals (), locals (), [], - 1 )
@@ -143,12 +142,12 @@ def do_search(query):
143142 # and we can also ignore the result.
144143 for query in queries :
145144 do_search (query )
146-
145+
147146 # Record the current time at the end of the benchmark,
148147 # and print the delta elapsed time.
149148 newtime = datetime .datetime .now ()
150149 print ("Elapsed Time: %s" % (newtime - oldtime ))
151-
150+
152151
153152##### Custom `urllib2`-based HTTP handler
154153
@@ -158,21 +157,21 @@ def request(url, message, **kwargs):
158157 body = message .get ("body" , "" )
159158
160159 # Setup the default headers.
161- head = {
160+ head = {
162161 "Content-Length" : str (len (body )),
163162 "Host" : host ,
164163 "User-Agent" : "http.py/1.0" ,
165164 "Accept" : "*/*" ,
166165 }
167166
168167 # Add in the passed in headers.
169- for key , value in message ["headers" ]:
168+ for key , value in message ["headers" ]:
170169 head [key ] = value
171170
172171 # Note the HTTP method we're using, defaulting
173172 # to `GET`.
174173 method = message .get ("method" , "GET" )
175-
174+
176175 # Note that we do not support proxies in this example
177176 # If running Python 2.7.9+, disable SSL certificate validation
178177 if sys .version_info >= (2 , 7 , 9 ):
@@ -181,7 +180,7 @@ def request(url, message, **kwargs):
181180 else :
182181 opener = urllib2 .build_opener ()
183182
184- # Unfortunately, we need to use the hack of
183+ # Unfortunately, we need to use the hack of
185184 # "overriding" `request.get_method` to specify
186185 # a method other than `GET` or `POST`.
187186 request = urllib2 .Request (url , body , head )
@@ -194,10 +193,10 @@ def request(url, message, **kwargs):
194193 except Exception as e :
195194 response = e
196195
197- # Normalize the response to something the SDK expects, and
196+ # Normalize the response to something the SDK expects, and
198197 # return it.
199198 return {
200- 'status' : response .code ,
199+ 'status' : response .code ,
201200 'reason' : response .msg ,
202201 'headers' : response .info ().dict ,
203202 'body' : binding .ResponseReader (response )
0 commit comments