<s> '''<STR_LIT>''' <EOL> __version_info__ = ( '<STR_LIT:0>' , '<STR_LIT:1>' , '<STR_LIT:4>' ) <EOL> __version__ = '<STR_LIT:.>' . join ( __version_info__ ) <EOL> __author__ = '<STR_LIT>' <EOL> __license__ = '<STR_LIT>' <EOL> __copyright__ = '<STR_LIT>' <EOL> from cassandra . cluster import Cluster <EOL> import logging <EOL> from flask import current_app <EOL> log = logging . getLogger ( __name__ ) <EOL> try : <EOL> from flask import _app_ctx_stack as stack <EOL> except ImportError : <EOL> from flask import _request_ctx_stack as stack <EOL> try : <EOL> unicode <EOL> except NameError : <EOL> unicode = str <EOL> class CassandraCluster ( object ) : <EOL> def __init__ ( self , app = None ) : <EOL> self . app = app <EOL> self . cluster = None <EOL> if app is not None : <EOL> self . init_app ( app ) <EOL> def init_app ( self , app ) : <EOL> app . config . setdefault ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> if hasattr ( app , '<STR_LIT>' ) : <EOL> app . teardown_appcontext ( self . teardown ) <EOL> else : <EOL> app . teardown_request ( self . teardown ) <EOL> def connect ( self ) : <EOL> log . debug ( "<STR_LIT>" . format ( current_app . config [ '<STR_LIT>' ] ) ) <EOL> if self . cluster is None : <EOL> if isinstance ( current_app . config [ '<STR_LIT>' ] , ( list , tuple ) ) : <EOL> self . cluster = Cluster ( current_app . config [ '<STR_LIT>' ] ) <EOL> elif isinstance ( current_app . config [ '<STR_LIT>' ] , ( str , unicode ) ) : <EOL> self . cluster = Cluster ( [ current_app . config [ '<STR_LIT>' ] ] ) <EOL> else : <EOL> raise TypeError ( "<STR_LIT>" ) <EOL> online_cluster = self . cluster . connect ( ) <EOL> return online_cluster <EOL> def teardown ( self , exception ) : <EOL> ctx = stack . top <EOL> if hasattr ( ctx , '<STR_LIT>' ) : <EOL> ctx . cassandra_cluster . shutdown ( ) <EOL> @ property <EOL> def connection ( self ) : <EOL> ctx = stack . top <EOL> if ctx is not None : <EOL> if not hasattr ( ctx , '<STR_LIT>' ) : <EOL> ctx . cassandra_cluster = self . connect ( ) <EOL> return ctx . cassandra_cluster </s>
