Ejemplo n.º 1
0
    def get_response(self, action, params, page=0, itemSet=None):
        """
        Utility method to handle calls to ECS and parsing of responses.
        """
        params['Service'] = "AWSECommerceService"
        params['Operation'] = action
        if page:
            params['ItemPage'] = page
        response = self.make_request(None, params, "/onca/xml")
        body = response.read().decode('utf-8')
        fcu_boto.log.debug(body)

        if response.status != 200:
            fcu_boto.log.error('%s %s' % (response.status, response.reason))
            fcu_boto.log.error('%s' % body)
            raise BotoServerError(response.status, response.reason, body)

        if itemSet is None:
            rs = ItemSet(self, action, params, page)
        else:
            rs = itemSet
        h = handler.XmlHandler(rs, self)
        xml.sax.parseString(body.encode('utf-8'), h)
        if not rs.is_valid:
            raise BotoServerError(response.status,
                                  '{Code}: {Message}'.format(**rs.errors[0]))
        return rs
Ejemplo n.º 2
0
 def _get_acl_helper(self, key_name, headers, query_args):
     """Provides common functionality for get_acl and get_def_acl."""
     body = self._get_xml_acl_helper(key_name, headers, query_args)
     acl = ACL(self)
     h = handler.XmlHandler(acl, self)
     xml.sax.parseString(body, h)
     return acl
Ejemplo n.º 3
0
 def get_all_parts(self,
                   max_parts=None,
                   part_number_marker=None,
                   encoding_type=None):
     """
     Return the uploaded parts of this MultiPart Upload.  This is
     a lower-level method that requires you to manually page through
     results.  To simplify this process, you can just use the
     object itself as an iterator and it will automatically handle
     all of the paging with S3.
     """
     self._parts = []
     query_args = 'uploadId=%s' % self.id
     if max_parts:
         query_args += '&max-parts=%d' % max_parts
     if part_number_marker:
         query_args += '&part-number-marker=%s' % part_number_marker
     if encoding_type:
         query_args += '&encoding-type=%s' % encoding_type
     response = self.bucket.connection.make_request('GET',
                                                    self.bucket.name,
                                                    self.key_name,
                                                    query_args=query_args)
     body = response.read()
     if response.status == 200:
         h = handler.XmlHandler(self, self)
         xml.sax.parseString(body, h)
         return self._parts
Ejemplo n.º 4
0
 def endElement(self, name, value, connection):
     # the answer consists of embedded XML, so it needs to be parsed independantly
     if name == 'Answer':
         answer_rs = ResultSet([('Answer', QuestionFormAnswer)])
         h = handler.XmlHandler(answer_rs, connection)
         value = connection.get_utf8_value(value)
         xml.sax.parseString(value, h)
         self.answers.append(answer_rs)
     else:
         super(Assignment, self).endElement(name, value, connection)
Ejemplo n.º 5
0
 def get_all_buckets(self, headers=None):
     response = self.make_request('GET', headers=headers)
     body = response.read()
     if response.status > 300:
         raise self.provider.storage_response_error(response.status,
                                                    response.reason, body)
     rs = ResultSet([('Bucket', self.bucket_class)])
     h = handler.XmlHandler(rs, self)
     if not isinstance(body, bytes):
         body = body.encode('utf-8')
     xml.sax.parseString(body, h)
     return rs
Ejemplo n.º 6
0
 def _get_config(self, id, resource, config_class):
     uri = '/%s/%s/%s/config' % (self.Version, resource, id)
     response = self.make_request('GET', uri)
     body = response.read()
     fcu_boto.log.debug(body)
     if response.status >= 300:
         raise CloudFrontServerError(response.status, response.reason, body)
     d = config_class(connection=self)
     d.etag = self.get_etag(response)
     h = handler.XmlHandler(d, self)
     xml.sax.parseString(body, h)
     return d
Ejemplo n.º 7
0
 def _process_response(self, response, marker_elems=None):
     """
     Helper to process the xml response from AWS
     """
     body = response.read()
     if self.debug == 2:
         print(body)
     if '<Errors>' not in body.decode('utf-8'):
         rs = ResultSet(marker_elems)
         h = handler.XmlHandler(rs, self)
         xml.sax.parseString(body, h)
         return rs
     else:
         raise MTurkRequestError(response.status, response.reason, body)
