<s> """<STR_LIT>""" <EOL> from __future__ import with_statement <EOL> import base64 <EOL> import errno <EOL> import httplib <EOL> import os <EOL> import Queue <EOL> import random <EOL> import re <EOL> import socket <EOL> import sys <EOL> import time <EOL> import urllib , urlparse <EOL> import xml . sax <EOL> import boto . auth <EOL> import boto . auth_handler <EOL> import boto <EOL> import boto . utils <EOL> import boto . handler <EOL> import boto . cacerts <EOL> from boto import config , UserAgent <EOL> from boto . exception import AWSConnectionError , BotoClientError , BotoServerError <EOL> from boto . provider import Provider <EOL> from boto . resultset import ResultSet <EOL> from boto . connection import * <EOL> import StringIO <EOL> import httplib <EOL> import mimetools <EOL> import tornado . httpclient <EOL> import tornado . httputil <EOL> class AsyncHTTPConnection ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , host , port = None , strict = None , timeout = <NUM_LIT> , http_client = None , ** kwargs ) : <EOL> """<STR_LIT:U+0020>""" <EOL> self . method = '<STR_LIT:GET>' <EOL> self . host = host <EOL> self . port = port <EOL> self . path = '<STR_LIT:/>' <EOL> self . headers = [ ] <EOL> self . body = None <EOL> self . timeout = timeout <EOL> self . http_client = http_client if http_client else tornado . httpclient . AsyncHTTPClient ( ** kwargs ) <EOL> def __repr__ ( self ) : <EOL> return '<STR_LIT>' % ( repr ( self . getrequest ( ) ) ) <EOL> def request ( self , method , path , body = None , headers = None ) : <EOL> self . path = path <EOL> self . method = method <EOL> if body is not None : <EOL> if hasattr ( body , '<STR_LIT>' ) : <EOL> self . body = body . read ( ) <EOL> else : <EOL> self . body = body if body else None <EOL> if headers is not None : <EOL> self . headers += [ ( k , headers [ k ] ) for k in headers ] <EOL> def getrequest ( self , scheme = '<STR_LIT:http>' ) : <EOL> if self . port and ( ( scheme == '<STR_LIT:http>' and self . port != <NUM_LIT> ) or ( scheme == '<STR_LIT>' and self . port != <NUM_LIT> ) ) : <EOL> host = "<STR_LIT>" % ( self . host , self . port ) <EOL> else : <EOL> host = self . host <EOL> url = urlparse . urlunsplit ( ( scheme , host , self . path , '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> headers = tornado . httputil . HTTPHeaders ( ) <EOL> for ( k , v ) in self . headers : <EOL> headers . add ( k , v ) <EOL> request = tornado . httpclient . HTTPRequest ( <EOL> url , method = self . method , headers = headers , body = self . body , <EOL> connect_timeout = self . timeout , request_timeout = self . timeout , <EOL> validate_cert = False , <EOL> ) <EOL> return request <EOL> def getresponse ( self , callback = None ) : <EOL> def fetched ( tornado_response ) : <EOL> if callable ( callback ) : <EOL> callback ( AsyncHTTPResponse ( tornado_response ) ) <EOL> self . http_client . fetch ( self . getrequest ( ) , callback = fetched ) <EOL> def set_debuglevel ( self , level ) : <EOL> pass <EOL> def connect ( self ) : <EOL> pass <EOL> def close ( self ) : <EOL> pass <EOL> def putrequest ( self , method , path , ** kwargs ) : <EOL> self . method = method <EOL> self . path = path <EOL> def putheader ( self , header , argument ) : <EOL> self . headers . append ( ( header , argument ) ) <EOL> def endheaders ( self ) : <EOL> pass <EOL> def send ( self , data ) : <EOL> if self . body is not None and data : <EOL> self . body += data <EOL> else : <EOL> self . body = data if data else None <EOL> class AsyncHTTPSConnection ( AsyncHTTPConnection ) : <EOL> def getrequest ( self , scheme = '<STR_LIT>' ) : <EOL> return AsyncHTTPConnection . getrequest ( self , scheme = scheme ) <EOL> class AsyncHTTPResponse ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , tornado_response ) : <EOL> self . response = tornado_response <EOL> self . _msg = None <EOL> self . version = <NUM_LIT:10> <EOL> self . status = self . response . code <EOL> self . reason = self . response . error . message if self . response . error else '<STR_LIT>' <EOL> def __repr__ ( self ) : <EOL> return '<STR_LIT>' % ( repr ( self . response ) ) <EOL> def read ( self , amt = None ) : <EOL> return self . response . body <EOL> def getheader ( self , name , default = None ) : <EOL> return self . response . headers . get ( name , default ) <EOL> def getheaders ( self ) : <EOL> return map ( lambda ( k , v ) : ( k , v ) , self . response . headers . get_all ( ) ) <EOL> def _get_msg ( self ) : <EOL> if self . _msg is None : <EOL> fp = StringIO . StringIO ( "<STR_LIT:\r\n>" . join ( map ( lambda ( k , v ) : "<STR_LIT>" % ( k , v ) , self . response . headers . get_all ( ) ) ) ) <EOL> self . _msg = mimetools . Message ( fp ) <EOL> return self . _msg <EOL> msg = property ( _get_msg ) <EOL> class AsyncConnection ( object ) : <EOL> def __init__ ( self , http_client = None , ** kwargs ) : <EOL> self . _httpclient = http_client if http_client else tornado . httpclient . AsyncHTTPClient ( ** kwargs ) <EOL> def get_http_connection ( self , host , is_secure ) : <EOL> """<STR_LIT>""" <EOL> if is_secure : <EOL> return AsyncHTTPSConnection ( host , http_client = self . _httpclient ) <EOL> else : <EOL> return AsyncHTTPConnection ( host , http_client = self . _httpclient ) <EOL> def _mexe ( self , request , sender = None , callback = None ) : <EOL> boto . log . debug ( '<STR_LIT>' % request . method ) <EOL> boto . log . debug ( '<STR_LIT>' % request . path ) <EOL> boto . log . debug ( '<STR_LIT>' % request . body ) <EOL> boto . log . debug ( '<STR_LIT>' % request . headers ) <EOL> boto . log . debug ( '<STR_LIT>' % request . host ) <EOL> connection = self . get_http_connection ( request . host , self . is_secure ) <EOL> request . authorize ( connection = self ) <EOL> if callable ( sender ) : <EOL> sender ( connection , request . method , request . path , <EOL> request . body , request . headers , callback ) <EOL> else : <EOL> connection . request ( request . method , request . path , request . body , <EOL> request . headers ) <EOL> connection . getresponse ( callback = callback ) <EOL> class AsyncAWSAuthConnection ( AsyncConnection , boto . connection . AWSAuthConnection ) : <EOL> def __init__ ( self , host , http_client = None , http_client_params = { } , ** kwargs ) : <EOL> AsyncConnection . __init__ ( self , http_client = http_client , ** http_client_params ) <EOL> boto . connection . AWSAuthConnection . __init__ ( self , host , ** kwargs ) <EOL> def make_request ( self , method , path , headers = None , data = '<STR_LIT>' , host = None , auth_path = None , sender = None , callback = None , ** kwargs ) : <EOL> request = self . build_base_http_request ( method , path , auth_path , <EOL> { } , headers , data , host ) <EOL> self . _mexe ( request , sender = sender , callback = callback ) <EOL> class AsyncAWSQueryConnection ( AsyncConnection , boto . connection . AWSQueryConnection ) : <EOL> def __init__ ( self , http_client = None , http_client_params = { } , ** kwargs ) : <EOL> AsyncConnection . __init__ ( self , http_client = http_client , ** http_client_params ) <EOL> boto . connection . AWSQueryConnection . __init__ ( self , ** kwargs ) <EOL> def make_request ( self , action , params , path , verb , callback = None ) : <EOL> request = self . build_base_http_request ( verb , path , None , <EOL> params , { } , '<STR_LIT>' , self . server_name ( ) ) <EOL> if action : <EOL> request . params [ '<STR_LIT>' ] = action <EOL> request . params [ '<STR_LIT>' ] = self . APIVersion <EOL> self . _mexe ( request , callback = callback ) <EOL> def get_list ( self , action , params , markers , path = '<STR_LIT:/>' , <EOL> parent = None , verb = '<STR_LIT:GET>' , callback = None ) : <EOL> if not parent : <EOL> parent = self <EOL> def list_got ( response ) : <EOL> body = response . read ( ) <EOL> boto . log . debug ( body ) <EOL> if not body : <EOL> boto . log . error ( '<STR_LIT>' % body ) <EOL> raise self . ResponseError ( response . status , response . reason , body ) <EOL> elif response . status == <NUM_LIT:200> : <EOL> rs = ResultSet ( markers ) <EOL> h = boto . handler . XmlHandler ( rs , parent ) <EOL> xml . sax . parseString ( body , h ) <EOL> if callable ( callback ) : <EOL> callback ( rs ) <EOL> else : <EOL> boto . log . error ( '<STR_LIT>' % ( response . status , response . reason ) ) <EOL> boto . log . error ( '<STR_LIT:%s>' % body ) <EOL> raise self . ResponseError ( response . status , response . reason , body ) <EOL> self . make_request ( action , params , path , verb , callback = list_got ) <EOL> def get_object ( self , action , params , cls , path = '<STR_LIT:/>' , <EOL> parent = None , verb = '<STR_LIT:GET>' , callback = None ) : <EOL> if not parent : <EOL> parent = self <EOL> def object_got ( response ) : <EOL> body = response . read ( ) <EOL> boto . log . debug ( body ) <EOL> if not body : <EOL> boto . log . error ( '<STR_LIT>' % body ) <EOL> raise self . ResponseError ( response . status , response . reason , body ) <EOL> elif response . status == <NUM_LIT:200> : <EOL> obj = cls ( parent ) <EOL> h = boto . handler . XmlHandler ( obj , parent ) <EOL> xml . sax . parseString ( body , h ) <EOL> if callable ( callback ) : <EOL> callback ( obj ) <EOL> else : <EOL> boto . log . error ( '<STR_LIT>' % ( response . status , response . reason ) ) <EOL> boto . log . error ( '<STR_LIT:%s>' % body ) <EOL> raise self . ResponseError ( response . status , response . reason , body ) <EOL> self . make_request ( action , params , path , verb , callback = object_got ) <EOL> def get_status ( self , action , params , path = '<STR_LIT:/>' , parent = None , verb = '<STR_LIT:GET>' , callback = None ) : <EOL> if not parent : <EOL> parent = self <EOL> def status_got ( response ) : <EOL> body = response . read ( ) <EOL> boto . log . debug ( body ) <EOL> if not body : <EOL> boto . log . error ( '<STR_LIT>' % body ) <EOL> raise self . ResponseError ( response . status , response . reason , body ) <EOL> elif response . status == <NUM_LIT:200> : <EOL> rs = ResultSet ( ) <EOL> h = boto . handler . XmlHandler ( rs , parent ) <EOL> xml . sax . parseString ( body , h ) <EOL> if callable ( callback ) : <EOL> callback ( rs . status ) <EOL> else : <EOL> boto . log . error ( '<STR_LIT>' % ( response . status , response . reason ) ) <EOL> boto . log . error ( '<STR_LIT:%s>' % body ) <EOL> raise self . ResponseError ( response . status , response . reason , body ) <EOL> self . make_request ( action , params , path , verb , callback = status_got ) </s>
