Skip to content

Commit 52eade7

Browse files
committed
build params
1 parent fe2855f commit 52eade7

File tree

3 files changed

+58
-2
lines changed

3 files changed

+58
-2
lines changed

singlestoredb/config.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import os
55

66
from . import auth
7-
from .utils.config import check_bool # noqa: F401
7+
from .utils.config import check_bool, check_socket_options # noqa: F401
88
from .utils.config import check_dict_str_str # noqa: F401
99
from .utils.config import check_float # noqa: F401
1010
from .utils.config import check_int # noqa: F401
@@ -263,6 +263,11 @@
263263
environ='SINGLESTOREDB_FUSION_ENABLED',
264264
)
265265

266+
register_option(
267+
'socket_options', 'dict', check_socket_options, None,
268+
'Format for socket options',
269+
)
270+
266271
#
267272
# Query results options
268273
#

singlestoredb/connection.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1320,7 +1320,6 @@ def connect(
13201320
ssl_ca: Optional[str] = None, ssl_disabled: Optional[bool] = None,
13211321
ssl_cipher: Optional[str] = None, ssl_verify_cert: Optional[bool] = None,
13221322
tls_sni_servername: Optional[str] = None,
1323-
socket_options: Optional[Dict[int, Dict[int, Any]]] = None,
13241323
ssl_verify_identity: Optional[bool] = None,
13251324
conv: Optional[Dict[int, Callable[..., Any]]] = None,
13261325
credential_type: Optional[str] = None,
@@ -1341,6 +1340,7 @@ def connect(
13411340
vector_data_format: Optional[str] = None,
13421341
parse_json: Optional[bool] = None,
13431342
interpolate_query_with_empty_args: Optional[bool] = None,
1343+
socket_options: Optional[Dict[int, Dict[int, Any]]] = None,
13441344
) -> Connection:
13451345
"""
13461346
Return a SingleStoreDB connection.
@@ -1429,6 +1429,11 @@ def connect(
14291429
interpolate_query_with_empty_args : bool, optional
14301430
Should the connector apply parameter interpolation even when the
14311431
parameters are empty? This corresponds to pymysql/mysqlclient's handling
1432+
socket_options : dict, optional
1433+
Socket options to set on the underlying socket. The keys should be
1434+
socket level constants (e.g., socket.SOL_SOCKET) and the values should be
1435+
dictionaries mapping socket option constants (e.g., socket.SO_KEEPALIVE) to
1436+
the desired value for that option.
14321437
14331438
Examples
14341439
--------

singlestoredb/utils/config.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -645,7 +645,53 @@ def check_str(
645645

646646
return out
647647

648+
def check_socket_options(
649+
value: Any,
650+
) -> Optional[Dict[int, Dict[int, Any]]]:
651+
"""
652+
Validate socket options.
653+
654+
Parameters
655+
----------
656+
value : dict
657+
The value to validate. It must be a dictionary where the keys are
658+
socket level constants (e.g., socket.SOL_SOCKET) and the values are
659+
dictionaries mapping socket option constants (e.g., socket.SO_KEEPALIVE)
660+
to the desired value for that option.
661+
662+
Returns
663+
-------
664+
dict
665+
The validated socket options
666+
667+
"""
668+
if value is None:
669+
return None
648670

671+
if not isinstance(value, Mapping):
672+
raise ValueError(
673+
'value {} must be of type dict'.format(value),
674+
)
675+
676+
out = {}
677+
for level, options in value.items():
678+
if not isinstance(level, int):
679+
raise ValueError(
680+
'keys in {} must be integers corresponding to socket levels'.format(value),
681+
)
682+
if not isinstance(options, Mapping):
683+
raise ValueError(
684+
'values in {} must be dicts mapping socket option constants to values'.format(value),
685+
)
686+
out[level] = {}
687+
for opt, val in options.items():
688+
if not isinstance(opt, int):
689+
raise ValueError(
690+
'keys in sub-dicts of {} must be integers corresponding to socket option constants'.format(value),
691+
)
692+
out[level][opt] = val
693+
694+
return out
649695
def check_dict_str_str(
650696
value: Any,
651697
) -> Optional[Dict[str, str]]:

0 commit comments

Comments
 (0)