66
66
IPROTO_FEATURE_TRANSACTIONS ,
67
67
IPROTO_FEATURE_ERROR_EXTENSION ,
68
68
IPROTO_FEATURE_WATCHERS ,
69
+ IPROTO_FEATURE_PAGINATION ,
70
+ IPROTO_FEATURE_SPACE_AND_INDEX_NAMES ,
71
+ IPROTO_FEATURE_WATCH_ONCE ,
69
72
IPROTO_CHUNK ,
70
73
AUTH_TYPE_CHAP_SHA1 ,
71
74
AUTH_TYPE_PAP_SHA256 ,
@@ -608,7 +611,9 @@ def __init__(self, host, port,
608
611
packer_factory = default_packer_factory ,
609
612
unpacker_factory = default_unpacker_factory ,
610
613
auth_type = None ,
611
- fetch_schema = True ):
614
+ fetch_schema = True ,
615
+ required_protocol_version = None ,
616
+ required_features = None ):
612
617
"""
613
618
:param host: Server hostname or IP address. Use ``None`` for
614
619
Unix sockets.
@@ -777,6 +782,14 @@ def __init__(self, host, port,
777
782
:meth:`~tarantool.Connection.space`.
778
783
:type fetch_schema: :obj:`bool`, optional
779
784
785
+ :param required_protocol_version: Minimal protocol version that
786
+ should be supported by Tarantool server.
787
+ :type required_protocol_version: :obj:`int` or :obj:`None`, optional
788
+
789
+ :param required_features: List of protocol features that
790
+ should be supported by Tarantool server.
791
+ :type required_features: :obj:`list` or :obj:`None`, optional
792
+
780
793
:raise: :exc:`~tarantool.error.ConfigurationError`,
781
794
:meth:`~tarantool.Connection.connect` exceptions
782
795
@@ -785,7 +798,7 @@ def __init__(self, host, port,
785
798
.. _mp_bin: https://github.com/msgpack/msgpack/blob/master/spec.md#bin-format-family
786
799
.. _mp_array: https://github.com/msgpack/msgpack/blob/master/spec.md#array-format-family
787
800
"""
788
- # pylint: disable=too-many-arguments,too-many-locals
801
+ # pylint: disable=too-many-arguments,too-many-locals,too-many-statements
789
802
790
803
if msgpack .version >= (1 , 0 , 0 ) and encoding not in (None , 'utf-8' ):
791
804
raise ConfigurationError ("msgpack>=1.0.0 only supports None and "
@@ -831,6 +844,9 @@ def __init__(self, host, port,
831
844
IPROTO_FEATURE_TRANSACTIONS : False ,
832
845
IPROTO_FEATURE_ERROR_EXTENSION : False ,
833
846
IPROTO_FEATURE_WATCHERS : False ,
847
+ IPROTO_FEATURE_PAGINATION : False ,
848
+ IPROTO_FEATURE_SPACE_AND_INDEX_NAMES : False ,
849
+ IPROTO_FEATURE_WATCH_ONCE : False ,
834
850
}
835
851
self ._packer_factory_impl = packer_factory
836
852
self ._unpacker_factory_impl = unpacker_factory
@@ -843,6 +859,8 @@ def __init__(self, host, port,
843
859
self ._client_features = copy (CONNECTOR_FEATURES )
844
860
self ._server_protocol_version = None
845
861
self ._server_features = None
862
+ self .required_protocol_version = required_protocol_version
863
+ self .required_features = copy (required_features )
846
864
847
865
if connect_now :
848
866
self .connect ()
@@ -2076,6 +2094,21 @@ def _check_features(self):
2076
2094
if exc .code != ER_UNKNOWN_REQUEST_TYPE :
2077
2095
raise exc
2078
2096
2097
+ if self .required_protocol_version is not None :
2098
+ if self ._server_protocol_version is None or \
2099
+ self ._server_protocol_version < self .required_protocol_version :
2100
+ raise ConfigurationError ('Server protocol version is '
2101
+ f'{ self ._server_protocol_version } , '
2102
+ f'protocol version { self .required_protocol_version } '
2103
+ 'is required' )
2104
+
2105
+ if self .required_features is not None :
2106
+ failed_features = [val for val in self .required_features
2107
+ if val not in self ._server_features ]
2108
+ if len (failed_features ) > 0 :
2109
+ str_features = ', ' .join ([str (v ) for v in failed_features ])
2110
+ raise ConfigurationError (f'Server missing protocol features with id { str_features } ' )
2111
+
2079
2112
if self ._server_protocol_version is not None :
2080
2113
self ._protocol_version = min (self ._server_protocol_version ,
2081
2114
self ._client_protocol_version )
0 commit comments