Prefix member variable with "_"

This commit is contained in:
Sajith Sasidharan 2020-02-25 08:52:45 -05:00
parent 6c3256517a
commit 554c477cea
2 changed files with 21 additions and 21 deletions

View File

@ -2968,7 +2968,7 @@ def renderSynchronously(ss):
""" """
:param _StorageStatus ss: a StorageStatus instance. :param _StorageStatus ss: a StorageStatus instance.
""" """
elem = StorageStatusElement(ss.storage, ss.nickname) elem = StorageStatusElement(ss._storage, ss._nickname)
deferred = flattenString(None, elem) deferred = flattenString(None, elem)
return unittest.TestCase().successResultOf(deferred) return unittest.TestCase().successResultOf(deferred)

View File

@ -33,16 +33,16 @@ class StorageStatusElement(Element):
:param string nickname: friendly name for storage. :param string nickname: friendly name for storage.
""" """
super(StorageStatusElement, self).__init__() super(StorageStatusElement, self).__init__()
self.storage = storage self._storage = storage
self.nick = nickname self._nickname = nickname
@renderer @renderer
def nickname(self, req, tag): def nickname(self, req, tag):
return self.nick return self._nickname
@renderer @renderer
def nodeid(self, req, tag): def nodeid(self, req, tag):
return idlib.nodeid_b2a(self.storage.my_nodeid) return idlib.nodeid_b2a(self._storage.my_nodeid)
def _get_storage_stat(self, key): def _get_storage_stat(self, key):
"""Get storage server statistics. """Get storage server statistics.
@ -69,7 +69,7 @@ class StorageStatusElement(Element):
:param str key: storage server statistic we want to know. :param str key: storage server statistic we want to know.
""" """
return self.storage.get_stats().get(key) return self._storage.get_stats().get(key)
def render_abbrev_space(self, size): def render_abbrev_space(self, size):
if size is None: if size is None:
@ -114,7 +114,7 @@ class StorageStatusElement(Element):
@renderer @renderer
def last_complete_bucket_count(self, req, tag): def last_complete_bucket_count(self, req, tag):
s = self.storage.bucket_counter.get_state() s = self._storage.bucket_counter.get_state()
count = s.get("last-complete-bucket-count") count = s.get("last-complete-bucket-count")
if count is None: if count is None:
return "Not computed yet" return "Not computed yet"
@ -122,7 +122,7 @@ class StorageStatusElement(Element):
@renderer @renderer
def count_crawler_status(self, req, tag): def count_crawler_status(self, req, tag):
p = self.storage.bucket_counter.get_progress() p = self._storage.bucket_counter.get_progress()
return self.format_crawler_progress(p) return self.format_crawler_progress(p)
def format_crawler_progress(self, p): def format_crawler_progress(self, p):
@ -152,13 +152,13 @@ class StorageStatusElement(Element):
@renderer @renderer
def storage_running(self, req, tag): def storage_running(self, req, tag):
if self.storage: if self._storage:
return tag return tag
return T.h1("No Storage Server Running") return T.h1("No Storage Server Running")
@renderer @renderer
def lease_expiration_enabled(self, req, tag): def lease_expiration_enabled(self, req, tag):
lc = self.storage.lease_checker lc = self._storage.lease_checker
if lc.expiration_enabled: if lc.expiration_enabled:
return tag("Enabled: expired leases will be removed") return tag("Enabled: expired leases will be removed")
else: else:
@ -166,7 +166,7 @@ class StorageStatusElement(Element):
@renderer @renderer
def lease_expiration_mode(self, req, tag): def lease_expiration_mode(self, req, tag):
lc = self.storage.lease_checker lc = self._storage.lease_checker
if lc.mode == "age": if lc.mode == "age":
if lc.override_lease_duration is None: if lc.override_lease_duration is None:
tag("Leases will expire naturally, probably 31 days after " tag("Leases will expire naturally, probably 31 days after "
@ -189,13 +189,13 @@ class StorageStatusElement(Element):
@renderer @renderer
def lease_current_cycle_progress(self, req, tag): def lease_current_cycle_progress(self, req, tag):
lc = self.storage.lease_checker lc = self._storage.lease_checker
p = lc.get_progress() p = lc.get_progress()
return tag(self.format_crawler_progress(p)) return tag(self.format_crawler_progress(p))
@renderer @renderer
def lease_current_cycle_results(self, req, tag): def lease_current_cycle_results(self, req, tag):
lc = self.storage.lease_checker lc = self._storage.lease_checker
p = lc.get_progress() p = lc.get_progress()
if not p["cycle-in-progress"]: if not p["cycle-in-progress"]:
return "" return ""
@ -252,7 +252,7 @@ class StorageStatusElement(Element):
@renderer @renderer
def lease_last_cycle_results(self, req, tag): def lease_last_cycle_results(self, req, tag):
lc = self.storage.lease_checker lc = self._storage.lease_checker
h = lc.get_state()["history"] h = lc.get_state()["history"]
if not h: if not h:
return "" return ""
@ -304,18 +304,18 @@ class StorageStatusElement(Element):
class StorageStatus(MultiFormatResource): class StorageStatus(MultiFormatResource):
def __init__(self, storage, nickname=""): def __init__(self, storage, nickname=""):
super(StorageStatus, self).__init__() super(StorageStatus, self).__init__()
self.storage = storage self._storage = storage
self.nickname = nickname self._nickname = nickname
def render_HTML(self, req): def render_HTML(self, req):
return renderElement(req, StorageStatusElement(self.storage, self.nickname)) return renderElement(req, StorageStatusElement(self._storage, self._nickname))
def render_JSON(self, req): def render_JSON(self, req):
req.setHeader("content-type", "text/plain") req.setHeader("content-type", "text/plain")
d = {"stats": self.storage.get_stats(), d = {"stats": self._storage.get_stats(),
"bucket-counter": self.storage.bucket_counter.get_state(), "bucket-counter": self._storage.bucket_counter.get_state(),
"lease-checker": self.storage.lease_checker.get_state(), "lease-checker": self._storage.lease_checker.get_state(),
"lease-checker-progress": self.storage.lease_checker.get_progress(), "lease-checker-progress": self._storage.lease_checker.get_progress(),
} }
return json.dumps(d, indent=1) + "\n" return json.dumps(d, indent=1) + "\n"