classification
Title: Missing module code does spurious file search
Type: behavior Stage: test needed
Components: Interpreter Core Versions: Python 3.2, Python 3.1, Python 2.7
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: ajaksu2, nmm, zbysz
Priority: normal Keywords:

Created on 2006-06-29 16:13 by nmm, last changed 2010-08-22 11:06 by BreamoreBoy.

Messages (4)
msg60931 - (view) Author: Nick Maclaren (nmm) Date: 2006-06-29 16:13
Now, exactly WHY is it looking for a file called
<stdin>? :-)

This bug has been present since at least 2.3.3 - I
can't be bothered to
check back further.  Not surprisingly, it causes
misbehaviour if there
is a file called <stdin> in any of the places searched,
but it doesn't
strike me as the world's most catastrophic bug.



strace -e open python
Python 2.5b1 (trunk:47059, Jun 29 2006, 14:26:46)
[GCC 4.1.0 (SUSE Linux)] on linux2
>>> import dismal
open("dismal.so", O_RDONLY)             = -1 ENOENT (No
such file or directory)open("dismalmodule.so",
O_RDONLY)       = -1 ENOENT (No such file or directory)
open("dismal.py", O_RDONLY)             = -1 ENOENT (No
such file or directory)
open("dismal.pyc", O_RDONLY)            = -1 ENOENT (No
such file or directory)
open("/home/nmm/Python_2.5/lib/python2.5/dismal.so",
O_RDONLY) = -1 ENOENT (No such file or directory)
open("/home/nmm/Python_2.5/lib/python2.5/<stdin>",
O_RDONLY) = -1 ENOENT (No such file or directory)
open("/home/nmm/Python_2.5/lib/python2.5/plat-linux2/<stdin>",
O_RDONLY) = -1 ENOENT (No such file or directory)
open("/home/nmm/Python_2.5/lib/python2.5/lib-tk/<stdin>",
O_RDONLY) = -1 ENOENT (No such file or directory)
open("/home/nmm/Python_2.5/lib/python2.5/lib-dynload/<stdin>",
O_RDONLY) = -1 ENOENT (No such file or directory)
open("/home/nmm/Python_2.5/lib/python2.5/site-packages/<stdin>",
O_RDONLY) = -1 ENOENT (No such file or directory)
  File "<stdin>", line 1, in <module>
ImportError: No module named dismal
>>>
msg60932 - (view) Author: Ronald Oussoren (ronaldoussoren) * (Python committer) Date: 2006-07-13 12:04
Logged In: YES 
user_id=580910

It's probably looking for a file named <stdin> because the co_filename 
attribute for code that's executed from the interactive prompt has that value:

>>> import sys
>>> f = sys._getframe(0)
>>> f.f_code.co_filename
'<stdin>'

I agree that looking for that file is rather pointless and a bug.
msg84515 - (view) Author: Daniel Diniz (ajaksu2) Date: 2009-03-30 05:56
Confirmed in py3k and trunk. It's also possible to create a file named
"<stdin>", I seem to recall discussion on this.
msg86735 - (view) Author: Zbyszek Jędrzejewski-Szmek (zbysz) * Date: 2009-04-28 13:10
The bug is certainly not catastrophic, but creates
a slight security risk:

ln -s /etc/shadow '<stdin>'
some-suid-program -with-error

or whatever.
History
Date User Action Args
2010-08-22 11:06:09BreamoreBoysetversions: + Python 3.1, Python 2.7, Python 3.2, - Python 2.6, Python 3.0
2009-04-28 13:29:08ronaldoussorensetnosy: - ronaldoussoren
2009-04-28 13:10:45zbyszsetnosy: + zbysz
messages: + msg86735
2009-03-30 05:56:57ajaksu2setversions: + Python 2.6, Python 3.0, - Python 2.5
nosy: + ajaksu2

messages: + msg84515

type: behavior
stage: test needed
2006-06-29 16:13:21nmmcreate