1
- import time
2
- import six
1
+ import http .client
3
2
import os
4
3
import ssl
4
+ import time
5
+ from io import StringIO
5
6
6
- from six .moves import http_client
7
- from six .moves .urllib .parse import urlparse , unquote
7
+ from urllib .parse import urlparse , unquote
8
8
9
9
from chart_studio .api import utils
10
10
@@ -50,12 +50,12 @@ def write(self, data, reconnect_on=("", 200, 502)):
50
50
# Reconnect depending on the status code.
51
51
if (response == "" and "" in reconnect_on ) or (
52
52
response
53
- and isinstance (response , http_client .HTTPResponse )
53
+ and isinstance (response , http . client .HTTPResponse )
54
54
and response .status in reconnect_on
55
55
):
56
56
self ._reconnect ()
57
57
58
- elif response and isinstance (response , http_client .HTTPResponse ):
58
+ elif response and isinstance (response , http . client .HTTPResponse ):
59
59
# If an HTTPResponse was recieved then
60
60
# make the users aware instead of
61
61
# auto-reconnecting in case the
@@ -85,7 +85,7 @@ def write(self, data, reconnect_on=("", 200, 502)):
85
85
"{msglen}\r \n {msg}\r \n " .format (msglen = msglen , msg = msg ).encode ("utf-8" )
86
86
)
87
87
self ._conn .sock .setblocking (0 )
88
- except http_client .socket .error :
88
+ except http . client .socket .error :
89
89
self ._reconnect ()
90
90
self .write (data )
91
91
@@ -152,11 +152,11 @@ def _connect(self):
152
152
if proxy_server and proxy_port :
153
153
if ssl_enabled :
154
154
context = self ._get_ssl_context ()
155
- self ._conn = http_client .HTTPSConnection (
155
+ self ._conn = http . client .HTTPSConnection (
156
156
proxy_server , proxy_port , context = context
157
157
)
158
158
else :
159
- self ._conn = http_client .HTTPConnection (proxy_server , proxy_port )
159
+ self ._conn = http . client .HTTPConnection (proxy_server , proxy_port )
160
160
161
161
tunnel_headers = None
162
162
if proxy_auth :
@@ -166,9 +166,9 @@ def _connect(self):
166
166
else :
167
167
if ssl_enabled :
168
168
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 )
170
170
else :
171
- self ._conn = http_client .HTTPConnection (server , port )
171
+ self ._conn = http . client .HTTPConnection (server , port )
172
172
173
173
self ._conn .putrequest ("POST" , self ._url )
174
174
self ._conn .putheader ("Transfer-Encoding" , "chunked" )
@@ -179,14 +179,14 @@ def _connect(self):
179
179
# Set blocking to False prevents recv
180
180
# from blocking while waiting for a response.
181
181
self ._conn .sock .setblocking (False )
182
- self ._bytes = six . b ( "" )
182
+ self ._bytes = b""
183
183
self ._reset_retries ()
184
184
time .sleep (0.5 )
185
185
186
186
def close (self ):
187
187
""" Close the connection to server.
188
188
189
- If available, return a http_client .HTTPResponse object.
189
+ If available, return a http.client .HTTPResponse object.
190
190
191
191
Closing the connection involves sending the
192
192
Transfer-Encoding terminating bytes.
@@ -199,7 +199,7 @@ def close(self):
199
199
# require an extra \r\n.
200
200
try :
201
201
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 :
203
203
# In case the socket has already been closed
204
204
return ""
205
205
@@ -219,28 +219,28 @@ def _getresponse(self):
219
219
while True :
220
220
try :
221
221
_bytes = self ._conn .sock .recv (1 )
222
- except http_client .socket .error :
222
+ except http . client .socket .error :
223
223
# For error 54: Connection reset by peer
224
224
# (and perhaps others)
225
- return six . b ( "" )
226
- if _bytes == six . b ( "" ) :
225
+ return b""
226
+ if _bytes == b"" :
227
227
break
228
228
else :
229
229
response += _bytes
230
230
# Set recv to be non-blocking again
231
231
self ._conn .sock .setblocking (False )
232
232
233
- # Convert the response string to a http_client .HTTPResponse
233
+ # Convert the response string to a http.client .HTTPResponse
234
234
# object with a bit of a hack
235
- if response != six . b ( "" ) :
235
+ if response != b"" :
236
236
# Taken from
237
237
# http://pythonwise.blogspot.ca/2010/02/parse-http-response.html
238
238
try :
239
- response = http_client .HTTPResponse (_FakeSocket (response ))
239
+ response = http . client .HTTPResponse (_FakeSocket (response ))
240
240
response .begin ()
241
241
except :
242
242
# Bad headers ... etc.
243
- response = six . b ( "" )
243
+ response = b""
244
244
return response
245
245
246
246
def _isconnected (self ):
@@ -268,10 +268,10 @@ def _isconnected(self):
268
268
# 3 - Check if the server has returned any data.
269
269
# If they have, then start to store the response
270
270
# in _bytes.
271
- self ._bytes = six . b ( "" )
271
+ self ._bytes = b""
272
272
self ._bytes = self ._conn .sock .recv (1 )
273
273
return False
274
- except http_client .socket .error as e :
274
+ except http . client .socket .error as e :
275
275
# Check why recv failed
276
276
# Windows machines are the error codes
277
277
# that start with 1
@@ -320,7 +320,7 @@ def _reconnect(self):
320
320
if not self ._isconnected ():
321
321
try :
322
322
self ._connect ()
323
- except http_client .socket .error as e :
323
+ except http . client .socket .error as e :
324
324
# Attempt to reconnect if the connection was refused
325
325
if e .errno == 61 or e .errno == 10061 :
326
326
# errno 61 is the "Connection Refused" error
@@ -346,8 +346,8 @@ def _reset_retries(self):
346
346
self ._delay = 1
347
347
348
348
349
- class _FakeSocket (six . StringIO ):
350
- # Used to construct a http_client .HTTPResponse object
349
+ class _FakeSocket (StringIO ):
350
+ # Used to construct a http.client .HTTPResponse object
351
351
# from a string.
352
352
# Thx to: http://pythonwise.blogspot.ca/2010/02/parse-http-response.html
353
353
def makefile (self , * args , ** kwargs ):
0 commit comments