MCPcopy Index your code
hub / github.com/python/cpython / Readliner

Class Readliner

Lib/test/test_httplib.py:1778–1809  ·  view source on GitHub ↗

a simple readline class that uses an arbitrary read function and buffering

Source from the content-addressed store, hash-verified

1776
1777
1778class Readliner:
1779 """
1780 a simple readline class that uses an arbitrary read function and buffering
1781 """
1782 def __init__(self, readfunc):
1783 self.readfunc = readfunc
1784 self.remainder = b""
1785
1786 def readline(self, limit):
1787 data = []
1788 datalen = 0
1789 read = self.remainder
1790 try:
1791 while True:
1792 idx = read.find(b'\n')
1793 if idx != -1:
1794 break
1795 if datalen + len(read) >= limit:
1796 idx = limit - datalen - 1
1797 # read more data
1798 data.append(read)
1799 read = self.readfunc()
1800 if not read:
1801 idx = 0 #eof condition
1802 break
1803 idx += 1
1804 data.append(read[:idx])
1805 self.remainder = read[idx:]
1806 return b"".join(data)
1807 except:
1808 self.remainder = b"".join(data)
1809 raise
1810
1811
1812class OfflineTest(TestCase):

Callers 1

test_read1Method · 0.85

Calls

no outgoing calls

Tested by 1

test_read1Method · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…