<s> from boto . connection import AWSQueryConnection <EOL> from boto . sqs . regioninfo import SQSRegionInfo <EOL> from boto . sqs . queue import Queue <EOL> from boto . sqs . message import Message <EOL> from boto . sqs . attributes import Attributes <EOL> from boto . sqs . batchresults import BatchResults <EOL> from boto . exception import SQSError <EOL> class SQSConnection ( AWSQueryConnection ) : <EOL> """<STR_LIT>""" <EOL> DefaultRegionName = '<STR_LIT>' <EOL> DefaultRegionEndpoint = '<STR_LIT>' <EOL> APIVersion = '<STR_LIT>' <EOL> DefaultContentType = '<STR_LIT>' <EOL> ResponseError = SQSError <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> security_token = None ) : <EOL> if not region : <EOL> region = SQSRegionInfo ( self , self . DefaultRegionName , <EOL> self . DefaultRegionEndpoint ) <EOL> self . region = region <EOL> AWSQueryConnection . __init__ ( self , aws_access_key_id , <EOL> aws_secret_access_key , <EOL> is_secure , port , <EOL> proxy , proxy_port , <EOL> proxy_user , proxy_pass , <EOL> self . region . endpoint , debug , <EOL> https_connection_factory , path , <EOL> security_token = security_token ) <EOL> def _required_auth_capability ( self ) : <EOL> return [ '<STR_LIT>' ] <EOL> def create_queue ( self , queue_name , visibility_timeout = None ) : <EOL> """<STR_LIT>""" <EOL> params = { '<STR_LIT>' : queue_name } <EOL> if visibility_timeout : <EOL> params [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> params [ '<STR_LIT>' ] = int ( visibility_timeout ) <EOL> return self . get_object ( '<STR_LIT>' , params , Queue ) <EOL> def delete_queue ( self , queue , force_deletion = False ) : <EOL> """<STR_LIT>""" <EOL> return self . get_status ( '<STR_LIT>' , None , queue . id ) <EOL> def get_queue_attributes ( self , queue , attribute = '<STR_LIT>' ) : <EOL> """<STR_LIT>""" <EOL> params = { '<STR_LIT>' : attribute } <EOL> return self . get_object ( '<STR_LIT>' , params , <EOL> Attributes , queue . id ) <EOL> def set_queue_attribute ( self , queue , attribute , value ) : <EOL> params = { '<STR_LIT>' : attribute , '<STR_LIT>' : value } <EOL> return self . get_status ( '<STR_LIT>' , params , queue . id ) <EOL> def receive_message ( self , queue , number_messages = <NUM_LIT:1> , <EOL> visibility_timeout = None , attributes = None ) : <EOL> """<STR_LIT>""" <EOL> params = { '<STR_LIT>' : number_messages } <EOL> if visibility_timeout : <EOL> params [ '<STR_LIT>' ] = visibility_timeout <EOL> if attributes : <EOL> self . build_list_params ( params , attributes , '<STR_LIT>' ) <EOL> return self . get_list ( '<STR_LIT>' , params , <EOL> [ ( '<STR_LIT>' , queue . message_class ) ] , <EOL> queue . id , queue ) <EOL> def delete_message ( self , queue , message ) : <EOL> """<STR_LIT>""" <EOL> params = { '<STR_LIT>' : message . receipt_handle } <EOL> return self . get_status ( '<STR_LIT>' , params , queue . id ) <EOL> def delete_message_batch ( self , queue , messages ) : <EOL> """<STR_LIT>""" <EOL> params = { } <EOL> for i , msg in enumerate ( messages ) : <EOL> prefix = '<STR_LIT>' <EOL> p_name = '<STR_LIT>' % ( prefix , ( i + <NUM_LIT:1> ) ) <EOL> params [ p_name ] = msg . id <EOL> p_name = '<STR_LIT>' % ( prefix , ( i + <NUM_LIT:1> ) ) <EOL> params [ p_name ] = msg . receipt_handle <EOL> return self . get_object ( '<STR_LIT>' , params , BatchResults , <EOL> queue . id , verb = '<STR_LIT:POST>' ) <EOL> def delete_message_from_handle ( self , queue , receipt_handle ) : <EOL> """<STR_LIT>""" <EOL> params = { '<STR_LIT>' : receipt_handle } <EOL> return self . get_status ( '<STR_LIT>' , params , queue . id ) <EOL> def send_message ( self , queue , message_content , delay_seconds = None ) : <EOL> params = { '<STR_LIT>' : message_content } <EOL> if delay_seconds : <EOL> params [ '<STR_LIT>' ] = int ( delay_seconds ) <EOL> return self . get_object ( '<STR_LIT>' , params , Message , <EOL> queue . id , verb = '<STR_LIT:POST>' ) <EOL> def send_message_batch ( self , queue , messages ) : <EOL> """<STR_LIT>""" <EOL> params = { } <EOL> for i , msg in enumerate ( messages ) : <EOL> p_name = '<STR_LIT>' % ( i + <NUM_LIT:1> ) <EOL> params [ p_name ] = msg [ <NUM_LIT:0> ] <EOL> p_name = '<STR_LIT>' % ( i + <NUM_LIT:1> ) <EOL> params [ p_name ] = msg [ <NUM_LIT:1> ] <EOL> p_name = '<STR_LIT>' % ( i + <NUM_LIT:1> ) <EOL> params [ p_name ] = msg [ <NUM_LIT:2> ] <EOL> return self . get_object ( '<STR_LIT>' , params , BatchResults , <EOL> queue . id , verb = '<STR_LIT:POST>' ) <EOL> def change_message_visibility ( self , queue , receipt_handle , <EOL> visibility_timeout ) : <EOL> """<STR_LIT>""" <EOL> params = { '<STR_LIT>' : receipt_handle , <EOL> '<STR_LIT>' : visibility_timeout } <EOL> return self . get_status ( '<STR_LIT>' , params , queue . id ) <EOL> def change_message_visibility_batch ( self , queue , messages ) : <EOL> """<STR_LIT>""" <EOL> params = { } <EOL> for i , t in enumerate ( messages ) : <EOL> prefix = '<STR_LIT>' <EOL> p_name = '<STR_LIT>' % ( prefix , ( i + <NUM_LIT:1> ) ) <EOL> params [ p_name ] = t [ <NUM_LIT:0> ] . id <EOL> p_name = '<STR_LIT>' % ( prefix , ( i + <NUM_LIT:1> ) ) <EOL> params [ p_name ] = t [ <NUM_LIT:0> ] . receipt_handle <EOL> p_name = '<STR_LIT>' % ( prefix , ( i + <NUM_LIT:1> ) ) <EOL> params [ p_name ] = t [ <NUM_LIT:1> ] <EOL> return self . get_object ( '<STR_LIT>' , <EOL> params , BatchResults , <EOL> queue . id , verb = '<STR_LIT:POST>' ) <EOL> def get_all_queues ( self , prefix = '<STR_LIT>' ) : <EOL> """<STR_LIT>""" <EOL> params = { } <EOL> if prefix : <EOL> params [ '<STR_LIT>' ] = prefix <EOL> return self . get_list ( '<STR_LIT>' , params , [ ( '<STR_LIT>' , Queue ) ] ) <EOL> def get_queue ( self , queue_name ) : <EOL> """<STR_LIT>""" <EOL> params = { '<STR_LIT>' : queue_name } <EOL> try : <EOL> return self . get_object ( '<STR_LIT>' , params , Queue ) <EOL> except SQSError : <EOL> return None <EOL> lookup = get_queue <EOL> def add_permission ( self , queue , label , aws_account_id , action_name ) : <EOL> """<STR_LIT>""" <EOL> params = { '<STR_LIT>' : label , <EOL> '<STR_LIT>' : aws_account_id , <EOL> '<STR_LIT>' : action_name } <EOL> return self . get_status ( '<STR_LIT>' , params , queue . id ) <EOL> def remove_permission ( self , queue , label ) : <EOL> """<STR_LIT>""" <EOL> params = { '<STR_LIT>' : label } <EOL> return self . get_status ( '<STR_LIT>' , params , queue . id ) </s>
