6666Req-sent-unread-response _CS_REQ_SENT <response_class>
6767"""
6868
69- import io
70- import socket
7169import email .parser
7270import email .message
71+ import io
72+ import os
73+ import socket
7374from urllib .parse import urlsplit
7475import warnings
7576
@@ -673,29 +674,24 @@ def send(self, str):
673674 # ignore the error... the caller will know if they can retry.
674675 if self .debuglevel > 0 :
675676 print ("send:" , repr (str ))
676- try :
677- blocksize = 8192
678- if hasattr (str , "read" ) :
677+ blocksize = 8192
678+ if hasattr (str , "read" ) :
679+ if self .debuglevel > 0 :
680+ print ("sendIng a read()able" )
681+ encode = False
682+ if "b" not in str .mode :
683+ encode = True
679684 if self .debuglevel > 0 :
680- print ("sendIng a read()able" )
681- encode = False
682- if "b" not in str .mode :
683- encode = True
684- if self .debuglevel > 0 :
685- print ("encoding file using iso-8859-1" )
686- while 1 :
687- data = str .read (blocksize )
688- if not data :
689- break
690- if encode :
691- data = data .encode ("iso-8859-1" )
692- self .sock .sendall (data )
693- else :
694- self .sock .sendall (str )
695- except socket .error as v :
696- if v .args [0 ] == 32 : # Broken pipe
697- self .close ()
698- raise
685+ print ("encoding file using iso-8859-1" )
686+ while 1 :
687+ data = str .read (blocksize )
688+ if not data :
689+ break
690+ if encode :
691+ data = data .encode ("iso-8859-1" )
692+ self .sock .sendall (data )
693+ else :
694+ self .sock .sendall (str )
699695
700696 def _output (self , s ):
701697 """Add a line of output to the current request buffer.
@@ -869,14 +865,7 @@ def endheaders(self, message_body=None):
869865
870866 def request (self , method , url , body = None , headers = {}):
871867 """Send a complete request to the server."""
872- try :
873- self ._send_request (method , url , body , headers )
874- except socket .error as v :
875- # trap 'Broken pipe' if we're allowed to automatically reconnect
876- if v .args [0 ] != 32 or not self .auto_open :
877- raise
878- # try one more time
879- self ._send_request (method , url , body , headers )
868+ self ._send_request (method , url , body , headers )
880869
881870 def _set_content_length (self , body ):
882871 # Set the content-length based on the body.
@@ -886,7 +875,6 @@ def _set_content_length(self, body):
886875 except TypeError as te :
887876 # If this is a file-like object, try to
888877 # fstat its file descriptor
889- import os
890878 try :
891879 thelen = str (os .fstat (body .fileno ()).st_size )
892880 except (AttributeError , OSError ):
@@ -897,7 +885,7 @@ def _set_content_length(self, body):
897885 self .putheader ('Content-Length' , thelen )
898886
899887 def _send_request (self , method , url , body , headers ):
900- # honour explicitly requested Host: and Accept-Encoding headers
888+ # Honor explicitly requested Host: and Accept-Encoding: headers.
901889 header_names = dict .fromkeys ([k .lower () for k in headers ])
902890 skips = {}
903891 if 'host' in header_names :
@@ -983,7 +971,8 @@ def __init__(self, host, port=None, key_file=None, cert_file=None,
983971 def connect (self ):
984972 "Connect to a host on a given (SSL) port."
985973
986- sock = socket .create_connection ((self .host , self .port ), self .timeout )
974+ sock = socket .create_connection ((self .host , self .port ),
975+ self .timeout )
987976 self .sock = ssl .wrap_socket (sock , self .key_file , self .cert_file )
988977
989978
0 commit comments