Remove some Python 2 compatibility code
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
This commit is contained in:
parent
fd7aa13671
commit
0c3f5f1471
1 changed files with 5 additions and 16 deletions
|
@ -220,25 +220,17 @@ class FileWrapper(io.FileIO):
|
|||
|
||||
:param file_name: File path to open.
|
||||
"""
|
||||
super(FileWrapper, self).__init__(file_name, 'r')
|
||||
super().__init__(file_name, 'r')
|
||||
self._line_no = 0
|
||||
|
||||
def next(self):
|
||||
def __next__(self):
|
||||
"""
|
||||
Python 2 iterator method. This method overrides base class's
|
||||
next method and extends the next method to count the line
|
||||
numbers as each line is read.
|
||||
|
||||
It works for both Python 2 and Python 3 by checking iterator
|
||||
method name in the base iterator object.
|
||||
This method overrides base class's __next__ method and extends it
|
||||
method to count the line numbers as each line is read.
|
||||
|
||||
:return: Line read from file.
|
||||
"""
|
||||
parent = super(FileWrapper, self)
|
||||
if hasattr(parent, '__next__'):
|
||||
line = parent.__next__() # Python 3
|
||||
else:
|
||||
line = parent.next() # Python 2 # pylint: disable=no-member
|
||||
line = super().__next__()
|
||||
if line is not None:
|
||||
self._line_no += 1
|
||||
# Convert byte array to string with correct encoding and
|
||||
|
@ -246,9 +238,6 @@ class FileWrapper(io.FileIO):
|
|||
return line.decode(sys.getdefaultencoding()).rstrip() + '\n'
|
||||
return None
|
||||
|
||||
# Python 3 iterator method
|
||||
__next__ = next
|
||||
|
||||
def get_line_no(self):
|
||||
"""
|
||||
Gives current line number.
|
||||
|
|
Loading…
Reference in a new issue