Ejemplo n.º 8
0
    def get_attributes(self,
                       domain_or_name,
                       item_name,
                       attribute_names=None,
                       consistent_read=False,
                       item=None):
        """
        Retrieve attributes for a given item in a domain.

        :type domain_or_name: string or :class:`fcu_boto.sdb.domain.Domain` object.
        :param domain_or_name: Either the name of a domain or a Domain object

        :type item_name: string
        :param item_name: The name of the item whose attributes are
            being retrieved.

        :type attribute_names: string or list of strings
        :param attribute_names: An attribute name or list of attribute names.
            This parameter is optional.  If not supplied, all attributes will
            be retrieved for the item.

        :type consistent_read: bool
        :param consistent_read: When set to true, ensures that the most recent
            data is returned.

        :type item: :class:`fcu_boto.sdb.item.Item`
        :keyword item: Instead of instantiating a new Item object, you may
            specify one to update.

        :rtype: :class:`fcu_boto.sdb.item.Item`
        :return: An Item with the requested attribute name/values set on it
        """
        domain, domain_name = self.get_domain_and_name(domain_or_name)
        params = {'DomainName': domain_name, 'ItemName': item_name}
        if consistent_read:
            params['ConsistentRead'] = 'true'
        if attribute_names:
            if not isinstance(attribute_names, list):
                attribute_names = [attribute_names]
            self.build_list_params(params, attribute_names, 'AttributeName')
        response = self.make_request('GetAttributes', params)
        body = response.read()
        if response.status == 200:
            if item is None:
                item = self.item_cls(domain, item_name)
            h = handler.XmlHandler(item, self)
            xml.sax.parseString(body, h)
            return item
        else:
            raise SDBResponseError(response.status, response.reason, body)
Ejemplo n.º 9
0
 def _get_info(self, id, resource, dist_class):
     uri = '/%s/%s/%s' % (self.Version, resource, id)
     response = self.make_request('GET', uri)
     body = response.read()
     fcu_boto.log.debug(body)
     if response.status >= 300:
         raise CloudFrontServerError(response.status, response.reason, body)
     d = dist_class(connection=self)
     response_headers = response.msg
     for key in response_headers.keys():
         if key.lower() == 'etag':
             d.etag = response_headers[key]
     h = handler.XmlHandler(d, self)
     xml.sax.parseString(body, h)
     return d
Ejemplo n.º 10
0
 def invalidation_request_status(self,
                                 distribution_id,
                                 request_id,
                                 caller_reference=None):
     uri = '/%s/distribution/%s/invalidation/%s' % (
         self.Version, distribution_id, request_id)
     response = self.make_request('GET', uri, {'Content-Type': 'text/xml'})
     body = response.read()
     if response.status == 200:
         paths = InvalidationBatch([])
         h = handler.XmlHandler(paths, self)
         xml.sax.parseString(body, h)
         return paths
     else:
         raise CloudFrontServerError(response.status, response.reason, body)
Ejemplo n.º 11
0
 def _create_object(self, config, resource, dist_class):
     response = self.make_request('POST',
                                  '/%s/%s' % (self.Version, resource),
                                  {'Content-Type': 'text/xml'},
                                  data=config.to_xml())
     body = response.read()
     fcu_boto.log.debug(body)
     if response.status == 201:
         d = dist_class(connection=self)
         h = handler.XmlHandler(d, self)
         xml.sax.parseString(body, h)
         d.etag = self.get_etag(response)
         return d
     else:
         raise CloudFrontServerError(response.status, response.reason, body)
Ejemplo n.º 12
0
    def get_storage_class(self):
        """
        Returns the StorageClass for the bucket.

        :rtype: str
        :return: The StorageClass for the bucket.
        """
        response = self.connection.make_request('GET',
                                                self.name,
                                                query_args=STORAGE_CLASS_ARG)
        body = response.read()
        if response.status == 200:
            rs = ResultSet(self)
            h = handler.XmlHandler(rs, self)
            xml.sax.parseString(body, h)
            return rs.StorageClass
        else:
            raise self.connection.provider.storage_response_error(
                response.status, response.reason, body)
Ejemplo n.º 13
0
 def _get_all_objects(self,
                      resource,
                      tags,
                      result_set_class=None,
                      result_set_kwargs=None):
     if not tags:
         tags = [('DistributionSummary', DistributionSummary)]
     response = self.make_request('GET',
                                  '/%s/%s' % (self.Version, resource))
     body = response.read()
     fcu_boto.log.debug(body)
     if response.status >= 300:
         raise CloudFrontServerError(response.status, response.reason, body)
     rs_class = result_set_class or ResultSet
     rs_kwargs = result_set_kwargs or dict()
     rs = rs_class(tags, **rs_kwargs)
     h = handler.XmlHandler(rs, self)
     xml.sax.parseString(body, h)
     return rs
