<s> """<STR_LIT>""" <EOL> from sqlalchemy import Column , Integer , String , ForeignKey <EOL> from sqlalchemy . orm import relationship <EOL> from . caching_query import FromCache , RelationshipCache <EOL> from . environment import Base , bootstrap <EOL> class Country ( Base ) : <EOL> __tablename__ = '<STR_LIT>' <EOL> id = Column ( Integer , primary_key = True ) <EOL> name = Column ( String ( <NUM_LIT:100> ) , nullable = False ) <EOL> def __init__ ( self , name ) : <EOL> self . name = name <EOL> class City ( Base ) : <EOL> __tablename__ = '<STR_LIT>' <EOL> id = Column ( Integer , primary_key = True ) <EOL> name = Column ( String ( <NUM_LIT:100> ) , nullable = False ) <EOL> country_id = Column ( Integer , ForeignKey ( '<STR_LIT>' ) , nullable = False ) <EOL> country = relationship ( Country ) <EOL> def __init__ ( self , name , country ) : <EOL> self . name = name <EOL> self . country = country <EOL> class PostalCode ( Base ) : <EOL> __tablename__ = '<STR_LIT>' <EOL> id = Column ( Integer , primary_key = True ) <EOL> code = Column ( String ( <NUM_LIT:10> ) , nullable = False ) <EOL> city_id = Column ( Integer , ForeignKey ( '<STR_LIT>' ) , nullable = False ) <EOL> city = relationship ( City ) <EOL> @ property <EOL> def country ( self ) : <EOL> return self . city . country <EOL> def __init__ ( self , code , city ) : <EOL> self . code = code <EOL> self . city = city <EOL> class Address ( Base ) : <EOL> __tablename__ = '<STR_LIT:address>' <EOL> id = Column ( Integer , primary_key = True ) <EOL> person_id = Column ( Integer , ForeignKey ( '<STR_LIT>' ) , nullable = False ) <EOL> street = Column ( String ( <NUM_LIT:200> ) , nullable = False ) <EOL> postal_code_id = Column ( Integer , ForeignKey ( '<STR_LIT>' ) ) <EOL> postal_code = relationship ( PostalCode ) <EOL> @ property <EOL> def city ( self ) : <EOL> return self . postal_code . city <EOL> @ property <EOL> def country ( self ) : <EOL> return self . postal_code . country <EOL> def __str__ ( self ) : <EOL> return "<STR_LIT>" "<STR_LIT>" "<STR_LIT:%s>" % ( self . street , self . city . name , <EOL> self . postal_code . code , self . country . name ) <EOL> class Person ( Base ) : <EOL> __tablename__ = '<STR_LIT>' <EOL> id = Column ( Integer , primary_key = True ) <EOL> name = Column ( String ( <NUM_LIT:100> ) , nullable = False ) <EOL> addresses = relationship ( Address , collection_class = set ) <EOL> def __init__ ( self , name , * addresses ) : <EOL> self . name = name <EOL> self . addresses = set ( addresses ) <EOL> def __str__ ( self ) : <EOL> return self . name <EOL> def __repr__ ( self ) : <EOL> return "<STR_LIT>" % self . name <EOL> def format_full ( self ) : <EOL> return "<STR_LIT:\t>" . join ( [ str ( x ) for x in [ self ] + list ( self . addresses ) ] ) <EOL> cache_address_bits = RelationshipCache ( PostalCode . city , "<STR_LIT:default>" ) . and_ ( <EOL> RelationshipCache ( City . country , "<STR_LIT:default>" ) <EOL> ) . and_ ( <EOL> RelationshipCache ( Address . postal_code , "<STR_LIT:default>" ) <EOL> ) <EOL> bootstrap ( ) </s>
