Merge "Cache the lines that are read instead of re-reading"
This commit is contained in:
commit
89779ed115
|
@ -35,6 +35,7 @@ class ParsedFile(object):
|
||||||
self._encoding = encoding
|
self._encoding = encoding
|
||||||
self._doc = None
|
self._doc = None
|
||||||
self._errors = None
|
self._errors = None
|
||||||
|
self._lines = None
|
||||||
self._extension = os.path.splitext(filename)[1]
|
self._extension = os.path.splitext(filename)[1]
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
@ -72,12 +73,14 @@ class ParsedFile(object):
|
||||||
return self._doc
|
return self._doc
|
||||||
|
|
||||||
def lines_iter(self, remove_trailing_newline=True):
|
def lines_iter(self, remove_trailing_newline=True):
|
||||||
with open(self.filename, 'rb') as fh:
|
if self._lines is None:
|
||||||
for line in fh:
|
with open(self.filename, 'rb') as fh:
|
||||||
line = six.text_type(line, encoding=self.encoding)
|
self._lines = list(fh)
|
||||||
if remove_trailing_newline and line.endswith("\n"):
|
for line in self._lines:
|
||||||
line = line[0:-1]
|
line = six.text_type(line, encoding=self.encoding)
|
||||||
yield line
|
if remove_trailing_newline and line.endswith("\n"):
|
||||||
|
line = line[0:-1]
|
||||||
|
yield line
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def extension(self):
|
def extension(self):
|
||||||
|
|
Loading…
Reference in New Issue