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
ba2d3a94
Commit
ba2d3a94
authored
Jan 09, 2008
by
Christian Heimes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed #1776. __import__() no longer imports modules by file name
parent
e168c061
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
25 additions
and
1 deletion
+25
-1
Lib/test/test_import.py
Lib/test/test_import.py
+11
-1
Misc/NEWS
Misc/NEWS
+4
-0
Python/import.c
Python/import.c
+10
-0
No files found.
Lib/test/test_import.py
View file @
ba2d3a94
from
test.test_support
import
TESTFN
,
run_unittest
,
catch_warning
from
test.test_support
import
TESTFN
,
run_unittest
,
catch_warning
import
unittest
import
os
...
...
@@ -223,6 +223,16 @@ class ImportTest(unittest.TestCase):
warnings
.
simplefilter
(
'error'
,
ImportWarning
)
self
.
assertRaises
(
ImportWarning
,
__import__
,
"site-packages"
)
def
test_importbyfilename
(
self
):
path
=
os
.
path
.
abspath
(
TESTFN
)
try
:
__import__
(
path
)
except
ImportError
,
err
:
self
.
assertEqual
(
"Import by filename is not supported."
,
err
.
args
[
0
])
else
:
self
.
fail
(
"import by path didn't raise an exception"
)
class
PathsTests
(
unittest
.
TestCase
):
path
=
TESTFN
...
...
Misc/NEWS
View file @
ba2d3a94
...
...
@@ -12,6 +12,10 @@ What's New in Python 2.6 alpha 1?
Core and builtins
-----------------
- Bug #1776: __import__ must not accept filenames. Python 2.6 does no longer
support module loading by filename. It worked on some system by coincident
but it was never intended to work.
- Patch #1668: renamed THREADDEBUG envvar to PYTHONTHREADDEBUG.
- Patch #602345: Add -B command line option, PYTHONDONTWRITEBYTECODE envvar
...
...
Python/import.c
View file @
ba2d3a94
...
...
@@ -2055,6 +2055,16 @@ import_module_level(char *name, PyObject *globals, PyObject *locals,
Py_ssize_t
buflen
=
0
;
PyObject
*
parent
,
*
head
,
*
next
,
*
tail
;
if
(
strchr
(
name
,
'/'
)
!=
NULL
#ifdef MS_WINDOWS
||
strchr
(
name
,
'\\'
)
!=
NULL
#endif
)
{
PyErr_SetString
(
PyExc_ImportError
,
"Import by filename is not supported."
);
return
NULL
;
}
parent
=
get_parent
(
globals
,
buf
,
&
buflen
,
level
);
if
(
parent
==
NULL
)
return
NULL
;
...
...
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