<s> import boto <EOL> import sys <EOL> from boto . exception import S3ResponseError <EOL> from tornado import ioloop , options , web <EOL> from viewfinder . backend . base import asyncboto , secrets <EOL> options . define ( "<STR_LIT:port>" , default = <NUM_LIT> , help = "<STR_LIT>" ) <EOL> class S3Handler ( web . RequestHandler ) : <EOL> def initialize ( self ) : <EOL> self . conn = boto . connect_s3 ( <EOL> aws_access_key_id = secrets . GetSecret ( '<STR_LIT>' ) . strip ( ) , <EOL> aws_secret_access_key = secrets . GetSecret ( '<STR_LIT>' ) . strip ( ) ) <EOL> self . bucket = self . conn . get_bucket ( '<STR_LIT>' ) <EOL> @ asyncboto . asyncs3 <EOL> def get ( self ) : <EOL> k = self . bucket . new_key ( self . get_argument ( "<STR_LIT:key>" ) ) <EOL> try : <EOL> self . write ( k . get_contents_as_string ( ) ) <EOL> except S3ResponseError : <EOL> self . send_error ( <NUM_LIT> ) <EOL> return <EOL> finally : <EOL> k . close ( ) <EOL> self . finish ( ) <EOL> def main ( ) : <EOL> options . parse_command_line ( ) <EOL> application = web . Application ( [ <EOL> ( r"<STR_LIT>" , S3Handler ) , <EOL> ] ) <EOL> application . listen ( options . options . port ) <EOL> ioloop . IOLoop . instance ( ) . start ( ) <EOL> return <NUM_LIT:0> <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> sys . exit ( main ( ) ) </s>
