<s> import os <EOL> os . environ [ '<STR_LIT>' ] = '<STR_LIT:1>' <EOL> import logging <EOL> log = logging . getLogger ( ) <EOL> log . setLevel ( '<STR_LIT>' ) <EOL> handler = logging . StreamHandler ( ) <EOL> handler . setFormatter ( logging . Formatter ( "<STR_LIT>" ) ) <EOL> log . addHandler ( handler ) <EOL> from uuid import uuid4 <EOL> from cassandra . cqlengine import columns <EOL> from cassandra . cqlengine import connection <EOL> from cassandra . cqlengine import management <EOL> from cassandra . cqlengine import ValidationError <EOL> from cassandra . cqlengine . models import Model <EOL> from cassandra . cqlengine . query import BatchQuery , LWTException <EOL> KEYSPACE = "<STR_LIT>" <EOL> class FamilyMembers ( Model ) : <EOL> __keyspace__ = KEYSPACE <EOL> id = columns . UUID ( primary_key = True , default = uuid4 ) <EOL> surname = columns . Text ( primary_key = True ) <EOL> name = columns . Text ( primary_key = True ) <EOL> birth_year = columns . Integer ( ) <EOL> sex = columns . Text ( min_length = <NUM_LIT:1> , max_length = <NUM_LIT:1> ) <EOL> def validate ( self ) : <EOL> super ( FamilyMembers , self ) . validate ( ) <EOL> if self . sex and self . sex not in '<STR_LIT>' : <EOL> raise ValidationError ( "<STR_LIT>" ) <EOL> if self . birth_year and self . sex == '<STR_LIT:f>' : <EOL> raise ValidationError ( "<STR_LIT>" ) <EOL> def main ( ) : <EOL> connection . default ( ) <EOL> log . info ( "<STR_LIT>" ) <EOL> management . create_keyspace_simple ( KEYSPACE , <NUM_LIT:1> ) <EOL> log . info ( "<STR_LIT>" ) <EOL> management . sync_table ( FamilyMembers ) <EOL> simmons = FamilyMembers . create ( surname = '<STR_LIT>' , name = '<STR_LIT>' , birth_year = <NUM_LIT> , sex = '<STR_LIT:m>' ) <EOL> FamilyMembers . create ( id = simmons . id , surname = '<STR_LIT>' , name = '<STR_LIT>' , birth_year = <NUM_LIT> , sex = '<STR_LIT:m>' ) <EOL> sophie = FamilyMembers . create ( id = simmons . id , surname = '<STR_LIT>' , name = '<STR_LIT>' , sex = '<STR_LIT:f>' ) <EOL> nick = FamilyMembers . objects ( id = simmons . id , surname = '<STR_LIT>' , name = '<STR_LIT>' ) <EOL> try : <EOL> nick . iff ( birth_year = <NUM_LIT> ) . update ( birth_year = <NUM_LIT> ) <EOL> except LWTException : <EOL> print "<STR_LIT>" <EOL> try : <EOL> FamilyMembers . create ( id = simmons . id , surname = '<STR_LIT>' , name = '<STR_LIT>' , birth_year = <NUM_LIT> , sex = '<STR_LIT:f>' ) <EOL> except ValidationError : <EOL> log . exception ( '<STR_LIT>' ) <EOL> FamilyMembers . create ( id = simmons . id , surname = '<STR_LIT>' , name = '<STR_LIT>' , sex = '<STR_LIT:f>' ) <EOL> log . info ( "<STR_LIT>" ) <EOL> hogan_id = uuid4 ( ) <EOL> with BatchQuery ( ) as b : <EOL> FamilyMembers . batch ( b ) . create ( id = hogan_id , surname = '<STR_LIT>' , name = '<STR_LIT>' , sex = '<STR_LIT:m>' ) <EOL> FamilyMembers . batch ( b ) . create ( id = hogan_id , surname = '<STR_LIT>' , name = '<STR_LIT>' , sex = '<STR_LIT:f>' ) <EOL> FamilyMembers . batch ( b ) . create ( id = hogan_id , surname = '<STR_LIT>' , name = '<STR_LIT>' , sex = '<STR_LIT:m>' ) <EOL> FamilyMembers . batch ( b ) . create ( id = hogan_id , surname = '<STR_LIT>' , name = '<STR_LIT>' , sex = '<STR_LIT:f>' ) <EOL> log . info ( "<STR_LIT>" ) <EOL> for m in FamilyMembers . all ( ) : <EOL> print m , m . birth_year , m . sex <EOL> log . info ( "<STR_LIT>" ) <EOL> for m in FamilyMembers . objects ( id = simmons . id ) : <EOL> print m , m . birth_year , m . sex <EOL> log . info ( "<STR_LIT>" ) <EOL> for m in FamilyMembers . objects ( id = simmons . id , surname = simmons . surname ) : <EOL> print m , m . birth_year , m . sex <EOL> log . info ( "<STR_LIT>" ) <EOL> kids = FamilyMembers . objects ( id = simmons . id , surname = simmons . surname , name__in = [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> log . info ( "<STR_LIT>" ) <EOL> FamilyMembers ( id = hogan_id , surname = '<STR_LIT>' , name = '<STR_LIT>' ) . delete ( ) <EOL> for m in FamilyMembers . objects ( id = hogan_id ) : <EOL> print m , m . birth_year , m . sex <EOL> management . drop_keyspace ( KEYSPACE ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> main ( ) </s>
