From 34c3ef8038fd89bad405b9a9d1cb8b95348e25f4 Mon Sep 17 00:00:00 2001 From: Antoine Millet Date: Wed, 22 Dec 2010 10:13:38 +0100 Subject: [PATCH] Added search_client_by_connection method on CCServer. Also updated the CCClient class to make its attributes publics. --- ccserver/ccserver.py | 15 +++++++++++++++ ccserver/client.py | 14 +++++++------- 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/ccserver/ccserver.py b/ccserver/ccserver.py index 3908b31..399b341 100644 --- a/ccserver/ccserver.py +++ b/ccserver/ccserver.py @@ -71,6 +71,21 @@ class CCServer(object): self._connected[login] = CCClient(login, role, self, connection) + def search_client_by_connection(self, connection): + ''' + Search a connected client by it connection. If no client is found, + return None. + + :param connection: the connection of the client to search + :return: the found client or None + ''' + + for client in self._connected.values(): + if client.connection is connection: + return client + else: + return None + def run(self): ''' Run the server mainloop. diff --git a/ccserver/client.py b/ccserver/client.py index 4eca56e..52ece0d 100644 --- a/ccserver/client.py +++ b/ccserver/client.py @@ -9,13 +9,13 @@ class CCClient(object): def __init__(self, login, role, server, connection): # The login of the client: - self._login = login + self.login = login # The role of the client: - self._role = role + self.role = role # The server binded to this client: - self._server = server + self.server = server # The connection of the client (public attribute): self.connection = connection @@ -30,10 +30,10 @@ class CCClient(object): # Get the tags from the server tags = self.connection.call('get_tags', tags) # Add the static tags: - tags['a'] = self._login - tags['hv'] = self._login - tags['role'] = self._role + tags['a'] = self.login + tags['hv'] = self.login + tags['role'] = self.role # Update it with the locally defined tags: - tags.update(self._server.conf.show(self._login)['tags']) + tags.update(self.server.conf.show(self.login)['tags']) return tags -- GitLab