Replace logger by _logger in servers

This commit is contained in:
nemunaire 2017-09-13 08:03:47 +02:00 committed by Pierre-Olivier Mercier
parent 05d20ed6ee
commit 7a4b27510c
4 changed files with 19 additions and 18 deletions

View File

@ -53,7 +53,7 @@ class DCC(server.AbstractServer):
self.port = self.foundPort() self.port = self.foundPort()
if self.port is None: if self.port is None:
self.logger.critical("No more available slot for DCC connection") self._logger.critical("No more available slot for DCC connection")
self.setError("Il n'y a plus de place disponible sur le serveur" self.setError("Il n'y a plus de place disponible sur le serveur"
" pour initialiser une session DCC.") " pour initialiser une session DCC.")
@ -79,7 +79,7 @@ class DCC(server.AbstractServer):
self.s = socket.socket() self.s = socket.socket()
try: try:
self.s.connect((host, port)) self.s.connect((host, port))
self.logger.info("Accepted user from %s:%d for %s", host, port, self.sender) self._logger.info("Accepted user from %s:%d for %s", host, port, self.sender)
self.connected = True self.connected = True
self.stop = False self.stop = False
except: except:
@ -104,7 +104,7 @@ class DCC(server.AbstractServer):
self.setError("Une erreur s'est produite durant la tentative" self.setError("Une erreur s'est produite durant la tentative"
" d'ouverture d'une session DCC.") " d'ouverture d'une session DCC.")
return False return False
self.logger.info("Listening on %d for %s", self.port, self.sender) self._logger.info("Listening on %d for %s", self.port, self.sender)
#Send CTCP request for DCC #Send CTCP request for DCC
self.srv.send_ctcp(self.sender, self.srv.send_ctcp(self.sender,
@ -115,7 +115,7 @@ class DCC(server.AbstractServer):
s.listen(1) s.listen(1)
#Waiting for the client #Waiting for the client
(self.s, addr) = s.accept() (self.s, addr) = s.accept()
self.logger.info("Connected by %d", addr) self._logger.info("Connected by %d", addr)
self.connected = True self.connected = True
return True return True
@ -149,7 +149,7 @@ class DCC(server.AbstractServer):
except RuntimeError: except RuntimeError:
pass pass
else: else:
self.logger.error("File not found `%s'", filename) self._logger.error("File not found `%s'", filename)
def run(self): def run(self):
self.stopping.clear() self.stopping.clear()
@ -202,7 +202,7 @@ class DCC(server.AbstractServer):
if self.realname in self.srv.dcc_clients: if self.realname in self.srv.dcc_clients:
del self.srv.dcc_clients[self.realname] del self.srv.dcc_clients[self.realname]
self.logger.info("Closing connection with %s", self.nick) self._logger.info("Closing connection with %s", self.nick)
self.stopping.set() self.stopping.set()
if self.closing_event is not None: if self.closing_event is not None:
self.closing_event() self.closing_event()

View File

@ -84,13 +84,13 @@ class _IRC:
except: except:
return "ERRMSG invalid parameters provided as DCC CTCP request" return "ERRMSG invalid parameters provided as DCC CTCP request"
self.logger.info("Receive DCC connection request from %s to %s:%d", conn.sender, ip, port) self._logger.info("Receive DCC connection request from %s to %s:%d", conn.sender, ip, port)
if conn.accept_user(ip, port): if conn.accept_user(ip, port):
srv.dcc_clients[conn.sender] = conn srv.dcc_clients[conn.sender] = conn
conn.send_dcc("Hello %s!" % conn.nick) conn.send_dcc("Hello %s!" % conn.nick)
else: else:
self.logger.error("DCC: unable to connect to %s:%d", ip, port) self._logger.error("DCC: unable to connect to %s:%d", ip, port)
return "ERRMSG unable to connect to %s:%d" % (ip, port) return "ERRMSG unable to connect to %s:%d" % (ip, port)
import nemubot import nemubot
@ -109,7 +109,7 @@ class _IRC:
# TODO: Temporary fix, waiting for hook based CTCP management # TODO: Temporary fix, waiting for hook based CTCP management
self.ctcp_capabilities["TYPING"] = lambda msg, cmds: None self.ctcp_capabilities["TYPING"] = lambda msg, cmds: None
self.logger.debug("CTCP capabilities setup: %s", ", ".join(self.ctcp_capabilities)) self._logger.debug("CTCP capabilities setup: %s", ", ".join(self.ctcp_capabilities))
# Register hooks on some IRC CMD # Register hooks on some IRC CMD

View File

@ -32,10 +32,11 @@ class AbstractServer:
""" """
self._name = name self._name = name
self._socket = socket
super().__init__(**kwargs) super().__init__(**kwargs)
self.logger = logging.getLogger("nemubot.server." + str(self.name)) self._logger = logging.getLogger("nemubot.server." + str(self.name))
self._readbuffer = b'' self._readbuffer = b''
self._sending_queue = queue.Queue() self._sending_queue = queue.Queue()
@ -53,7 +54,7 @@ class AbstractServer:
def connect(self, *args, **kwargs): def connect(self, *args, **kwargs):
"""Register the server in _poll""" """Register the server in _poll"""
self.logger.info("Opening connection") self._logger.info("Opening connection")
super().connect(*args, **kwargs) super().connect(*args, **kwargs)
@ -66,7 +67,7 @@ class AbstractServer:
def close(self, *args, **kwargs): def close(self, *args, **kwargs):
"""Unregister the server from _poll""" """Unregister the server from _poll"""
self.logger.info("Closing connection") self._logger.info("Closing connection")
if self.fileno() > 0: if self.fileno() > 0:
sync_act("sckt", "unregister", self.fileno()) sync_act("sckt", "unregister", self.fileno())
@ -84,7 +85,7 @@ class AbstractServer:
""" """
self._sending_queue.put(self.format(message)) self._sending_queue.put(self.format(message))
self.logger.debug("Message '%s' appended to write queue", message) self._logger.debug("Message '%s' appended to write queue", message)
sync_act("sckt", "write", self.fileno()) sync_act("sckt", "write", self.fileno())

View File

@ -90,7 +90,7 @@ class _SocketServer(_Socket):
def connect(self): def connect(self):
self.logger.info("Connection to %s:%d", *self._sockaddr[:2]) self._logger.info("Connection to %s:%d", *self._sockaddr[:2])
super().connect(self._sockaddr) super().connect(self._sockaddr)
if self._bind: if self._bind:
@ -114,7 +114,7 @@ class UnixSocket:
def connect(self): def connect(self):
self.logger.info("Connection to unix://%s", self._socket_path) self._logger.info("Connection to unix://%s", self._socket_path)
super().connect(self._socket_path) super().connect(self._socket_path)
@ -136,7 +136,7 @@ class _Listener:
def read(self): def read(self):
conn, addr = self.accept() conn, addr = self.accept()
fileno = conn.fileno() fileno = conn.fileno()
self.logger.info("Accept new connection from %s (fd=%d)", addr, fileno) self._logger.info("Accept new connection from %s (fd=%d)", addr, fileno)
ss = self._instanciate(name=self.name + "#" + str(fileno), fileno=conn.detach()) ss = self._instanciate(name=self.name + "#" + str(fileno), fileno=conn.detach())
ss.connect = ss._on_connect ss.connect = ss._on_connect
@ -152,7 +152,7 @@ class UnixSocketListener(_Listener, UnixSocket, _Socket, socket.socket):
def connect(self): def connect(self):
self.logger.info("Creating Unix socket at unix://%s", self._socket_path) self._logger.info("Creating Unix socket at unix://%s", self._socket_path)
try: try:
os.remove(self._socket_path) os.remove(self._socket_path)
@ -161,7 +161,7 @@ class UnixSocketListener(_Listener, UnixSocket, _Socket, socket.socket):
self.bind(self._socket_path) self.bind(self._socket_path)
self.listen(5) self.listen(5)
self.logger.info("Socket ready for accepting new connections") self._logger.info("Socket ready for accepting new connections")
self._on_connect() self._on_connect()