summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2014-09-08 17:30:04 +0000
committerGerrit Code Review <review@openstack.org>2014-09-08 17:30:04 +0000
commit89779ed115860d7f590448d80d61a7e45b74883e (patch)
tree58c58ad07580b3ba43a4f65d0fa29934ccaaa6d8
parent83de2e691212f076e18b5d3242069d357ea2c8ba (diff)
parent674cbbcd597d732bca5ac0e465d1a7162e416023 (diff)
Merge "Cache the lines that are read instead of re-reading"
-rw-r--r--doc8/parser.py15
1 files changed, 9 insertions, 6 deletions
diff --git a/doc8/parser.py b/doc8/parser.py
index aeffc2d..7a88520 100644
--- a/doc8/parser.py
+++ b/doc8/parser.py
@@ -35,6 +35,7 @@ class ParsedFile(object):
35 self._encoding = encoding 35 self._encoding = encoding
36 self._doc = None 36 self._doc = None
37 self._errors = None 37 self._errors = None
38 self._lines = None
38 self._extension = os.path.splitext(filename)[1] 39 self._extension = os.path.splitext(filename)[1]
39 40
40 @property 41 @property
@@ -72,12 +73,14 @@ class ParsedFile(object):
72 return self._doc 73 return self._doc
73 74
74 def lines_iter(self, remove_trailing_newline=True): 75 def lines_iter(self, remove_trailing_newline=True):
75 with open(self.filename, 'rb') as fh: 76 if self._lines is None:
76 for line in fh: 77 with open(self.filename, 'rb') as fh:
77 line = six.text_type(line, encoding=self.encoding) 78 self._lines = list(fh)
78 if remove_trailing_newline and line.endswith("\n"): 79 for line in self._lines:
79 line = line[0:-1] 80 line = six.text_type(line, encoding=self.encoding)
80 yield line 81 if remove_trailing_newline and line.endswith("\n"):
82 line = line[0:-1]
83 yield line
81 84
82 @property 85 @property
83 def extension(self): 86 def extension(self):