Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions pymemcache/client/retrying.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,10 @@ def _retry(self, name, func, *args, **kwargs):
# strictly defined for ourselves and pass it on to whatever client we've
# been given.
def __getattr__(self, name):
return lambda *args, **kwargs: self._retry(
name, self._client.__getattribute__(name), *args, **kwargs
)
attribute = getattr(self._client, name)
if not callable(attribute):
return attribute
return lambda *args, **kwargs: self._retry(name, attribute, *args, **kwargs)

# We implement these explicitly because they're "magic" functions and won't
# get passed on by __getattr__.
Expand Down
12 changes: 12 additions & 0 deletions pymemcache/test/test_client_retry.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,18 @@ def test_dir_passthrough(self):

assert dir(base) == dir(client)

@pytest.mark.parametrize("attribute", ["server", "ignore_exc", "sock"])
def test_attribute_passthrough(self, attribute):
base = self.make_base_client([])
client = RetryingClient(base)
assert getattr(client, attribute) is getattr(base, attribute)

def test_missing_attribute(self):
client = self.make_client([])
assert not hasattr(client, "missing_method")
with pytest.raises(AttributeError):
client.missing_method

def test_retry_dict_set_is_supported(self):
client = self.make_client([b"UNKNOWN\r\n", b"STORED\r\n"])
client[b"key"] = b"value"
Expand Down