1- import time
2- import six
1+ import http .client
32import os
43import ssl
4+ import time
5+ from io import StringIO
56
6- from six .moves import http_client
7- from six .moves .urllib .parse import urlparse , unquote
7+ from urllib .parse import urlparse , unquote
88
99from chart_studio .api import utils
1010
@@ -50,12 +50,12 @@ def write(self, data, reconnect_on=("", 200, 502)):
5050 # Reconnect depending on the status code.
5151 if (response == "" and "" in reconnect_on ) or (
5252 response
53- and isinstance (response , http_client .HTTPResponse )
53+ and isinstance (response , http . client .HTTPResponse )
5454 and response .status in reconnect_on
5555 ):
5656 self ._reconnect ()
5757
58- elif response and isinstance (response , http_client .HTTPResponse ):
58+ elif response and isinstance (response , http . client .HTTPResponse ):
5959 # If an HTTPResponse was recieved then
6060 # make the users aware instead of
6161 # auto-reconnecting in case the
@@ -85,7 +85,7 @@ def write(self, data, reconnect_on=("", 200, 502)):
8585 "{msglen}\r \n {msg}\r \n " .format (msglen = msglen , msg = msg ).encode ("utf-8" )
8686 )
8787 self ._conn .sock .setblocking (0 )
88- except http_client .socket .error :
88+ except http . client .socket .error :
8989 self ._reconnect ()
9090 self .write (data )
9191
@@ -152,11 +152,11 @@ def _connect(self):
152152 if proxy_server and proxy_port :
153153 if ssl_enabled :
154154 context = self ._get_ssl_context ()
155- self ._conn = http_client .HTTPSConnection (
155+ self ._conn = http . client .HTTPSConnection (
156156 proxy_server , proxy_port , context = context
157157 )
158158 else :
159- self ._conn = http_client .HTTPConnection (proxy_server , proxy_port )
159+ self ._conn = http . client .HTTPConnection (proxy_server , proxy_port )
160160
161161 tunnel_headers = None
162162 if proxy_auth :
@@ -166,9 +166,9 @@ def _connect(self):
166166 else :
167167 if ssl_enabled :
168168 context = self ._get_ssl_context ()
169- self ._conn = http_client .HTTPSConnection (server , port , context = context )
169+ self ._conn = http . client .HTTPSConnection (server , port , context = context )
170170 else :
171- self ._conn = http_client .HTTPConnection (server , port )
171+ self ._conn = http . client .HTTPConnection (server , port )
172172
173173 self ._conn .putrequest ("POST" , self ._url )
174174 self ._conn .putheader ("Transfer-Encoding" , "chunked" )
@@ -179,14 +179,14 @@ def _connect(self):
179179 # Set blocking to False prevents recv
180180 # from blocking while waiting for a response.
181181 self ._conn .sock .setblocking (False )
182- self ._bytes = six . b ( "" )
182+ self ._bytes = b""
183183 self ._reset_retries ()
184184 time .sleep (0.5 )
185185
186186 def close (self ):
187187 """Close the connection to server.
188188
189- If available, return a http_client .HTTPResponse object.
189+ If available, return a http.client .HTTPResponse object.
190190
191191 Closing the connection involves sending the
192192 Transfer-Encoding terminating bytes.
@@ -199,7 +199,7 @@ def close(self):
199199 # require an extra \r\n.
200200 try :
201201 self ._conn .send ("\r \n 0\r \n \r \n " .encode ("utf-8" ))
202- except http_client .socket .error :
202+ except http . client .socket .error :
203203 # In case the socket has already been closed
204204 return ""
205205
@@ -219,28 +219,28 @@ def _getresponse(self):
219219 while True :
220220 try :
221221 _bytes = self ._conn .sock .recv (1 )
222- except http_client .socket .error :
222+ except http . client .socket .error :
223223 # For error 54: Connection reset by peer
224224 # (and perhaps others)
225- return six . b ( "" )
226- if _bytes == six . b ( "" ) :
225+ return b""
226+ if _bytes == b"" :
227227 break
228228 else :
229229 response += _bytes
230230 # Set recv to be non-blocking again
231231 self ._conn .sock .setblocking (False )
232232
233- # Convert the response string to a http_client .HTTPResponse
233+ # Convert the response string to a http.client .HTTPResponse
234234 # object with a bit of a hack
235- if response != six . b ( "" ) :
235+ if response != b"" :
236236 # Taken from
237237 # http://pythonwise.blogspot.ca/2010/02/parse-http-response.html
238238 try :
239- response = http_client .HTTPResponse (_FakeSocket (response ))
239+ response = http . client .HTTPResponse (_FakeSocket (response ))
240240 response .begin ()
241241 except :
242242 # Bad headers ... etc.
243- response = six . b ( "" )
243+ response = b""
244244 return response
245245
246246 def _isconnected (self ):
@@ -268,10 +268,10 @@ def _isconnected(self):
268268 # 3 - Check if the server has returned any data.
269269 # If they have, then start to store the response
270270 # in _bytes.
271- self ._bytes = six . b ( "" )
271+ self ._bytes = b""
272272 self ._bytes = self ._conn .sock .recv (1 )
273273 return False
274- except http_client .socket .error as e :
274+ except http . client .socket .error as e :
275275 # Check why recv failed
276276 # Windows machines are the error codes
277277 # that start with 1
@@ -320,7 +320,7 @@ def _reconnect(self):
320320 if not self ._isconnected ():
321321 try :
322322 self ._connect ()
323- except http_client .socket .error as e :
323+ except http . client .socket .error as e :
324324 # Attempt to reconnect if the connection was refused
325325 if e .errno == 61 or e .errno == 10061 :
326326 # errno 61 is the "Connection Refused" error
@@ -345,8 +345,8 @@ def _reset_retries(self):
345345 self ._delay = 1
346346
347347
348- class _FakeSocket (six . StringIO ):
349- # Used to construct a http_client .HTTPResponse object
348+ class _FakeSocket (StringIO ):
349+ # Used to construct a http.client .HTTPResponse object
350350 # from a string.
351351 # Thx to: http://pythonwise.blogspot.ca/2010/02/parse-http-response.html
352352 def makefile (self , * args , ** kwargs ):
0 commit comments