예제 #1
0
 def post_request(self, path, params, cls, body='', headers={}, isXML=True):
     """Make a POST request, optionally with a content body,
        and return the response, optionally as raw text.
        Modelled off of the inherited get_object/make_request flow.
     """
     request = self.build_base_http_request('POST',
                                            path,
                                            None,
                                            data=body,
                                            params=params,
                                            headers=headers,
                                            host=self.server_name())
     response = self._mexe(request, override_num_retries=None)
     body = response.read()
     boto.log.debug(body)
     if not body:
         boto.log.error('Null body %s' % body)
         raise self.ResponseError(response.status, response.reason, body)
     if response.status != 200:
         boto.log.error('%s %s' % (response.status, response.reason))
         boto.log.error('%s' % body)
         raise self.ResponseError(response.status, response.reason, body)
     if not isXML:
         digest = response.getheader('Content-MD5')
         assert content_md5(body) == digest
         return body
     obj = cls(self)
     h = XmlHandler(obj, self)
     xml.sax.parseString(body, h)
     return obj
예제 #2
0
 def delete_message(self, message):
     path = '%s/%s' % (self.id, message.id)
     response = self.connection.make_request('DELETE', path)
     body = response.read()
     if response.status >= 300:
         raise SQSError(response.status, response.reason, body)
     rs = ResultSet()
     h = XmlHandler(rs, self.connection)
     xml.sax.parseString(body, h)
     return rs
예제 #3
0
 def get_messages(self, num_messages=1, visibility_timeout=None):
     path = '%s/front?NumberOfMessages=%d' % (self.id, num_messages)
     if visibility_timeout:
         path = '%s&VisibilityTimeout=%d' % (path, visibility_timeout)
     response = self.connection.make_request('GET', path)
     body = response.read()
     if response.status >= 300:
         raise SQSError(response.status, response.reason, body)
     rs = ResultSet([('Message', self.message_class)])
     h = XmlHandler(rs, self)
     xml.sax.parseString(body, h)
     return rs
예제 #4
0
 def write(self, message):
     """
     Add a single message to the queue.
     Inputs:
         message - The message to be written to the queue
     Returns:
         None
     """
     path = '%s/back' % self.id
     message.queue = self
     response = self.connection.make_request('PUT', path, None,
                                             message.get_body_encoded())
     body = response.read()
     if response.status >= 300:
         raise SQSError(response.status, response.reason, body)
     handler = XmlHandler(message, self.connection)
     xml.sax.parseString(body, handler)
     return None
예제 #5
0
 def test_message_id_available(self):
     import xml.sax
     from boto.resultset import ResultSet
     from boto.handler import XmlHandler
     sample_value = 'abcdef'
     body = """<?xml version="1.0"?>
         <ReceiveMessageResponse>
           <ReceiveMessageResult>
             <Message>
               <Body>%s</Body>
               <ReceiptHandle>%s</ReceiptHandle>
               <MessageId>%s</MessageId>
             </Message>
           </ReceiveMessageResult>
         </ReceiveMessageResponse>""" % tuple([sample_value] * 3)
     rs = ResultSet([('Message', DecodeExceptionRaisingMessage)])
     h = XmlHandler(rs, None)
     with self.assertRaises(SQSDecodeError) as context:
         xml.sax.parseString(body.encode('utf-8'), h)
     message = context.exception.message
     self.assertEquals(message.id, sample_value)
     self.assertEquals(message.receipt_handle, sample_value)
예제 #6
0
파일: s3.py 프로젝트: homm/boto_addins
    async def get_acl(self,
                      key_name='',
                      headers=None,
                      version_id=None,
                      attempts=3):
        query_args = 'acl'
        if version_id:
            query_args += '&versionId=%s' % version_id

        resp = await self.connection.generate_request(
            'GET',
            self.name,
            key_name,
            query_args=query_args,
            headers=headers,
            attempts=attempts,
        )

        policy = Policy(self)
        h = XmlHandler(policy, self)
        xml.sax.parseString(resp.body, h)
        return policy
예제 #7
0
 def _parse_response(self, parser, contenttype, body):
     if not contenttype.startswith('text/xml'):
         return body
     handler = XmlHandler(parser, self)
     xml.sax.parseString(body, handler)
     return parser
        current_cors_config = bucket.get_cors()
        current_cors_xml = current_cors_config.to_xml()
    except S3ResponseError, e:
        if e.error_code == "NoSuchCORSConfiguration":
            current_cors_xml = None
        else:
            module.fail_json(msg=e.message)

    if cors_xml is not None:
        cors_rule_change = False
        if current_cors_xml is None:
            cors_rule_change = True  # Create
        else:
            # Convert cors_xml to a Boto CorsConfiguration object for comparison
            cors_config = CORSConfiguration()
            h = XmlHandler(cors_config, bucket)
            xml.sax.parseString(cors_xml, h)
            if cors_config.to_xml() != current_cors_config.to_xml():
                cors_rule_change = True  # Update

        if cors_rule_change:
            try:
                bucket.set_cors_xml(cors_xml)
                changed = True
                current_cors_xml = bucket.get_cors().to_xml()
            except S3ResponseError, e:
                module.fail_json(msg=e.message)
    elif current_cors_xml is not None:
        try:
            bucket.delete_cors()
            changed = True
예제 #9
0
 def _parse_response(self, cls, body):
     obj = cls(self)
     h = XmlHandler(obj, self)
     xml.sax.parseString(body, h)
     return obj