def __delitem__(self, path): try: path = posixpath.join(self.bucketpath, path) self.s3fs.rm(path, recursive=True) except Exception as err: logger.error(err) raise S3Exception(err)
def __setitem__(self, path, content): try: path = posixpath.join(self.path, path) attrs = { "Bucket": self.bucket, "Body": content, "Key": path, "ContentType": ("application/octet-stream"), } self.client.put_object(**attrs) except Exception as err: logger.error(err) raise S3Exception(err)
def __setitem__(self, path, content): self.check_update_creds() try: path = posixpath.join(self.path, path) content = bytearray(memoryview(content)) attrs = { "Bucket": self.bucket, "Body": content, "Key": path, "ContentType": ("application/octet-stream"), } self.client.put_object(**attrs) except Exception as err: logger.error(err) raise S3Exception(err)
def __getitem__(self, path): try: path = posixpath.join(self.path, path) resp = self.client.get_object( Bucket=self.bucket, Key=path, ) x = resp["Body"].read() return x except ClientError as err: if err.response["Error"]["Code"] == "NoSuchKey": raise KeyError(err) else: raise except Exception as err: logger.error(err) raise S3Exception(err)