MCPcopy Create free account
hub / github.com/apache/cassandra-python-driver / _handle_options_response

Method _handle_options_response

cassandra/connection.py:1329–1399  ·  view source on GitHub ↗
(self, options_response)

Source from the content-addressed store, hash-verified

1327
1328 @defunct_on_error
1329 def _handle_options_response(self, options_response):
1330 if self.is_defunct:
1331 return
1332
1333 if not isinstance(options_response, SupportedMessage):
1334 if isinstance(options_response, ConnectionException):
1335 raise options_response
1336 else:
1337 log.error("Did not get expected SupportedMessage response; "
1338 "instead, got: %s", options_response)
1339 raise ConnectionException("Did not get expected SupportedMessage "
1340 "response; instead, got: %s"
1341 % (options_response,))
1342
1343 log.debug("Received options response on new connection (%s) from %s",
1344 id(self), self.endpoint)
1345 supported_cql_versions = options_response.cql_versions
1346 remote_supported_compressions = options_response.options['COMPRESSION']
1347 self._product_type = options_response.options.get('PRODUCT_TYPE', [None])[0]
1348
1349 if self.cql_version:
1350 if self.cql_version not in supported_cql_versions:
1351 raise ProtocolError(
1352 "cql_version %r is not supported by remote (w/ native "
1353 "protocol). Supported versions: %r"
1354 % (self.cql_version, supported_cql_versions))
1355 else:
1356 self.cql_version = supported_cql_versions[0]
1357
1358 self._compressor = None
1359 compression_type = None
1360 if self.compression:
1361 overlap = (set(locally_supported_compressions.keys()) &
1362 set(remote_supported_compressions))
1363 if len(overlap) == 0:
1364 log.debug("No available compression types supported on both ends."
1365 " locally supported: %r. remotely supported: %r",
1366 locally_supported_compressions.keys(),
1367 remote_supported_compressions)
1368 else:
1369 compression_type = None
1370 if isinstance(self.compression, str):
1371 # the user picked a specific compression type ('snappy' or 'lz4')
1372 if self.compression not in remote_supported_compressions:
1373 raise ProtocolError(
1374 "The requested compression type (%s) is not supported by the Cassandra server at %s"
1375 % (self.compression, self.endpoint))
1376 compression_type = self.compression
1377 else:
1378 # our locally supported compressions are ordered to prefer
1379 # lz4, if available
1380 for k in locally_supported_compressions.keys():
1381 if k in overlap:
1382 compression_type = k
1383 break
1384
1385 # If snappy compression is selected with v5+checksumming, the connection
1386 # will fail with OTO. Only lz4 is supported

Callers

nothing calls this directly

Calls 7

_send_startup_messageMethod · 0.95
ConnectionExceptionClass · 0.85
ProtocolErrorClass · 0.85
setFunction · 0.85
getMethod · 0.45
keysMethod · 0.45

Tested by

no test coverage detected