tor_rate: quick code QA
@@ -53,13 +53,14 @@ from stem import ProtocolError, SocketError
from stem.connection import AuthenticationFailure
from stem.control import Controller, EventType
-
ERROR_AUTHENTICATION = 'Error: Failed to authenticate with Tor daemon!'
ERROR_CONNECTION = 'Error: Failed to establish control connection!'
ERROR_PROTOCOL = 'Error: Failed to register event handler!'
class Py3status:
+ """
+ """
cache_timeout = 2
control_address = '127.0.0.1'
control_password = None
@@ -70,9 +71,9 @@ class Py3status:
si_units = False
def __init__(self):
+ self._auth_failure = False
self._down = 0
self._handler_active = False
- self._auth_failure = False
self._up = 0
def tor_rate(self, outputs, config):
@@ -93,21 +94,17 @@ class Py3status:
text = self.py3.safe_format(self.format, self._get_rates())
return {
- 'full_text': text,
'cached_until': self.py3.time_in(self.cache_timeout),
+ 'full_text': text,
}
def _get_rates(self):
- up, up_unit = self.py3.format_units(
- self._up,
+ up, up_unit = self.py3.format_units(self._up,
unit=self.rate_unit,
- si=self.si_units
- )
- down, down_unit = self.py3.format_units(
- self._down,
+ si=self.si_units)
+ down, down_unit = self.py3.format_units(self._down,
unit=self.rate_unit,
- si=self.si_units
- )
+ si=self.si_units)
return {
'up': self.py3.safe_format(self.format_value, {
'rate': up,
@@ -124,22 +121,16 @@ class Py3status:
self._up = event.written
def _register_event_handler(self):
- self._control = Controller.from_port(
- address=self.control_address,
- port=self.control_port
- )
+ self._control = Controller.from_port(address=self.control_address,
+ port=self.control_port)
if self.control_password:
self._control.authenticate(password=self.control_password)
- self._control.add_event_listener(
- lambda e: self._handle_event(e),
- EventType.BW
- )
+ self._control.add_event_listener(lambda e: self._handle_event(e),
+ EventType.BW)
self._handler_active = True
if __name__ == "__main__":
from py3status.module_test import module_test
- config = {
- 'control_password': 'SevenOfNine',
- }
+ config = {'control_password': 'SevenOfNine', }
module_test(Py3status, config)
