Skip to content
Snippets Groups Projects
Commit ca554f62 authored by Jean-Paul Calderone's avatar Jean-Paul Calderone
Browse files

Make a safer way to check if an interface has an attribute

parent 1f3558da
No related branches found
No related tags found
2 merge requests!231Remove `renew_lease` from our storage protocol,!229Set up CI for Tahoe 1.16.x
...@@ -141,6 +141,20 @@ def add_arguments(schema, kwargs): ...@@ -141,6 +141,20 @@ def add_arguments(schema, kwargs):
return modified_schema return modified_schema
def remoteinterface_hasattr(ri, name):
"""
:param InterfaceClass ri: A ``RemoteInterface`` to inspect.
:param str name: The name of an attribute.
:return bool: ``True`` if and only if ``ri`` has the attribute named by
``name``, ``False`` otherwise.
"""
try:
ri[name]
except KeyError:
return False
return True
class RIPrivacyPassAuthorizedStorageServer(RemoteInterface): class RIPrivacyPassAuthorizedStorageServer(RemoteInterface):
""" """
...@@ -162,7 +176,7 @@ class RIPrivacyPassAuthorizedStorageServer(RemoteInterface): ...@@ -162,7 +176,7 @@ class RIPrivacyPassAuthorizedStorageServer(RemoteInterface):
add_lease = add_passes(RIStorageServer["add_lease"]) add_lease = add_passes(RIStorageServer["add_lease"])
if "renew_lease" in RIStorageServer: if remoteinterface_hasattr(RIStorageServer, "renew_lease"):
# Tahoe-LAFS 1.16.0 drops renew_lease from the interface. Do likewise # Tahoe-LAFS 1.16.0 drops renew_lease from the interface. Do likewise
# here, if we discover we have a version of Tahoe that has done so. # here, if we discover we have a version of Tahoe that has done so.
# If Tahoe has dropped this method then nothing in Tahoe is going to # If Tahoe has dropped this method then nothing in Tahoe is going to
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment