Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
PyPy
pypy
Commits
650405891542
Commit
5421f36b
authored
May 30, 2014
by
Matti Picus
Browse files
close files opened during import (upstream issue 21610 created and patch submitted)
parent
94a0df43071c
Changes
2
Show whitespace changes
Inline
Side-by-side
lib-python/2.7/imputil.py
View file @
65040589
...
...
@@ -422,7 +422,8 @@ def _compile(pathname, timestamp):
saved back to the filesystem for future imports. The source file's
modification timestamp must be provided as a Long value.
"""
codestring
=
open
(
pathname
,
'rU'
).
read
()
with
open
(
pathname
,
'rU'
)
as
fp
:
codestring
=
fp
.
read
()
if
codestring
and
codestring
[
-
1
]
!=
'
\n
'
:
codestring
=
codestring
+
'
\n
'
code
=
__builtin__
.
compile
(
codestring
,
pathname
,
'exec'
)
...
...
@@ -603,7 +604,7 @@ class DynLoadSuffixImporter:
self
.
desc
=
desc
def
import_file
(
self
,
filename
,
finfo
,
fqname
):
fp
=
open
(
filename
,
self
.
desc
[
1
])
with
open
(
filename
,
self
.
desc
[
1
])
as
fp
:
module
=
imp
.
load_module
(
fqname
,
fp
,
filename
,
self
.
desc
)
module
.
__file__
=
filename
return
0
,
module
,
{
}
...
...
lib-python/2.7/modulefinder.py
View file @
65040589
...
...
@@ -109,14 +109,14 @@ class ModuleFinder:
def
run_script
(
self
,
pathname
):
self
.
msg
(
2
,
"run_script"
,
pathname
)
fp
=
open
(
pathname
,
READ_MODE
)
with
open
(
pathname
,
READ_MODE
)
as
fp
:
stuff
=
(
""
,
"r"
,
imp
.
PY_SOURCE
)
self
.
load_module
(
'__main__'
,
fp
,
pathname
,
stuff
)
def
load_file
(
self
,
pathname
):
dir
,
name
=
os
.
path
.
split
(
pathname
)
name
,
ext
=
os
.
path
.
splitext
(
name
)
fp
=
open
(
pathname
,
READ_MODE
)
with
open
(
pathname
,
READ_MODE
)
as
fp
:
stuff
=
(
ext
,
"r"
,
imp
.
PY_SOURCE
)
self
.
load_module
(
name
,
fp
,
pathname
,
stuff
)
...
...
@@ -461,6 +461,8 @@ class ModuleFinder:
fp
,
buf
,
stuff
=
self
.
find_module
(
"__init__"
,
m
.
__path__
)
self
.
load_module
(
fqname
,
fp
,
buf
,
stuff
)
self
.
msgout
(
2
,
"load_package ->"
,
m
)
if
fp
:
fp
.
close
()
return
m
def
add_module
(
self
,
fqname
):
...
...
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