simple_irc_bot.py 文件源码

python
阅读 25 收藏 0 点赞 0 评论 0

项目:irc_bot 作者: cvium 项目源码 文件源码
def connect(self, server):
        """Creates a (ssl) socket and connects to the server. Not using asyncore's connect-function because it sucks."""
        # sockets are garbage collected, but if the connection isn't closed it might fail
        try:
            self.socket.shutdown(socket.SHUT_WR)
            self.socket.close()
            del self.socket
        except Exception:
            pass
        self.create_socket(socket.AF_INET, socket.SOCK_STREAM)
        if self.use_ssl:
            try:
                self.socket.setblocking(True)
                self.socket = ssl.wrap_socket(self.socket)
            except (ssl.SSLWantReadError, ssl.SSLWantWriteError) as e:
                log.debug(e)
                self._handshake()
            except ssl.SSLError as e:
                log.error(e)
                self.exit()
                return
            finally:
                self.socket.setblocking(False)

        log.info('Connecting to %s', self.current_server)
        self.socket.settimeout(30)
        self.socket.connect(server)
        self.handle_connect_event()
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号