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: sys.ps1 not protected in EditorWindow.py
Type: Stage:
Components: IDLE Versions: Python 2.3
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: kbk Nosy List: d_florek, kbk
Priority: normal Keywords:

Created on 2004-08-16 22:15 by d_florek, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (6)
msg22091 - (view) Author: Dave Florek (d_florek) Date: 2004-08-16 22:15
Python 2.3.4 on
Linux <host> 2.4.19-xfs-p3-929 #1 SMP Thu Oct 24
11:29:34 PDT 2002 i686 unknown
(RedHat 7.3, patched)

Auto-indenting fails (and dumps errors to the shell)
when idle is started as a file editor.  I've wrapped
original lines 987 and 1057 of EditorWindow.py
(last_line_of_prompt = sys.ps1.split('\n')[-1]) with

if self.context_use_ps1:
    last_line_of_prompt = sys.ps1.split('\n')[-1]
else:
    last_line_of_prompt = '>>> '

This seems to fix it (might want to double-check other
attempts to access sys.ps1 and make sure they're
likewise protected).

FYI, the errors I got (other than incorrect line
numbers -- I was  tracking down a different problem
when I stumbled across this) are:

Exception in Tkinter callback
Traceback (most recent call last):
  File "/usr/local/lib/python2.3/lib-tk/Tkinter.py",
line 1345, in __call__
    return self.func(*args)
  File
"/work/florek/dev/python2.3/idlelib/EditorWindow.py",
line 1069, in newline_and_indent_event
    last_line_of_prompt = sys.ps1.split('\n')[-1]
AttributeError: 'module' object has no attribute 'ps1'

msg22092 - (view) Author: Kurt B. Kaiser (kbk) * (Python committer) Date: 2004-08-17 06:36
Logged In: YES 
user_id=149084

When IDLE starts via PyShell.main() sys.ps1 is set
to '>>>' at line 1273.  How are you "starting idle as a
file editor?"  It may be started either with the idle script
(probably in /usr/bin/ if IDLE was installed from the rpm)
or by calling ../../python ./PyShell.py from .../Lib/idlelib.
Also, take a look at idle.py, it's pretty flexible.
msg22093 - (view) Author: Dave Florek (d_florek) Date: 2004-08-17 17:10
Logged In: YES 
user_id=1105316

We have a Tk-based app that integrates IDLE as the default
text editor for python "scriptlets".  We create a new
idlelib.FileList attached to the parent gui, and then
on-demand from a button do a

editor = self.parentGui.flist.open(file)
editor.set_close_hook(lambda self=self:
self.parentGui.close_idle(self))
self.editor = editor

the close_idle callback, among other things, calls
flist.close_edit(widget.editor)

I'll look at idle.py and PyShell.py for more ideas, but it
seems to me if there's a valid "context" flag that indicates
whether IDLE is acting as a Python shell interface or as a
text-editor, then that flag should be used in this
particular case, since there won't be a prompt when acting
as a text-editor, and then there's no need to ensure that
sys.ps1 is currently defined.

Thanks,
Dave
msg22094 - (view) Author: Kurt B. Kaiser (kbk) * (Python committer) Date: 2004-08-18 02:15
Logged In: YES 
user_id=149084

I'm thinking that it might be best to move the code
which sets sys.ps1 from PyShell.main() to the 
EditorWindow module toplevel.  Do you see a
downside to that? (sys.ps1 is only defined for the
python interactive interpreter, so it's undefined in
IDLE until set.)
msg22095 - (view) Author: Dave Florek (d_florek) Date: 2004-08-18 20:48
Logged In: YES 
user_id=1105316

Whatever fixes the problem is fine with me.  Knock yourself
out.  Seems to me that cases which are specific to
run-as-shell or run-as-editor should be sensibly divided
rather than "if there isn't a prompt then create a fake one"
hacks, but you're the one who has to maintain it down the
road.  As I illustrated, I already have a fix in place.
msg22096 - (view) Author: Kurt B. Kaiser (kbk) * (Python committer) Date: 2006-07-24 17:14
Logged In: YES 
user_id=149084

Rev 50804
moved sys.ps1 test to EditorWindow init.
History
Date User Action Args
2022-04-11 14:56:06adminsetgithub: 40770
2004-08-16 22:15:02d_florekcreate