def get_object(self, kwargs): """ This operation gets an object from s3. It retrieves the body of the object or a part of the body specified by a range variable. A MagicMock() class is used to transfer the body allowing it to be read by a read() operation. The etags no matter if it is a multipart download or not is invalid as it will have a dash in the etags. So it is never compared during download. If the session's connection_error flag is set, it will raise a ConnectionError and reset the flag to False. """ bucket = kwargs['bucket'] key = kwargs['key'] response_data = {} etag = '' if bucket in self.session.s3: body = self.session.s3[bucket][key]['Body'] if 'range' in kwargs: str_range = kwargs['range'] str_range = str_range[6:] range_components = str_range.split('-') beginning = range_components[0] end = range_components[1] if end == '': body = body[int(beginning):] else: body = body[int(beginning):(int(end) + 1)] mock_response = BytesIO(body) mock_response.set_socket_timeout = Mock() response_data['Body'] = mock_response etag = self.session.s3[bucket][key]['ETag'] response_data['ETag'] = etag + '--' else: response_data['Errors'] = [{'Message': 'Bucket does not exist'}] if self.session.connection_error: self.session.connection_error = False raise requests.ConnectionError return FakeHttp(), response_data