<s> """<STR_LIT>""" <EOL> import time <EOL> import base64 <EOL> import hmac <EOL> import hashlib <EOL> import requests <EOL> from route53 . exceptions import Route53Error <EOL> class BaseTransport ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , connection ) : <EOL> """<STR_LIT>""" <EOL> self . connection = connection <EOL> @ property <EOL> def endpoint ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . connection . _endpoint <EOL> def _hmac_sign_string ( self , string_to_sign ) : <EOL> """<STR_LIT>""" <EOL> new_hmac = hmac . new ( <EOL> self . connection . _aws_secret_access_key . encode ( '<STR_LIT:utf-8>' ) , <EOL> digestmod = hashlib . sha256 <EOL> ) <EOL> new_hmac . update ( string_to_sign . encode ( '<STR_LIT:utf-8>' ) ) <EOL> digest = new_hmac . digest ( ) <EOL> return base64 . b64encode ( digest ) . decode ( '<STR_LIT:utf-8>' ) <EOL> def get_request_headers ( self ) : <EOL> """<STR_LIT>""" <EOL> date_header = time . asctime ( time . gmtime ( ) ) <EOL> signing_key = self . _hmac_sign_string ( date_header ) <EOL> auth_header = "<STR_LIT>" % ( <EOL> self . connection . _aws_access_key_id , <EOL> signing_key , <EOL> ) <EOL> return { <EOL> '<STR_LIT>' : auth_header , <EOL> '<STR_LIT>' : date_header , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } <EOL> def send_request ( self , path , data , method ) : <EOL> """<STR_LIT>""" <EOL> headers = self . get_request_headers ( ) <EOL> if method == '<STR_LIT:GET>' : <EOL> return self . _send_get_request ( path , data , headers ) <EOL> elif method == '<STR_LIT:POST>' : <EOL> return self . _send_post_request ( path , data , headers ) <EOL> elif method == '<STR_LIT>' : <EOL> return self . _send_delete_request ( path , headers ) <EOL> else : <EOL> raise Route53Error ( "<STR_LIT>" % method ) <EOL> def _send_get_request ( self , path , params , headers ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError <EOL> def _send_post_request ( self , path , data , headers ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError <EOL> def _send_delete_request ( self , path , headers ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError <EOL> class RequestsTransport ( BaseTransport ) : <EOL> """<STR_LIT>""" <EOL> def _send_get_request ( self , path , params , headers ) : <EOL> """<STR_LIT>""" <EOL> r = requests . get ( self . endpoint + path , params = params , headers = headers ) <EOL> r . raise_for_status ( ) <EOL> return r . text <EOL> def _send_post_request ( self , path , data , headers ) : <EOL> """<STR_LIT>""" <EOL> r = requests . post ( self . endpoint + path , data = data , headers = headers ) <EOL> return r . text <EOL> def _send_delete_request ( self , path , headers ) : <EOL> """<STR_LIT>""" <EOL> r = requests . delete ( self . endpoint + path , headers = headers ) <EOL> return r . text </s>
