Skip to content

Commit 8fb839e

Browse files
author
Kevin D Smith
committed
Use sockets to detect protocol
1 parent 9c4c8ee commit 8fb839e

File tree

4 files changed

+37
-13
lines changed

4 files changed

+37
-13
lines changed

swat/cas/connection.py

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -396,21 +396,25 @@ def _detect_protocol(self, hostname, port, protocol=None):
396396
# Try to detect the proper protocol
397397
if protocol == 'auto':
398398

399-
from six.moves import urllib
399+
import socket
400400

401401
# for ptype in ['http', 'https']:
402402
for ptype in ['http']:
403403
try:
404-
req = urllib.request.Request('%s://%s:%s/cas' %
405-
(ptype, hostname, port))
406-
with urllib.request.urlopen(req) as res:
407-
pass
408-
except urllib.error.HTTPError as err:
409-
protocol = ptype
410-
break
404+
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
405+
sock.connect((hostname, port))
406+
sock.send(bytes('GET /cas HTTP/1.1\r\nHost: %s\r\nConnection: close\r\nUser-Agent: Python-SWAT\r\nCache-Control: no-cache\r\n\r\n' % hostname, 'utf8'))
407+
408+
if sock.recv(4).decode('utf-8').lower() == 'http':
409+
protocol = ptype
410+
break
411+
411412
except Exception as err:
412413
pass
413414

415+
finally:
416+
sock.close()
417+
414418
if protocol == 'auto':
415419
protocol = 'cas'
416420

@@ -1993,7 +1997,7 @@ def _read_any(self, _method_, *args, **kwargs):
19931997
19941998
'''
19951999
import pandas as pd
1996-
use_addtable = kwargs.pop('use_addtable', False)
2000+
use_addtable = kwargs.pop('use_addtable', False)
19972001
table, kwargs = self._get_table_args(**kwargs)
19982002
dframe = getattr(pd, _method_)(*args, **kwargs)
19992003
# REST doesn't support table.addtable
@@ -2457,7 +2461,7 @@ def read_html(self, io, casout=None, **kwargs):
24572461
'''
24582462
import pandas as pd
24592463
from swat import datamsghandlers as dmh
2460-
use_addtable = kwargs.pop('use_addtable', False)
2464+
use_addtable = kwargs.pop('use_addtable', False)
24612465
out = []
24622466
table, kwargs = self._get_table_args(casout=casout, **kwargs)
24632467
for i, dframe in enumerate(pd.read_html(io, **kwargs)):

swat/cas/rest/table.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
from __future__ import print_function, division, absolute_import, unicode_literals
2525

2626
import base64
27+
import decimal
2728
import numpy as np
2829
import pandas as pd
2930
from ..utils.datetime import cas2python_date, cas2python_time, cas2python_datetime
@@ -286,17 +287,17 @@ def toTuples(self, errors, cas2python_datetime, cas2python_date,
286287
outrow.append(base64.b64decode(item['data']+'=='))
287288
# Check for datetime, date, time
288289
elif dtype == 'datetime':
289-
if item == -9223372036854775808:
290+
if item < decimal.Decimal('-9223372036854775807.5'):
290291
outrow.append(pd.NaT)
291292
else:
292293
outrow.append(cas2python_datetime(item))
293294
elif dtype == 'date':
294-
if item == -2147483648:
295+
if item < decimal.Decimal('-2147483647.5'):
295296
outrow.append(pd.NaT)
296297
else:
297298
outrow.append(cas2python_date(item))
298299
elif dtype == 'time':
299-
if item == -9223372036854775808:
300+
if item < decimal.Decimal('-9223372036854775807.5'):
300301
outrow.append(pd.NaT)
301302
else:
302303
outrow.append(cas2python_time(item))

swat/cas/transformers.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,22 @@ def py2cas(soptions, _sw_error, **kwargs):
461461
CASValueList representation of Python object
462462
463463
'''
464+
465+
def remove_unsupported(params):
466+
''' Remove any unsupported parameter types '''
467+
for key in list(params.keys()):
468+
if isinstance(params[key], dict_types):
469+
remove_unsupported(params[key])
470+
elif not isinstance(params[key], (binary_types, text_types, bool,
471+
blob, int64_types, int32_types,
472+
float64_types, items_types, ParamManager,
473+
datetime.datetime, datetime.date,
474+
datetime.time, type(nil))):
475+
del params[key]
476+
477+
# In-place operation
478+
remove_unsupported(kwargs)
479+
464480
_sw_values = errorcheck(clib.SW_CASValueList(len(kwargs), a2n(soptions),
465481
_sw_error), _sw_error)
466482

swat/tests/cas/test_table.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3162,6 +3162,7 @@ def test_read_html(self):
31623162
else:
31633163
self.assertEqual(set(tbl.dtypes.unique()), set(['double', 'int64', 'varchar']))
31643164

3165+
@unittest.skip('Need way to verify HDF installation')
31653166
def test_read_hdf(self):
31663167
df = self.get_cars_df(all_doubles=False)
31673168

@@ -3230,6 +3231,7 @@ def test_column_to_xarray(self):
32303231

32313232
self.assertEqual(list(dfx.values)[:200], list(tblx.values)[:200])
32323233

3234+
@unittest.skip('Need way to verify HDF installation')
32333235
def test_column_to_hdf(self):
32343236
df = self.get_cars_df(all_doubles=False)
32353237
tbl = self.table
@@ -3642,6 +3644,7 @@ def test_to_csv(self):
36423644

36433645
os.remove(tmp.name)
36443646

3647+
@unittest.skip('Need way to verify HDF installation')
36453648
def test_to_hdf(self):
36463649
df = self.get_cars_df()
36473650
tbl = self.table

0 commit comments

Comments
 (0)