-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(Re)ConnectionInfo: use attributes, not getter functions
Simplies the API somewhat.. none of the properties need functions. Thanks to meejah for additionally pointing out that providing functions implies the values are immutable/callee-owned, and providing attributes should make applications think twice about mutating them (they're actually shared, so mutation would cause serious problems).
- Loading branch information
Showing
5 changed files
with
126 additions
and
152 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,28 @@ | ||
|
||
class ConnectionInfo: | ||
def __init__(self): | ||
self._connected = False | ||
self._connector_statuses = {} | ||
self._handler_descriptions = {} | ||
self._listener_description = None | ||
self._listener_status = None | ||
self._winning_hint = None | ||
self._established_at = None | ||
self._lost_at = None | ||
self.connected = False | ||
self.connectorStatuses = {} | ||
self.connectionHandlers = {} | ||
self.listenerStatus = (None, None) | ||
self.winningHint = None | ||
self.establishedAt = None | ||
self.lostAt = None | ||
|
||
def _set_connected(self, connected): | ||
self._connected = connected | ||
self.connected = connected | ||
|
||
def _set_connection_status(self, location, status): | ||
self._connector_statuses[location] = status | ||
self.connectorStatuses[location] = status | ||
def _describe_connection_handler(self, location, description): | ||
self._handler_descriptions[location] = description | ||
self.connectionHandlers[location] = description | ||
def _set_established_at(self, when): | ||
self._established_at = when | ||
self.establishedAt = when | ||
def _set_winning_hint(self, location): | ||
self._winning_hint = location | ||
self.winningHint = location | ||
def _set_listener_description(self, description): | ||
self._listener_description = description | ||
self.listenerStatus = (description, self.listenerStatus[1]) | ||
def _set_listener_status(self, status): | ||
self._listener_status = status | ||
self.listenerStatus = (self.listenerStatus[0], status) | ||
def _set_lost_at(self, when): | ||
self._lost_at = when | ||
|
||
def connected(self): | ||
return self._connected | ||
|
||
def connectorStatuses(self): | ||
return self._connector_statuses | ||
def connectionHandlers(self): | ||
return self._handler_descriptions | ||
|
||
def connectionEstablishedAt(self): | ||
return self._established_at | ||
def winningHint(self): | ||
return self._winning_hint | ||
def listenerStatus(self): | ||
return (self._listener_description, self._listener_status) | ||
|
||
def connectionLostAt(self): | ||
return self._lost_at | ||
self.lostAt = when |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.