+ def getMultilineCommand(self, rstrip=1):
+ """Extract a multi-line command from the editor.
+
+ The command may not necessarily be valid Python syntax."""
+ # XXX Need to extract real prompts here. Need to keep track of the
+ # prompt every time a command is issued.
+ ps1 = str(sys.ps1)
+ ps1size = len(ps1)
+ ps2 = str(sys.ps2)
+ ps2size = len(ps2)
+ # This is a total hack job, but it works.
+ text = self.GetCurLine()[0]
+ line = self.GetCurrentLine()
+ while text[:ps2size] == ps2 and line > 0:
+ line -= 1
+ self.GotoLine(line)
+ text = self.GetCurLine()[0]
+ if text[:ps1size] == ps1:
+ line = self.GetCurrentLine()
+ self.GotoLine(line)
+ startpos = self.GetCurrentPos() + ps1size
+ line += 1
+ self.GotoLine(line)
+ while self.GetCurLine()[0][:ps2size] == ps2:
+ line += 1
+ self.GotoLine(line)
+ stoppos = self.GetCurrentPos()
+ command = self.GetTextRange(startpos, stoppos)
+ command = command.replace(os.linesep + sys.ps2, '\n')
+ command = command.rstrip()
+ command = command.replace('\n', os.linesep + sys.ps2)
+ else:
+ command = ''
+ if rstrip:
+ command = command.rstrip()
+ return command
+