<s> __author__ = """<STR_LIT>""" <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> from os import getcwd <EOL> from os import sys <EOL> sys . path . append ( getcwd ( ) ) <EOL> from MOAL . helpers . display import Section <EOL> DEBUG = True if __name__ == '<STR_LIT:__main__>' else False <EOL> """<STR_LIT>""" <EOL> class Structure : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , * args , ** kwargs ) : <EOL> self . props = { } <EOL> self . props [ '<STR_LIT>' ] = kwargs [ '<STR_LIT>' ] <EOL> for kwarg , val in kwargs . iteritems ( ) : <EOL> self . props [ kwarg ] = val <EOL> def __getitem__ ( self , key ) : <EOL> return self . props [ key ] <EOL> def show_model ( self ) : <EOL> for val , val_type in self . props [ '<STR_LIT>' ] . iteritems ( ) : <EOL> print ( '<STR_LIT>' . format ( val , val_type ) ) <EOL> def constraint ( self , constraint_name , field ) : <EOL> print ( '<STR_LIT>' . format ( constraint_name , field ) ) <EOL> if constraint_name not in self . props [ '<STR_LIT>' ] : <EOL> raise ValueError ( <EOL> '<STR_LIT>' . format ( constraint_name ) ) <EOL> _args , _kwargs = field [ '<STR_LIT:args>' ] , field [ '<STR_LIT>' ] <EOL> return self . props [ '<STR_LIT>' ] [ constraint_name ] ( * _args , ** _kwargs ) <EOL> def operation ( self , operation_name , val ) : <EOL> print ( '<STR_LIT>' . format ( operation_name , val ) ) <EOL> if operation_name not in self . props [ '<STR_LIT>' ] : <EOL> raise ValueError ( <EOL> '<STR_LIT>' . format ( operation_name ) ) <EOL> _args , _kwargs = val [ '<STR_LIT:args>' ] , val [ '<STR_LIT>' ] <EOL> return self . props [ '<STR_LIT>' ] [ operation_name ] ( * _args , ** _kwargs ) <EOL> def create_field ( schema , field , value ) : <EOL> print ( '<STR_LIT>' . format ( schema [ field ] ) ) <EOL> schema [ field ] = value <EOL> print ( '<STR_LIT>' . format ( schema [ field ] ) ) <EOL> def read_field ( schema , field ) : <EOL> return schema [ field ] <EOL> def update_field ( schema , field , replace ) : <EOL> schema [ field ] = replace <EOL> def delete_field ( schema , field ) : <EOL> del schema [ field ] <EOL> def greater_than ( val1 , val2 ) : <EOL> return val1 > val2 <EOL> def less_than ( val1 , val2 ) : <EOL> return val1 < val2 <EOL> def longer ( val1 , val2 ) : <EOL> return str ( val1 ) > str ( val2 ) <EOL> def shorter ( val1 , val2 ) : <EOL> return str ( val1 ) < str ( val2 ) <EOL> if DEBUG : <EOL> with Section ( '<STR_LIT>' ) : <EOL> person = Structure ( <EOL> schema = { '<STR_LIT:name>' : str , '<STR_LIT>' : int } , <EOL> constraints = { <EOL> '<STR_LIT>' : less_than , <EOL> '<STR_LIT>' : greater_than <EOL> } , <EOL> operations = { <EOL> '<STR_LIT>' : create_field , <EOL> '<STR_LIT>' : read_field , <EOL> '<STR_LIT>' : update_field , <EOL> '<STR_LIT>' : delete_field , <EOL> } ) <EOL> person . show_model ( ) <EOL> person . operation ( '<STR_LIT>' , <EOL> { '<STR_LIT:args>' : ( person [ '<STR_LIT>' ] , '<STR_LIT:name>' , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : { } } ) <EOL> person . show_model ( ) <EOL> person . operation ( '<STR_LIT>' , <EOL> { '<STR_LIT:args>' : ( person [ '<STR_LIT>' ] , '<STR_LIT:name>' , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : { } } ) <EOL> person . show_model ( ) <EOL> assert person [ '<STR_LIT>' ] [ '<STR_LIT:name>' ] == '<STR_LIT>' <EOL> person . operation ( '<STR_LIT>' , <EOL> { '<STR_LIT:args>' : ( person [ '<STR_LIT>' ] , '<STR_LIT>' , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : { } } ) </s>
