Пример #1
0
 def _get_key_internal(self, key_name, headers, query_args_l):
     query_args = query_args_l or None
     response = self.connection.make_request('HEAD', self.name, key_name,
                                             headers=headers,
                                             query_args=query_args)
     response.read()
     # Allow any success status (2xx) - for example this lets us
     # support Range gets, which return status 206:
     if response.status / 100 == 2:
         k = Key(self)
         #provider = self.connection.provider
         #k.metadata = boto.utils.get_aws_metadata(response.msg, provider)
         for field in Key.base_fields:
             k.__dict__[field.lower().replace('-', '_')] = \
                 response.getheader(field)
         # the following machinations are a workaround to the fact that
         # apache/fastcgi omits the content-length header on HEAD
         # requests when the content-length is zero.
         # See http://goo.gl/0Tdax for more details.
         clen = response.getheader('content-length')
         if clen:
             k.size = int(response.getheader('content-length'))
         else:
             k.size = 0
         k.name = key_name
         k.handle_version_headers(response)
         k.handle_encryption_headers(response)
         k.handle_restore_headers(response)
         k.handle_addl_headers(response.getheaders())
         return k, response
     else:
         if response.status == 404:
             return None, response
         else:
             raise S3ResponseError(response.status, response.reason, response.body)
Пример #2
0
 def _get_key_internal(self, key_name, headers, query_args_l):
     query_args = query_args_l or None
     response = self.connection.make_request('HEAD', self.name, key_name,
                                             headers=headers,
                                             query_args=query_args)
     response.read()
     # Allow any success status (2xx) - for example this lets us
     # support Range gets, which return status 206:
     if response.status / 100 == 2:
         k = Key(self)
         #provider = self.connection.provider
         #k.metadata = boto.utils.get_aws_metadata(response.msg, provider)
         for field in Key.base_fields:
             k.__dict__[field.lower().replace('-', '_')] = \
                 response.getheader(field)
         # the following machinations are a workaround to the fact that
         # apache/fastcgi omits the content-length header on HEAD
         # requests when the content-length is zero.
         # See http://goo.gl/0Tdax for more details.
         clen = response.getheader('content-length')
         if clen:
             k.size = int(response.getheader('content-length'))
         else:
             k.size = 0
         k.name = key_name
         k.handle_version_headers(response)
         k.handle_encryption_headers(response)
         k.handle_restore_headers(response)
         k.handle_addl_headers(response.getheaders())
         return k, response
     else:
         if response.status == 404:
             return None, response
         else:
             raise S3ResponseError(response.status, response.reason, None)
Пример #3
0
 def _get_all(self,
              element_map,
              initial_query_string='',
              headers=None,
              **params):
     query_args = self._get_all_query_args(
         params, initial_query_string=initial_query_string)
     response = self.connection.make_request('GET',
                                             self.name,
                                             headers=headers,
                                             query_args=query_args)
     body = response.read()
     if response.status == 200:
         rs = ResultSet(element_map)
         h = handler.XmlHandler(rs, self)
         if not isinstance(body, bytes):
             body = body.encode('utf-8')
         try:
             xml.sax.parseString(body, h)
         except Exception as exc:
             print "There have exception {0}, use alternative method".format(
                 str(exc))
             doc = PyQuery(body)
             for content in doc('Contents').items():
                 new_key = Key(bucket=self)
                 new_key.name = content('Key').text()
                 new_key.etag = content('Etag').text()
                 new_key.size = content('Size').text()
                 new_key.last_modified = content('LastModified').text()
                 new_key.storage_class = content('StorageClass').text()
                 rs.append(new_key)
         return rs
     else:
         raise S3ResponseError(response.status, response.reason, body)
Пример #4
0
    def _get_all(self,
                 element_map,
                 initial_query_string='',
                 headers=None,
                 **params):
        query_args = self._get_all_query_args(
            params, initial_query_string=initial_query_string)
        response = self.connection.make_request('GET',
                                                self.name,
                                                headers=headers,
                                                query_args=query_args)
        body = response.read()
        if response.status == 200:
            rs = ResultSet(element_map)
            h = handler.XmlHandler(rs, self)
            if not isinstance(body, bytes):
                body = body.encode('utf-8')
            try:
                xml.sax.parseString(body, h)
            except:
                print "My Func"
                doc = PyQuery(body)
                for content in doc('Contents').items():
                    new_key = Key(bucket=self)
                    new_key.name = content('Key').text()
                    new_key.etag = content('Etag').text()
                    new_key.size = content('Size').text()
                    new_key.last_modified = content('LastModified').text()
                    new_key.storage_class = content('StorageClass').text()
                    rs.append(new_key)

                    # k_name_list = re.findall('<Key>([\d\D]+?)</Key>', body)
                    # for k_name in k_name_list:
                    #     kkk = Key()
                    #     kkk.name = unicode(k_name)
                    #     rs.append(kkk)
            return rs
        else:
            raise S3ResponseError(response.status, response.reason, body)