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
b82b3804
Commit
b82b3804
authored
Apr 20, 2012
by
Brett Cannon
Browse files
Options
Browse Files
Download
Plain Diff
merge
parents
f3beed11
ffa5d6f2
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
26 additions
and
27 deletions
+26
-27
Lib/test/test_imp.py
Lib/test/test_imp.py
+11
-0
Lib/test/test_import.py
Lib/test/test_import.py
+0
-22
Python/dynload_shlib.c
Python/dynload_shlib.c
+10
-1
Python/importdl.c
Python/importdl.c
+5
-4
No files found.
Lib/test/test_imp.py
View file @
b82b3804
...
...
@@ -179,6 +179,17 @@ class ImportTests(unittest.TestCase):
self
.
assertRaises
(
SyntaxError
,
imp
.
find_module
,
"badsyntax_pep3120"
,
[
path
])
def
test_load_dynamic_ImportError_path
(
self
):
# Issue #1559549 added `name` and `path` attributes to ImportError
# in order to provide better detail. Issue #10854 implemented those
# attributes on import failures of extensions on Windows.
path
=
'bogus file path'
name
=
'extension'
with
self
.
assertRaises
(
ImportError
)
as
err
:
imp
.
load_dynamic
(
name
,
path
)
self
.
assertIn
(
path
,
err
.
exception
.
path
)
self
.
assertEqual
(
name
,
err
.
exception
.
name
)
class
ReloadTests
(
unittest
.
TestCase
):
...
...
Lib/test/test_import.py
View file @
b82b3804
...
...
@@ -337,28 +337,6 @@ class ImportTests(unittest.TestCase):
del
sys
.
path
[
0
]
remove_files
(
TESTFN
)
@
unittest
.
skipUnless
(
sys
.
platform
==
"win32"
,
"Windows-specific"
)
def
test_extension_import_fail
(
self
):
# Issue 1559549 added `name` and `path` attributes to ImportError
# in order to provide better detail. Issue 10854 implemented those
# attributes on import failures of extensions on Windows.
debug
=
True
if
sys
.
executable
[
-
6
:]
==
"_d.exe"
else
False
pkg_name
=
"extension"
pkg_file
=
pkg_name
+
"{}"
.
format
(
"_d.pyd"
if
debug
else
".pyd"
)
with
open
(
pkg_file
,
"w"
):
pass
importlib
.
invalidate_caches
()
try
:
with
self
.
assertRaises
(
ImportError
)
as
err
:
import
extension
self
.
assertEqual
(
err
.
exception
.
name
,
pkg_name
)
# The path we get back has the dot-slash, e.g., ".\\extension.pyd"
self
.
assertIsNotNone
(
err
.
exception
.
path
,
'unexpected None for ImportError.path: '
'{!r}'
.
format
(
err
.
exception
))
self
.
assertEqual
(
os
.
path
.
relpath
(
err
.
exception
.
path
),
pkg_file
)
finally
:
unlink
(
pkg_file
)
class
PycRewritingTests
(
unittest
.
TestCase
):
# Test that the `co_filename` attribute on code objects always points
...
...
Python/dynload_shlib.c
View file @
b82b3804
...
...
@@ -129,10 +129,19 @@ dl_funcptr _PyImport_GetDynLoadFunc(const char *shortname,
handle
=
dlopen
(
pathname
,
dlopenflags
);
if
(
handle
==
NULL
)
{
PyObject
*
mod_name
=
NULL
;
PyObject
*
path
=
NULL
;
PyObject
*
error_ob
=
NULL
;
const
char
*
error
=
dlerror
();
if
(
error
==
NULL
)
error
=
"unknown dlopen() error"
;
PyErr_SetString
(
PyExc_ImportError
,
error
);
error_ob
=
PyUnicode_FromString
(
error
);
path
=
PyUnicode_FromString
(
pathname
);
mod_name
=
PyUnicode_FromString
(
shortname
);
PyErr_SetImportError
(
error_ob
,
mod_name
,
path
);
Py_DECREF
(
error_ob
);
Py_DECREF
(
path
);
Py_DECREF
(
mod_name
);
return
NULL
;
}
if
(
fp
!=
NULL
&&
nhandles
<
128
)
...
...
Python/importdl.c
View file @
b82b3804
...
...
@@ -74,10 +74,11 @@ _PyImport_LoadDynamicModule(PyObject *name, PyObject *path, FILE *fp)
if
(
PyErr_Occurred
())
goto
error
;
if
(
p
==
NULL
)
{
PyErr_Format
(
PyExc_ImportError
,
"dynamic module does not define init function"
" (PyInit_%s)"
,
shortname
);
PyObject
*
msg
=
PyUnicode_FromFormat
(
"dynamic module does not define "
"init function (PyInit_%s)"
,
shortname
);
PyErr_SetImportError
(
msg
,
name
,
path
);
Py_DECREF
(
msg
);
goto
error
;
}
oldcontext
=
_Py_PackageContext
;
...
...
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