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

Class LineReader

Lib/test/test_fileinput.py:50–84  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

48 return name
49
50class LineReader:
51
52 def __init__(self):
53 self._linesread = []
54
55 @property
56 def linesread(self):
57 try:
58 return self._linesread[:]
59 finally:
60 self._linesread = []
61
62 def openhook(self, filename, mode):
63 self.it = iter(filename.splitlines(True))
64 return self
65
66 def readline(self, size=None):
67 line = next(self.it, '')
68 self._linesread.append(line)
69 return line
70
71 def readlines(self, hint=-1):
72 lines = []
73 size = 0
74 while True:
75 line = self.readline()
76 if not line:
77 return lines
78 lines.append(line)
79 size += len(line)
80 if size >= hint:
81 return lines
82
83 def close(self):
84 pass
85
86class BufferSizesTests(BaseTests, unittest.TestCase):
87 def test_buffer_sizes(self):

Callers 2

Calls

no outgoing calls

Tested by 2

Used in the wild real call sites across dependent graphs

searching dependent graphs…