diff options
author | Claudiu Popa <pcmanticore@gmail.com> | 2015-10-16 21:05:45 +0300 |
---|---|---|
committer | Claudiu Popa <pcmanticore@gmail.com> | 2015-10-16 21:05:45 +0300 |
commit | 258edc970bfe327ff5c37353a6b431d3f250fc35 (patch) | |
tree | 2b08c1e801e9fa6f9d25128bd411dbedf53b46db | |
parent | 7f77255f8719993f04070ef6ed100a378956b55d (diff) | |
download | pylint-258edc970bfe327ff5c37353a6b431d3f250fc35.tar.gz |
Simplify compute_content, by removing the custom implementations of write and writeln.
-rw-r--r-- | pylint/reporters/ureports/__init__.py | 37 |
1 files changed, 11 insertions, 26 deletions
diff --git a/pylint/reporters/ureports/__init__.py b/pylint/reporters/ureports/__init__.py index 0da4051..8a0a036 100644 --- a/pylint/reporters/ureports/__init__.py +++ b/pylint/reporters/ureports/__init__.py @@ -26,8 +26,6 @@ import sys import six -# pylint: disable=method-hidden; Weird API in compute_content. - class BaseWriter(object): """base class for ureport writers""" @@ -43,7 +41,6 @@ class BaseWriter(object): if not encoding: encoding = getattr(stream, 'encoding', 'UTF-8') self.encoding = encoding or 'UTF-8' - self.__compute_funcs = [] self.out = stream self.begin_format() layout.accept(self) @@ -98,27 +95,15 @@ class BaseWriter(object): return an iterator on strings (one for each child element) """ - # use cells ! - def write(data): - try: - stream.write(data) - except UnicodeEncodeError: - stream.write(data.encode(self.encoding)) - def writeln(data=u''): - try: - stream.write(data + os.linesep) - except UnicodeEncodeError: - stream.write(data.encode(self.encoding) + os.linesep) - self.write = write - self.writeln = writeln - self.__compute_funcs.append((write, writeln)) - for child in layout.children: - stream = six.StringIO() - child.accept(self) - yield stream.getvalue() - self.__compute_funcs.pop() + # Patch the underlying output stream with a fresh-generated stream, + # which is used to store a temporary representation of a child + # node. + out = self.out try: - self.write, self.writeln = self.__compute_funcs[-1] - except IndexError: - del self.write - del self.writeln + for child in layout.children: + stream = six.StringIO() + self.out = stream + child.accept(self) + yield stream.getvalue() + finally: + self.out = out |