@@ -135,7 +135,7 @@ def __init__(self):
135135 def add (self , host , connection , ready ):
136136 self ._lock .acquire ()
137137 try :
138- if not self ._hostmap . has_key ( host ) : self ._hostmap [host ] = []
138+ if host not in self ._hostmap : self ._hostmap [host ] = []
139139 self ._hostmap [host ].append (connection )
140140 self ._connmap [connection ] = host
141141 self ._readymap [connection ] = ready
@@ -165,7 +165,7 @@ def get_ready_conn(self, host):
165165 conn = None
166166 self ._lock .acquire ()
167167 try :
168- if self ._hostmap . has_key ( host ) :
168+ if host in self ._hostmap :
169169 for c in self ._hostmap [host ]:
170170 if self ._readymap [c ]:
171171 self ._readymap [c ] = 0
@@ -312,16 +312,16 @@ def _reuse_connection(self, h, req, host):
312312
313313 def _start_transaction (self , h , req ):
314314 try :
315- if req .has_data () :
315+ if req .data :
316316 data = req .data
317317 if hasattr (req , 'selector' ):
318318 h .putrequest (req .get_method () or 'POST' , req .selector , skip_host = req .has_header ("Host" ), skip_accept_encoding = req .has_header ("Accept-encoding" ))
319319 else :
320320 h .putrequest (req .get_method () or 'POST' , req .get_selector (), skip_host = req .has_header ("Host" ), skip_accept_encoding = req .has_header ("Accept-encoding" ))
321- if not req . headers . has_key ( 'Content-type' ) :
321+ if 'Content-type' not in req . headers :
322322 h .putheader ('Content-type' ,
323323 'application/x-www-form-urlencoded' )
324- if not req . headers . has_key ( 'Content-length' ) :
324+ if 'Content-length' not in req . headers :
325325 h .putheader ('Content-length' , '%d' % len (data ))
326326 else :
327327 if hasattr (req , 'selector' ):
@@ -331,16 +331,16 @@ def _start_transaction(self, h, req):
331331 except (socket .error , _http_client .HTTPException ) as err :
332332 raise _urllib .error .URLError (err )
333333
334- if not req .headers . has_key ( 'Connection' ) :
334+ if 'Connection' not in req .headers :
335335 req .headers ['Connection' ] = 'keep-alive'
336336
337337 for args in self .parent .addheaders :
338- if not req .headers . has_key ( args [ 0 ]) :
338+ if args [ 0 ] not in req .headers :
339339 h .putheader (* args )
340340 for k , v in req .headers .items ():
341341 h .putheader (k , v )
342342 h .endheaders ()
343- if req .has_data () :
343+ if req .data :
344344 h .send (data )
345345
346346 def _get_connection (self , host ):
@@ -419,6 +419,10 @@ def close(self):
419419 self ._handler ._request_closed (self , self ._host ,
420420 self ._connection )
421421
422+ # Note: Patch for Python3 (otherwise, connections won't be reusable)
423+ def _close_conn (self ):
424+ self .close ()
425+
422426 def close_connection (self ):
423427 self ._handler ._remove_connection (self ._host , self ._connection , close = 1 )
424428 self .close ()
0 commit comments