Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python3
- class ReadLine:
- def __init__(self, s):
- self.buf = bytearray()
- self.s = s
- def readline(self):
- i = self.buf.find(b"\n")
- if i >= 0:
- r = self.buf[:i+1]
- self.buf = self.buf[i+1:]
- return r
- while True:
- i = max(1, min(2048, self.s.in_waiting))
- data = self.s.read(i)
- i = data.find(b"\n")
- if i >= 0:
- r = self.buf + data[:i+1]
- self.buf[0:] = data[i+1:]
- return r
- else:
- self.buf.extend(data)
Advertisement
Add Comment
Please, Sign In to add comment