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)
def get_all_buckets(self, headers=None): response = self.make_request('GET', headers=headers) body = response.read() if response.status > 300: raise S3ResponseError(response.status, response.reason, body) rs = ResultSet([('Bucket', Bucket)]) h = handler.XmlHandler(rs, self) if not isinstance(body, bytes): body = body.encode('utf-8') xml.sax.parseString(body, h) return rs
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)
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') xml.sax.parseString(body, h) return rs else: raise S3ResponseError(response.status, response.reason, body)