Ejemplo n.º 14
0
    def get_cors(self, headers=None):
        """Returns a bucket's CORS XML document.

        :param dict headers: Additional headers to send with the request.
        :rtype: :class:`~.cors.Cors`
        """
        response = self.connection.make_request('GET',
                                                self.name,
                                                query_args=CORS_ARG,
                                                headers=headers)
        body = response.read()
        if response.status == 200:
            # Success - parse XML and return Cors object.
            cors = Cors()
            h = handler.XmlHandler(cors, self)
            xml.sax.parseString(body, h)
            return cors
        else:
            raise self.connection.provider.storage_response_error(
                response.status, response.reason, body)
Ejemplo n.º 15
0
    def get_lifecycle_config(self, headers=None):
        """
        Returns the current lifecycle configuration on the bucket.

        :rtype: :class:`fcu_boto.gs.lifecycle.LifecycleConfig`
        :returns: A LifecycleConfig object that describes all current
            lifecycle rules in effect for the bucket.
        """
        response = self.connection.make_request('GET',
                                                self.name,
                                                query_args=LIFECYCLE_ARG,
                                                headers=headers)
        body = response.read()
        fcu_boto.log.debug(body)
        if response.status == 200:
            lifecycle_config = LifecycleConfig()
            h = handler.XmlHandler(lifecycle_config, self)
            xml.sax.parseString(body, h)
            return lifecycle_config
        else:
            raise self.connection.provider.storage_response_error(
                response.status, response.reason, body)
Ejemplo n.º 16
0
 def create_invalidation_request(self,
                                 distribution_id,
                                 paths,
                                 caller_reference=None):
     """Creates a new invalidation request
         :see: http://goo.gl/8vECq
     """
     # We allow you to pass in either an array or
     # an InvalidationBatch object
     if not isinstance(paths, InvalidationBatch):
         paths = InvalidationBatch(paths)
     paths.connection = self
     uri = '/%s/distribution/%s/invalidation' % (self.Version,
                                                 distribution_id)
     response = self.make_request('POST',
                                  uri, {'Content-Type': 'text/xml'},
                                  data=paths.to_xml())
     body = response.read()
     if response.status == 201:
         h = handler.XmlHandler(paths, self)
         xml.sax.parseString(body, h)
         return paths
     else:
         raise CloudFrontServerError(response.status, response.reason, body)
Ejemplo n.º 17
0
    def get_all_rrsets(self,
                       hosted_zone_id,
                       type=None,
                       name=None,
                       identifier=None,
                       maxitems=None):
        """
        Retrieve the Resource Record Sets defined for this Hosted Zone.
        Returns the raw XML data returned by the Route53 call.

        :type hosted_zone_id: str
        :param hosted_zone_id: The unique identifier for the Hosted Zone

        :type type: str
        :param type: The type of resource record set to begin the record
            listing from.  Valid choices are:

                * A
                * AAAA
                * CNAME
                * MX
                * NS
                * PTR
                * SOA
                * SPF
                * SRV
                * TXT

            Valid values for weighted resource record sets:

                * A
                * AAAA
                * CNAME
                * TXT

            Valid values for Zone Apex Aliases:

                * A
                * AAAA

        :type name: str
        :param name: The first name in the lexicographic ordering of domain
                     names to be retrieved

        :type identifier: str
        :param identifier: In a hosted zone that includes weighted resource
            record sets (multiple resource record sets with the same DNS
            name and type that are differentiated only by SetIdentifier),
            if results were truncated for a given DNS name and type,
            the value of SetIdentifier for the next resource record
            set that has the current DNS name and type

        :type maxitems: int
        :param maxitems: The maximum number of records

        """
        params = {
            'type': type,
            'name': name,
            'identifier': identifier,
            'maxitems': maxitems
        }
        uri = '/%s/hostedzone/%s/rrset' % (self.Version, hosted_zone_id)
        response = self.make_request('GET', uri, params=params)
        body = response.read()
        fcu_boto.log.debug(body)
        if response.status >= 300:
            raise exception.DNSServerError(response.status, response.reason,
                                           body)
        rs = ResourceRecordSets(connection=self, hosted_zone_id=hosted_zone_id)
        h = handler.XmlHandler(rs, self)
        xml.sax.parseString(body, h)
        return rs