connection.py 文件源码

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

项目:snowboard 作者: dwhagar 项目源码 文件源码
def read(self):
        '''Read a line of data from the server, if any.'''
        # Only do something if we're connected.
        if self.__connected:
            done = False
            received = ""

            while not done:
                try:
                    if self.ssl:
                        data = self.__ssl.recv(1)
                    else:
                        data = self.__socket.recv(1)
                except (ssl.SSLWantReadError, BlockingIOError):
                    received = None
                    break
                except OSError as err:
                    debug.error("Error #" + str(err.errno) + ": '" + err.strerror + "' disconnecting.")
                    data = False

                # Process the data.
                # socket.recv is supposed to return a False if the connection
                # been broken.
                if not data:
                    self.disconnect()
                    done = True
                    received = None
                else:
                    text = data.decode('utf-8','replace')
                    if text == '\n':
                        done = True
                    else:
                        received += text

        else:
            received = None

        # Remove the trailing carriage return character (cr/lf pair)
        if not received is None:
            received = received.strip('\r')
            if len(received) > 0:
                if received[0] == ':':
                    received = received[1:]

        # Bug fix for Issue #18, do not return blank lines.
        if received == "":
            received = None

        return received
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号