<s> import boto <EOL> import pyswfaws . util <EOL> class DataStore : <EOL> """<STR_LIT>""" <EOL> def put ( self , message , key ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> def get ( self , key ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> class SwfDataStore ( DataStore ) : <EOL> """<STR_LIT>""" <EOL> _message_size_limit = <NUM_LIT> <EOL> def __init__ ( self ) : <EOL> pass <EOL> def put ( self , message , key ) : <EOL> """<STR_LIT>""" <EOL> """<STR_LIT>""" <EOL> return message <EOL> def get ( self , key ) : <EOL> """<STR_LIT>""" <EOL> """<STR_LIT>""" <EOL> return key <EOL> def _message_size_check ( self , message ) : <EOL> if len ( message ) > self . _message_size_limit : <EOL> raise Exception ( '<STR_LIT>' ) <EOL> class S3DataStore ( DataStore ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , bucket , base_key , aws_key = None , aws_secret = None ) : <EOL> """<STR_LIT>""" <EOL> self . _s3_client = boto . connect_s3 ( aws_access_key_id = aws_key , aws_secret_access_key = aws_secret ) <EOL> self . _bucket = self . _s3_client . get_bucket ( bucket , validate = False ) <EOL> if base_key != '<STR_LIT>' and base_key [ - <NUM_LIT:1> : ] != '<STR_LIT:/>' : <EOL> self . _base_key_name = base_key + '<STR_LIT:/>' <EOL> else : <EOL> self . _base_key_name = '<STR_LIT>' <EOL> def put ( self , message , key ) : <EOL> """<STR_LIT>""" <EOL> s3_key = boto . s3 . key . Key ( self . _bucket ) <EOL> s3_key . key = '<STR_LIT>' . format ( self . _base_key_name , key ) <EOL> s3_key . set_contents_from_string ( message ) <EOL> return '<STR_LIT>' . format ( self . _bucket . name , s3_key . key ) <EOL> def get ( self , key ) : <EOL> """<STR_LIT>""" <EOL> return pyswfaws . util . get_from_s3 ( self . _s3_client , key ) </s>
