Skip to content

Commit 6a3f2e1

Browse files
committed
testhelper/smbclient: add support to write files
This is in preparation for writing larger files over SMB. Signed-off-by: Sachin Prabhu <[email protected]>
1 parent 9f7d0f4 commit 6a3f2e1

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

testhelper/smbclient.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -80,26 +80,32 @@ def unlink(self, fpath: str) -> None:
8080
except base.NotConnectedError as error:
8181
raise ConnectionError(f"unlink: {error}")
8282

83-
def write_text(self, fpath: str, teststr: str) -> None:
83+
def write(self, fpath: str, writeobj: typing.IO) -> None:
8484
try:
85-
with io.BytesIO(teststr.encode()) as writeobj:
86-
self.ctx.storeFile(self.share, fpath, writeobj)
85+
self.ctx.storeFile(self.share, fpath, writeobj)
8786
except smb_structs.OperationFailure as error:
8887
raise IOError(f"failed in write_text: {error}")
8988
except base.SMBTimeout as error:
9089
raise TimeoutError(f"write_text: {error}")
9190
except base.NotConnectedError as error:
9291
raise ConnectionError(f"write: {error}")
9392

94-
def read_text(self, fpath: str) -> str:
93+
def read(self, fpath: str, readobj: typing.IO) -> None:
9594
try:
96-
with io.BytesIO() as readobj:
97-
self.ctx.retrieveFile(self.share, fpath, readobj)
98-
ret = readobj.getvalue().decode("utf8")
95+
self.ctx.retrieveFile(self.share, fpath, readobj)
9996
except smb_structs.OperationFailure as error:
10097
raise IOError(f"failed in read_text: {error}")
10198
except base.SMBTimeout as error:
10299
raise TimeoutError(f"read_text: {error}")
103100
except base.NotConnectedError as error:
104101
raise ConnectionError(f"read: {error}")
102+
103+
def write_text(self, fpath: str, teststr: str) -> None:
104+
with io.BytesIO(teststr.encode()) as writeobj:
105+
self.write(fpath, writeobj)
106+
107+
def read_text(self, fpath: str) -> str:
108+
with io.BytesIO() as readobj:
109+
self.read(fpath, readobj)
110+
ret = readobj.getvalue().decode("utf8")
105111
return ret

0 commit comments

Comments
 (0)