Skip to content

Commit 1d64bed

Browse files
committed
docstrings
1 parent 9a13d8c commit 1d64bed

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

nodescraper/connection/inband/inband.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,17 @@ class CommandArtifact(BaseModel):
4040

4141

4242
class BaseFileArtifact(BaseModel, abc.ABC):
43+
"""Base class for files"""
44+
4345
filename: str
4446

4547
@abc.abstractmethod
4648
def log_model(self, log_path: str) -> None:
49+
"""Write file to path
50+
51+
Args:
52+
log_path (str): Path for file
53+
"""
4754
pass
4855

4956
@abc.abstractmethod
@@ -58,6 +65,17 @@ def from_bytes(
5865
encoding: Optional[str] = "utf-8",
5966
strip: bool = True,
6067
) -> "BaseFileArtifact":
68+
"""factory method
69+
70+
Args:
71+
filename (str): name of file to be read
72+
raw_contents (bytes): Raw file content
73+
encoding (Optional[str], optional): Optional encoding. Defaults to "utf-8".
74+
strip (bool, optional): Remove padding. Defaults to True.
75+
76+
Returns:
77+
BaseFileArtifact: _Returns instance of Artifact file
78+
"""
6179
if encoding is None:
6280
return BinaryFileArtifact(filename=filename, contents=raw_contents)
6381

@@ -69,26 +87,50 @@ def from_bytes(
6987

7088

7189
class TextFileArtifact(BaseFileArtifact):
90+
"""Class for text file artifacts"""
91+
7292
contents: str
7393

7494
def log_model(self, log_path: str) -> None:
95+
"""Write file to disk
96+
97+
Args:
98+
log_path (str): Path for file
99+
"""
75100
path = os.path.join(log_path, self.filename)
76101
with open(path, "w", encoding="utf-8") as f:
77102
f.write(self.contents)
78103

79104
def contents_str(self) -> str:
105+
"""Get content as str
106+
107+
Returns:
108+
str: Str instance of file content
109+
"""
80110
return self.contents
81111

82112

83113
class BinaryFileArtifact(BaseFileArtifact):
114+
"""Class for binary file artifacts"""
115+
84116
contents: bytes
85117

86118
def log_model(self, log_path: str) -> None:
119+
"""Write file to disk
120+
121+
Args:
122+
log_path (str): Path for file
123+
"""
87124
log_name = os.path.join(log_path, self.filename)
88125
with open(log_name, "wb") as f:
89126
f.write(self.contents)
90127

91128
def contents_str(self) -> str:
129+
"""File content
130+
131+
Returns:
132+
str: Str instance of file content
133+
"""
92134
try:
93135
return self.contents.decode("utf-8")
94136
except UnicodeDecodeError:

0 commit comments

Comments
 (0)