Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
0554d83f
Commit
0554d83f
authored
Mar 08, 2016
by
Serhiy Storchaka
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #15068: Avoid creating a reference loop in fileinput.
parent
4a6f4825
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
15 additions
and
13 deletions
+15
-13
Lib/fileinput.py
Lib/fileinput.py
+15
-13
No files found.
Lib/fileinput.py
View file @
0554d83f
...
@@ -207,7 +207,6 @@ class FileInput:
...
@@ -207,7 +207,6 @@ class FileInput:
self
.
_startlineno
=
0
self
.
_startlineno
=
0
self
.
_filelineno
=
0
self
.
_filelineno
=
0
self
.
_file
=
None
self
.
_file
=
None
self
.
_readline
=
self
.
_start_readline
self
.
_isstdin
=
False
self
.
_isstdin
=
False
self
.
_backupfilename
=
None
self
.
_backupfilename
=
None
# restrict mode argument to reading modes
# restrict mode argument to reading modes
...
@@ -245,6 +244,7 @@ class FileInput:
...
@@ -245,6 +244,7 @@ class FileInput:
return
self
return
self
def
__next__
(
self
):
def
__next__
(
self
):
while
True
:
line
=
self
.
_readline
()
line
=
self
.
_readline
()
if
line
:
if
line
:
self
.
_filelineno
+=
1
self
.
_filelineno
+=
1
...
@@ -252,8 +252,7 @@ class FileInput:
...
@@ -252,8 +252,7 @@ class FileInput:
if
not
self
.
_file
:
if
not
self
.
_file
:
raise
StopIteration
raise
StopIteration
self
.
nextfile
()
self
.
nextfile
()
# Recursive call
# repeat with next file
return
self
.
__next__
()
def
__getitem__
(
self
,
i
):
def
__getitem__
(
self
,
i
):
if
i
!=
self
.
lineno
():
if
i
!=
self
.
lineno
():
...
@@ -277,7 +276,10 @@ class FileInput:
...
@@ -277,7 +276,10 @@ class FileInput:
finally
:
finally
:
file
=
self
.
_file
file
=
self
.
_file
self
.
_file
=
None
self
.
_file
=
None
self
.
_readline
=
self
.
_start_readline
try
:
del
self
.
_readline
# restore FileInput._readline
except
AttributeError
:
pass
try
:
try
:
if
file
and
not
self
.
_isstdin
:
if
file
and
not
self
.
_isstdin
:
file
.
close
()
file
.
close
()
...
@@ -301,7 +303,7 @@ class FileInput:
...
@@ -301,7 +303,7 @@ class FileInput:
self
.
nextfile
()
self
.
nextfile
()
# repeat with next file
# repeat with next file
def
_
start_
readline
(
self
):
def
_readline
(
self
):
if
not
self
.
_files
:
if
not
self
.
_files
:
if
'b'
in
self
.
_mode
:
if
'b'
in
self
.
_mode
:
return
b''
return
b''
...
@@ -356,7 +358,7 @@ class FileInput:
...
@@ -356,7 +358,7 @@ class FileInput:
self
.
_file
=
self
.
_openhook
(
self
.
_filename
,
self
.
_mode
)
self
.
_file
=
self
.
_openhook
(
self
.
_filename
,
self
.
_mode
)
else
:
else
:
self
.
_file
=
open
(
self
.
_filename
,
self
.
_mode
)
self
.
_file
=
open
(
self
.
_filename
,
self
.
_mode
)
self
.
_readline
=
self
.
_file
.
readline
self
.
_readline
=
self
.
_file
.
readline
# hide FileInput._readline
return
self
.
_readline
()
return
self
.
_readline
()
def
filename
(
self
):
def
filename
(
self
):
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment