Beispiel #1
0
 def _get_data():
     try:
         req = urllib2.Request(url, headers=headers)
         resp = urllib2.urlopen(req)
         return resp.read()
     except urllib2.HTTPError, e:
         tree = XML.loads(e.read())
         raise S3Error(tree, e.code)
Beispiel #2
0
 def _parse_list_buckets(self, data):
     tree = XML.loads(data)
     owner = AmazonUser.from_xml(tree.find('Owner'))
     
     buckets = []
     for ele in tree.find('Buckets').getchildren():
         buckets.append(S3Bucket.from_xml(ele))
         
     return owner, buckets
Beispiel #3
0
 def _parse_get_service(self, data):
     tree = XML.loads(data)
     owner = GSUser.from_xml(tree.find('Owner'))
     
     buckets = []
     for ele in tree.find('Buckets').getchildren():
         buckets.append(GSBucket.from_xml(ele))
         
     return owner, buckets
Beispiel #4
0
    def _parse_list_buckets(self, data):
        tree = XML.loads(data)
        owner = AmazonUser.from_xml(tree.find('Owner'))

        buckets = []
        for ele in tree.find('Buckets').getchildren():
            buckets.append(S3Bucket.from_xml(ele))

        return owner, buckets
Beispiel #5
0
 def _parse_get_acl(self, data):
     tree = XML.loads(data)
     
     owner = GSUser.from_xml(tree.find('Owner'))
     
     grants = []
     for entry in tree.find('Entries').getchildren():
         grants.append(GSAclGrant.from_xml(entry))
            
     return owner, grants
Beispiel #6
0
 def _get_data():
     headers = self.get_headers()
     try:
         opener = urllib2.build_opener(urllib2.HTTPHandler)
         req = urllib2.Request(self.end_point, data=self.data, headers=headers)
         req.get_method = lambda: self.action
         resp = opener.open(req)
         
         if include_headers:
             return resp.read(), resp.headers.dict
         return resp.read()
     except urllib2.HTTPError, e:
         tree = XML.loads(e.read())
         raise S3Error(e.code, tree)
Beispiel #7
0
        def _get_data():
            headers = self.get_headers()
            try:
                opener = urllib2.build_opener(urllib2.HTTPHandler)
                req = urllib2.Request(self.end_point,
                                      data=self.data,
                                      headers=headers)
                req.get_method = lambda: self.action
                resp = opener.open(req)

                if include_headers:
                    return resp.read(), resp.headers.dict
                return resp.read()
            except urllib2.HTTPError, e:
                tree = XML.loads(e.read())
                raise S3Error(e.code, tree)
Beispiel #8
0
 def _parse_get_bucket(self, data):
     tree = XML.loads(data)
     bucket = S3Bucket.from_xml(tree)
     has_next = True if bucket.is_truncated == 'true' else False
     
     objs = []
     for ele in tree.findall('Contents'):
         obj = S3Object.from_xml(ele)
         obj.bucket = bucket
         objs.append(obj)
         
     common_prefix = []
     for ele in tree.findall('CommonPrefixes'):
         prefix = ele.find('Prefix')
         if hasattr(prefix, 'text'):
             common_prefix.append(prefix.text)
         
     return objs, common_prefix, has_next
Beispiel #9
0
 def _parse_get_bucket(self, data):
     tree = XML.loads(data)
     bucket = GSBucket.from_xml(tree)
     has_next = True if bucket.is_truncated == 'true' else False
     
     objs = []
     for ele in tree.findall('Contents'):
         obj = GSObject.from_xml(ele)
         obj.bucket = bucket
         objs.append(obj)
         
     common_prefix = []
     for ele in tree.findall('CommonPrefixes'):
         prefix = ele.find('Prefix')
         if hasattr(prefix, 'text'):
             common_prefix.append(prefix.text)
         
     return objs, common_prefix, has_next
Beispiel #10
0
 def _parse_get_acl(self, data):
     tree = XML.loads(data)
     
     owner = AmazonUser.from_xml(tree.find('Owner'))
     
     grants = {}
     for grant in tree.findall('AccessControlList/Grant'):
         user = AmazonUser.from_xml(grant.find('Grantee'))
         permission = grant.find('Permission').text
         
         if not user.display_name and user.uri == ALL_USERS_URI:
             user.display_name = 'AllUsers'
         
         if user not in grants:
             grants[user] = [permission]
         else:
             if permission not in grants[user]:
                 grants[user].append(permission)
            
     return owner, grants
Beispiel #11
0
    def _parse_get_acl(self, data):
        tree = XML.loads(data)

        owner = AmazonUser.from_xml(tree.find('Owner'))

        grants = {}
        for grant in tree.findall('AccessControlList/Grant'):
            user = AmazonUser.from_xml(grant.find('Grantee'))
            permission = grant.find('Permission').text

            if not user.display_name and user.uri == ALL_USERS_URI:
                user.display_name = 'AllUsers'

            if user not in grants:
                grants[user] = [permission]
            else:
                if permission not in grants[user]:
                    grants[user].append(permission)

        return owner, grants