2121import logging
2222import os
2323import ssl
24- from typing import Any , Dict , List , Optional
25-
26- from cassandra .auth import PlainTextAuthProvider
27- from cassandra .cluster import Cluster , Session
28-
2924from .consts import (
3025 CERT_DIRECTORY ,
3126 CERT_FILENAME ,
3530 PROTOCOL_VERSION ,
3631 UNSAFE_OPERATIONS ,
3732)
33+ from cassandra .auth import PlainTextAuthProvider
34+ from cassandra .cluster import Cluster , Session
35+ from typing import Any , Dict , List , Optional
3836
3937
4038# Older versions of the Cassandra Python driver may not include SSLOptions. Conditionally
@@ -252,8 +250,7 @@ async def describe_table(self, keyspace_name: str, table_name: str) -> Dict[str,
252250 """Get detailed information about a table."""
253251 try :
254252 query = (
255- 'SELECT * FROM system_schema.tables WHERE '
256- 'keyspace_name = %s AND table_name = %s'
253+ 'SELECT * FROM system_schema.tables WHERE keyspace_name = %s AND table_name = %s'
257254 )
258255 session = await self .get_session ()
259256
@@ -318,23 +315,28 @@ async def describe_table(self, keyspace_name: str, table_name: str) -> Dict[str,
318315 )
319316 session = await self .get_session ()
320317
321- capacity_row = session .execute (
322- query , [keyspace_name , table_name ]
323- ).one ()
318+ capacity_row = session .execute (query , [keyspace_name , table_name ]).one ()
324319
325320 if capacity_row and capacity_row .custom_properties :
326321 props = capacity_row .custom_properties
327322 if 'capacity_mode' in props :
328323 table_details ['capacity_mode' ] = props ['capacity_mode' ]
329324
330325 if props ['capacity_mode' ] == 'PROVISIONED' :
331- if 'read_capacity_units' not in props or 'write_capacity_units' not in props :
326+ if (
327+ 'read_capacity_units' not in props
328+ or 'write_capacity_units' not in props
329+ ):
332330 raise RuntimeError (
333331 f'PROVISIONED capacity mode requires both read_capacity_units '
334332 f'and write_capacity_units for table { keyspace_name } .{ table_name } '
335333 )
336- table_details ['read_capacity_units' ] = int (props ['read_capacity_units' ])
337- table_details ['write_capacity_units' ] = int (props ['write_capacity_units' ])
334+ table_details ['read_capacity_units' ] = int (
335+ props ['read_capacity_units' ]
336+ )
337+ table_details ['write_capacity_units' ] = int (
338+ props ['write_capacity_units' ]
339+ )
338340 except (RuntimeError , ValueError , AttributeError ) as e :
339341 # Ignore errors when trying to get capacity information
340342 logger .warning (
@@ -361,10 +363,7 @@ async def execute_read_only_query(
361363 raise ValueError ('Only SELECT queries are allowed for read-only execution' )
362364
363365 # Check for any modifications that might be disguised as SELECT
364- if any (
365- op in trimmed_query
366- for op in UNSAFE_OPERATIONS
367- ):
366+ if any (op in trimmed_query for op in UNSAFE_OPERATIONS ):
368367 raise ValueError ('Query contains potentially unsafe operations' )
369368
370369 try :
@@ -398,9 +397,7 @@ async def execute_read_only_query(
398397 if hasattr (row , col_name ) and getattr (row , col_name ) is not None :
399398 value = getattr (row , col_name )
400399 except (AttributeError , TypeError , ValueError ) as e :
401- logger .warning (
402- 'Error getting value for column %s: %s' , col_name , str (e )
403- )
400+ logger .warning ('Error getting value for column %s: %s' , col_name , str (e ))
404401 row_data [col_name ] = value
405402 rows .append (row_data )
406403
0 commit comments