How to use _fix_endpoint method in localstack

Best Python code snippet using localstack_python

sqs_client.py

Source: sqs_client.py Github

copy

Full Screen

...38 def __init__(self, credentials, url=None, proxyinfo=None):39 if not url:40 endpoint = SQSClient.endpointForRegion('us-east-1')41 else:42 endpoint = self._fix_endpoint(url)43 super(SQSClient, self).__init__(credentials, False, endpoint, xmlns='http:/​/​queue.amazonaws.com/​doc/​%s/​' % SQSClient._apiVersion, proxyinfo=proxyinfo)44 log.debug("SQS client initialized with endpoint %s", endpoint)45 # SQS SSL certificates have CNs based on queue.amazonaws.com46 # Python2.6 will fail to verify the hostname of the certificate47 # Due to http:/​/​bugs.python.org/​issue13034 only being fixed in 2.7 and 3.248 def _fix_endpoint(self, url):49 m = re.match(r'^https:/​/​sqs\.(.*?)\.amazonaws\.com(.*)$', url)50 if m:51 if m.group(1) == 'us-east-1':52 return 'https:/​/​queue.amazonaws.com%s' % m.group(2)53 return 'https:/​/​%s.queue.amazonaws.com%s' % m.group(1, 2)54 return url55 @classmethod56 def endpointForRegion(cls, region):57 if region == 'us-east-1':58 return 'https:/​/​queue.amazonaws.com'59 return 'https:/​/​%s.queue.amazonaws.com' % region60 @retry_on_failure(http_error_extractor=aws_client.Client._get_xml_extractor(_xmlns))61 def receive_message(self, queue_url, attributes=None, max_messages=1, visibility_timeout=None,62 request_credentials=None, wait_time=None):63 """64 Calls ReceiveMessage and returns a list of Message objects65 Throws an IOError on failure.66 """67 if not attributes: attributes = ['All']68 queue_url = self._fix_endpoint(queue_url)69 log.debug("Receiving messages for queue %s", queue_url)70 params = { "Action" : "ReceiveMessage", "Version" : SQSClient._apiVersion, "MaxNumberOfMessages" : str(max_messages) }71 for i in range(len(attributes)):72 params['AttributeName.%s' % (i + 1)]=attributes[i]73 if visibility_timeout:74 params['VisibilityTimeout'] = str(visibility_timeout)75 if wait_time:76 params['WaitTimeSeconds'] = str(wait_time)77 response_content = self._call(params, queue_url, request_credentials,78 timeout=wait_time + 3 if wait_time else None).content79 return Message._parse_list(StringIO.StringIO(response_content), self._xmlns)80 @retry_on_failure(http_error_extractor=aws_client.Client._get_xml_extractor(_xmlns))81 def send_message(self, queue_url, message_body, delay_seconds=None, request_credentials=None):82 """83 Calls SendMessage and returns a tuple of (MessageId, MD5OfMessageBody)84 Throws an IOError on failure.85 """86 queue_url = self._fix_endpoint(queue_url)87 log.debug("Sending %s to queue %s", message_body, queue_url)88 params = { "Action" : "SendMessage", "Version" : SQSClient._apiVersion, "MessageBody" : message_body}89 if delay_seconds:90 params["DelaySeconds"] = delay_seconds91 root = ElementTree.ElementTree(file=StringIO.StringIO(self._call(params, queue_url, request_credentials, verb='POST').content))92 message_id = root.findtext('{%s}SendMessageResult/​{%s}MessageId' % (self._xmlns, self._xmlns))93 md5_of_body = root.findtext('{%s}SendMessageResult/​{%s}MD5OfMessageBody' % (self._xmlns, self._xmlns))94 return (message_id, md5_of_body)95 @retry_on_failure(http_error_extractor=aws_client.Client._get_xml_extractor(_xmlns))96 def delete_message(self, queue_url, receipt_handle, request_credentials=None):97 """98 Calls DeleteMessage on a specified receipt handle99 Throws an IOError on failure.100 """101 queue_url = self._fix_endpoint(queue_url)102 log.debug("Deleting %s from queue %s", receipt_handle, queue_url)103 params = { "Action" : "DeleteMessage", "Version" : SQSClient._apiVersion, "ReceiptHandle" : receipt_handle}104 self._call(params, queue_url, request_credentials)105class Message(object):106 """A message off of an SQS queue"""107 @classmethod108 def _parse_list(cls, data, xmlns):109 if not data:110 return []111 root = ElementTree.ElementTree(file=data)112 msgs = root.findall('{%s}ReceiveMessageResult/​{%s}Message' % (xmlns, xmlns))113 return [cls._from_elem(elem, xmlns) for elem in msgs]114 @classmethod115 def _from_elem(cls, elem, xmlns):...

Full Screen

Full Screen

Blogs

Check out the latest blogs from LambdaTest on this topic:

13 Best Java Testing Frameworks For 2023

The fact is not alien to us anymore that cross browser testing is imperative to enhance your application’s user experience. Enhanced knowledge of popular and highly acclaimed testing frameworks goes a long way in developing a new app. It holds more significance if you are a full-stack developer or expert programmer.

QA Innovation – Using the senseshaping concept to discover customer needs

QA Innovation - Using the senseshaping concept to discover customer needsQA testers have a unique role and responsibility to serve the customer. Serving the customer in software testing means protecting customers from application defects, failures, and perceived failures from missing or misunderstood requirements. Testing for known requirements based on documentation or discussion is the core of the testing profession. One unique way QA testers can both differentiate themselves and be innovative occurs when senseshaping is used to improve the application user experience.

Best 23 Web Design Trends To Follow In 2023

Having a good web design can empower business and make your brand stand out. According to a survey by Top Design Firms, 50% of users believe that website design is crucial to an organization’s overall brand. Therefore, businesses should prioritize website design to meet customer expectations and build their brand identity. Your website is the face of your business, so it’s important that it’s updated regularly as per the current web design trends.

Acquiring Employee Support for Change Management Implementation

Enterprise resource planning (ERP) is a form of business process management software—typically a suite of integrated applications—that assists a company in managing its operations, interpreting data, and automating various back-office processes. The introduction of a new ERP system is analogous to the introduction of a new product into the market. If the product is not handled appropriately, it will fail, resulting in significant losses for the business. Most significantly, the employees’ time, effort, and morale would suffer as a result of the procedure.

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run localstack automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful