-
Notifications
You must be signed in to change notification settings - Fork 183
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b8cee74
commit 63469be
Showing
30 changed files
with
169 additions
and
313 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,24 @@ | ||
from __future__ import annotations | ||
|
||
from abc import ABC | ||
from io import BytesIO | ||
from os import PathLike | ||
from pathlib import Path | ||
from typing import Optional | ||
from typing import TYPE_CHECKING | ||
|
||
from attrs import define, field | ||
from attrs import Factory, define, field | ||
|
||
from griptape.drivers import BaseFileManagerDriver, LocalFileManagerDriver | ||
from griptape.loaders import BaseLoader | ||
|
||
if TYPE_CHECKING: | ||
from os import PathLike | ||
|
||
|
||
@define | ||
class BaseFileLoader(BaseLoader, ABC): | ||
encoding: Optional[str] = field(default=None, kw_only=True) | ||
|
||
def fetch(self, source: str | BytesIO | PathLike, *args, **kwargs) -> bytes: | ||
if isinstance(source, (str, PathLike)): | ||
content = Path(source).read_bytes() | ||
elif isinstance(source, BytesIO): | ||
content = source.read() | ||
file_manager_driver: BaseFileManagerDriver = field( | ||
default=Factory(lambda: LocalFileManagerDriver(workdir=None)), | ||
kw_only=True, | ||
) | ||
encoding: str = field(default="utf-8", kw_only=True) | ||
|
||
return content | ||
def fetch(self, source: str | PathLike, *args, **kwargs) -> bytes: | ||
return self.file_manager_driver.load_file(str(source), *args, **kwargs) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.