Skip to content

Commit fb4d773

Browse files
phlogistonjohnmergify[bot]
authored andcommitted
sambacc: rename rados object class to RADOSObjectRef
Previously, the class name was "private" and only expected to be used indirectly through the opener infrastructure. Future changes will make it possible to write "open" objects, lock them, etc. Prepare for that by making the class "public" and cleaning up the basic interface a bit. Signed-off-by: John Mulligan <[email protected]>
1 parent 6191e91 commit fb4d773

File tree

2 files changed

+17
-10
lines changed

2 files changed

+17
-10
lines changed

sambacc/rados_opener.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
import urllib.request
2626

2727
from . import url_opener
28-
from .typelets import ExcType, ExcValue, ExcTraceback
28+
from .typelets import ExcType, ExcValue, ExcTraceback, Self
2929

3030
_RADOSModule = typing.Any
3131
_RADOSObject = typing.Any
@@ -80,16 +80,23 @@ def rados_open(self, req: urllib.request.Request) -> typing.IO:
8080
# it's quite annoying to have a read-only typing.IO we're forced to
8181
# have so many stub methods. Go's much more granular io interfaces for
8282
# readers/writers is much nicer for this.
83-
class _RADOSResponse(typing.IO):
83+
class RADOSObjectRef(typing.IO):
8484
def __init__(
85-
self, interface: _RADOSInterface, pool: str, ns: str, key: str
85+
self,
86+
interface: _RADOSInterface,
87+
pool: str,
88+
ns: str,
89+
key: str,
90+
*,
91+
must_exist: bool = True,
8692
) -> None:
8793
self._pool = pool
8894
self._ns = ns
8995
self._key = key
9096

9197
self._open(interface)
92-
self._test()
98+
if must_exist:
99+
self._test()
93100

94101
def _open(self, interface: _RADOSInterface) -> None:
95102
# TODO: connection caching
@@ -142,15 +149,15 @@ def mode(self) -> str:
142149
def name(self) -> str:
143150
return self._key
144151

145-
def __enter__(self) -> _RADOSResponse:
152+
def __enter__(self) -> Self:
146153
return self
147154

148155
def __exit__(
149156
self, exc_type: ExcType, exc_val: ExcValue, exc_tb: ExcTraceback
150157
) -> None:
151158
self.close()
152159

153-
def __iter__(self) -> _RADOSResponse:
160+
def __iter__(self) -> Self:
154161
return self
155162

156163
def __next__(self) -> bytes:

tests/test_rados_opener.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ def _read(_, size, off):
133133
mock = unittest.mock.MagicMock()
134134
mock.Rados.return_value.open_ioctx.return_value.read.side_effect = _read
135135

136-
rr = sambacc.rados_opener._RADOSResponse(mock, "foo", "bar", "baz")
136+
rr = sambacc.rados_opener.RADOSObjectRef(mock, "foo", "bar", "baz")
137137
assert rr.readable()
138138
assert not rr.seekable()
139139
assert not rr.writable()
@@ -160,7 +160,7 @@ def _read(_, size, off):
160160
mock = unittest.mock.MagicMock()
161161
mock.Rados.return_value.open_ioctx.return_value.read.side_effect = _read
162162

163-
rr = sambacc.rados_opener._RADOSResponse(mock, "foo", "bar", "baz")
163+
rr = sambacc.rados_opener.RADOSObjectRef(mock, "foo", "bar", "baz")
164164
assert rr.readable()
165165
assert rr.read(8) == b"a bad ca"
166166
assert rr.read(8) == b"t lives "
@@ -178,7 +178,7 @@ def _read(_, size, off):
178178
mock = unittest.mock.MagicMock()
179179
mock.Rados.return_value.open_ioctx.return_value.read.side_effect = _read
180180

181-
rr = sambacc.rados_opener._RADOSResponse(mock, "foo", "bar", "baz")
181+
rr = sambacc.rados_opener.RADOSObjectRef(mock, "foo", "bar", "baz")
182182
with rr:
183183
result = [value for value in rr]
184184
assert result == [sval]
@@ -189,7 +189,7 @@ def _read(_, size, off):
189189
def test_rados_response_not_implemented():
190190
mock = unittest.mock.MagicMock()
191191

192-
rr = sambacc.rados_opener._RADOSResponse(mock, "foo", "bar", "baz")
192+
rr = sambacc.rados_opener.RADOSObjectRef(mock, "foo", "bar", "baz")
193193
with pytest.raises(NotImplementedError):
194194
rr.seek(10)
195195
with pytest.raises(NotImplementedError):

0 commit comments

Comments
 (0)