This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: modules search in help() crashes on insufficient file perms
Type: Stage:
Components: Documentation Versions: Python 2.4
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: georg.brandl, hauptbeuteltier, logistix, splitscreen, terry.reedy
Priority: normal Keywords:

Created on 2006-02-25 09:41 by hauptbeuteltier, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (9)
msg27615 - (view) Author: A. Coder (hauptbeuteltier) Date: 2006-02-25 09:41
In the python interpreter, in the interactive online
help, typing <code>modules <keyword></code>
throws a permission denied error (Errno 13) and dumps
the user back to the main interpreter if the user has
insufficient permission to read any .py file from the
site-packages directory.


Example:
~:$ ls -l /usr/lib/python2.4/site-packages/pygtk.py
-rw-r-----  1 root root 2619 2005-02-20 14:18
/usr/lib/python2.4/site-packages/pygtk.py
~:$ python
>>> help()

help> modules html

Here is a list of matching modules.  Enter any module
name to get more help.

HTMLParser - A parser for HTML and XHTML.
htmlentitydefs - HTML character entity references.
htmllib - HTML 2.0 parser.
markupbase - Shared support for scanning document type
declarations in HTML and XHTML.
pydoc - Generate Python documentation in HTML or text
for interactive use.
test.test_htmllib 
test.test_htmlparser - Tests for HTMLParser.py.
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "/usr/lib/python2.4/site.py", line 328, in __call__
    return pydoc.help(*args, **kwds)
  File "/usr/lib/python2.4/pydoc.py", line 1650, in
__call__
    self.interact()
  File "/usr/lib/python2.4/pydoc.py", line 1668, in
interact
    self.help(request)
  File "/usr/lib/python2.4/pydoc.py", line 1686, in help
    self.listmodules(split(request)[1])
  File "/usr/lib/python2.4/pydoc.py", line 1790, in
listmodules
    apropos(key)
  File "/usr/lib/python2.4/pydoc.py", line 1900, in apropos
    ModuleScanner().run(callback, key)
  File "/usr/lib/python2.4/pydoc.py", line 1886, in run
    desc = synopsis(path) or ''
  File "/usr/lib/python2.4/pydoc.py", line 182, in synopsis
    file = open(filename)
IOError: [Errno 13] Permission denied:
'/usr/lib/python2.4/site-packages/tageditor.py'
>>>
msg27616 - (view) Author: A. Coder (hauptbeuteltier) Date: 2006-02-25 09:44
Logged In: YES 
user_id=1420716

My apologies. The tageditor.py file had the same permissions
for my test as pygtk.py. The particular file is irrelevant
in this case, it only matters that a user has insufficient
permissions for any file in the site-packages directory.
msg27617 - (view) Author: Matt Fleming (splitscreen) Date: 2006-02-25 12:34
Logged In: YES 
user_id=1126061

Could this just be silently skipped? i.e returning None if
the user does not have the corrept permissions to access a
particular file?

Just wrap the 'file = open(filename)' in pydoc.py: line 182
in a try: except block returning None if there's an error
(such as permission denied).

I have written a patch I can supply if anyone wants it and
if this is the Right Thing To Do (TM).
msg27618 - (view) Author: Grant Olson (logistix) Date: 2006-02-26 23:32
Logged In: YES 
user_id=699438

That patch sounds pretty-much right, but I think it should
print some feedback to stderr instead of silently swallowing
the exception.
msg27619 - (view) Author: Matt Fleming (splitscreen) Date: 2006-02-28 15:54
Logged In: YES 
user_id=1126061

Yeah, I've modified it to tell the user which file caused
the problem.

Want the patch posting to the Patch Manager?
msg27620 - (view) Author: Grant Olson (logistix) Date: 2006-02-28 21:55
Logged In: YES 
user_id=699438

I personally don't have commit rights, but yes, it's
generally easiest if you post the patch to Patch manager and
put a cross reference note on the bug.  Developers usually
give working patches precidence over bugs.
msg27621 - (view) Author: Matt Fleming (splitscreen) Date: 2006-03-01 00:08
Logged In: YES 
user_id=1126061

Patch #1440660 fixes this.
msg27622 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2006-03-06 03:18
Logged In: YES 
user_id=593130

I am tempted to say that the restricted file permission is 
the bug but enhancing pydoc seems reasonable to me.  It 
appears to open the file to get the first line of the doc 
string.  So I would have the exception clause instead 
return a string like "Permission denied: you cannot import 
this file.  See your system administrator for more."

I would have attached such a mini patch here.  Once a 
committer reads this bug report and decides to make a 
change, hardly any review is needed.
msg27623 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2006-03-08 09:37
Logged In: YES 
user_id=849994

Added the try-except in 42912, 42913 (2.4).

I do not do anything other than returning None, since the
description returned here is searched, and you wouldn't want
to find these modules when searching for "system".

Printing to stdout is out of the question.
Issuing a warning would be a possibility, but no other code
in pydoc does that.
History
Date User Action Args
2022-04-11 14:56:15adminsetgithub: 42949
2006-02-25 09:41:06hauptbeuteltiercreate