<s> """<STR_LIT>""" <EOL> import functools <EOL> from tornado . httpclient import HTTPRequest <EOL> from tornado . httpclient import AsyncHTTPClient <EOL> import xml . sax <EOL> import boto <EOL> from boto . sts . connection import STSConnection <EOL> from boto . sts . credentials import Credentials <EOL> from boto . exception import BotoServerError <EOL> class InvalidClientTokenIdError ( BotoServerError ) : <EOL> '''<STR_LIT>''' <EOL> pass <EOL> class AsyncAwsSts ( STSConnection ) : <EOL> '''<STR_LIT>''' <EOL> def __init__ ( self , aws_access_key_id = None , aws_secret_access_key = None , <EOL> is_secure = True , port = None , proxy = None , proxy_port = None , <EOL> proxy_user = None , proxy_pass = None , debug = <NUM_LIT:0> , <EOL> https_connection_factory = None , region = None , path = '<STR_LIT:/>' , <EOL> converter = None , ioloop = None ) : <EOL> STSConnection . __init__ ( self , aws_access_key_id , <EOL> aws_secret_access_key , <EOL> is_secure , port , proxy , proxy_port , <EOL> proxy_user , proxy_pass , debug , <EOL> https_connection_factory , region , path , converter ) <EOL> self . http_client = AsyncHTTPClient ( io_loop = ioloop ) <EOL> def get_session_token ( self , callback ) : <EOL> '''<STR_LIT>''' <EOL> return self . get_object ( '<STR_LIT>' , { } , Credentials , verb = '<STR_LIT:POST>' , callback = callback ) <EOL> def get_object ( self , action , params , cls , path = "<STR_LIT:/>" , parent = None , verb = "<STR_LIT:GET>" , callback = None ) : <EOL> '''<STR_LIT>''' <EOL> if not parent : <EOL> parent = self <EOL> self . make_request ( action , params , path , verb , <EOL> functools . partial ( self . _finish_get_object , callback = callback , parent = parent , cls = cls ) ) <EOL> def _finish_get_object ( self , response_body , callback , cls = None , parent = None , error = None ) : <EOL> '''<STR_LIT>''' <EOL> if error : <EOL> if error . code == <NUM_LIT> : <EOL> error_class = InvalidClientTokenIdError <EOL> else : <EOL> error_class = BotoServerError <EOL> return callback ( None , error = error_class ( error . code , error . message , response_body ) ) <EOL> obj = cls ( parent ) <EOL> h = boto . handler . XmlHandler ( obj , parent ) <EOL> xml . sax . parseString ( response_body , h ) <EOL> return callback ( obj ) <EOL> def make_request ( self , action , params = { } , path = '<STR_LIT:/>' , verb = '<STR_LIT:GET>' , callback = None ) : <EOL> '''<STR_LIT>''' <EOL> request = HTTPRequest ( '<STR_LIT>' % self . host , <EOL> method = verb ) <EOL> request . params = params <EOL> request . auth_path = '<STR_LIT:/>' <EOL> request . host = self . host <EOL> if action : <EOL> request . params [ '<STR_LIT>' ] = action <EOL> if self . APIVersion : <EOL> request . params [ '<STR_LIT>' ] = self . APIVersion <EOL> self . _auth_handler . add_auth ( request ) <EOL> self . http_client . fetch ( request , functools . partial ( self . _finish_make_request , callback = callback ) ) <EOL> def _finish_make_request ( self , response , callback ) : <EOL> if response . error : <EOL> return callback ( response . body , error = response . error ) <EOL> return callback ( response . body ) </s>
