Show More
@@ -6,7 +6,7 b' Requires Python 2.3 or newer.' | |||
|
6 | 6 | |
|
7 | 7 | This file contains all the classes and helper functions specific to IPython. |
|
8 | 8 | |
|
9 |
$Id: iplib.py |
|
|
9 | $Id: iplib.py 3004 2008-02-01 10:24:29Z vivainio $ | |
|
10 | 10 | """ |
|
11 | 11 | |
|
12 | 12 | #***************************************************************************** |
@@ -223,6 +223,7 b' class InteractiveShell(object,Magic):' | |||
|
223 | 223 | |
|
224 | 224 | # Store the actual shell's name |
|
225 | 225 | self.name = name |
|
226 | self.more = False | |
|
226 | 227 | |
|
227 | 228 | # We need to know whether the instance is meant for embedding, since |
|
228 | 229 | # global/local namespaces need to be handled differently in that case |
@@ -1561,6 +1562,8 b' want to merge them back into the new files.""" % locals()' | |||
|
1561 | 1562 | while 1: |
|
1562 | 1563 | try: |
|
1563 | 1564 | self.interact(banner) |
|
1565 | # XXX for testing of a readline-decoupled repl loop | |
|
1566 | #self.interact_with_readline() | |
|
1564 | 1567 | break |
|
1565 | 1568 | except KeyboardInterrupt: |
|
1566 | 1569 | # this should not be necessary, but KeyboardInterrupt |
@@ -1647,6 +1650,62 b' want to merge them back into the new files.""" % locals()' | |||
|
1647 | 1650 | # and clean builtins we may have overridden |
|
1648 | 1651 | self.clean_builtins() |
|
1649 | 1652 | |
|
1653 | def interact_prompt(self): | |
|
1654 | """ Print the prompt (in read-eval-print loop) | |
|
1655 | ||
|
1656 | Provided for those who want to implement their own read-eval-print loop (e.g. GUIs), not | |
|
1657 | used in standard IPython flow. | |
|
1658 | """ | |
|
1659 | if self.more: | |
|
1660 | try: | |
|
1661 | prompt = self.hooks.generate_prompt(True) | |
|
1662 | except: | |
|
1663 | self.showtraceback() | |
|
1664 | if self.autoindent: | |
|
1665 | self.rl_do_indent = True | |
|
1666 | ||
|
1667 | else: | |
|
1668 | try: | |
|
1669 | prompt = self.hooks.generate_prompt(False) | |
|
1670 | except: | |
|
1671 | self.showtraceback() | |
|
1672 | self.write(prompt) | |
|
1673 | ||
|
1674 | def interact_handle_input(self,line): | |
|
1675 | """ Handle the input line (in read-eval-print loop) | |
|
1676 | ||
|
1677 | Provided for those who want to implement their own read-eval-print loop (e.g. GUIs), not | |
|
1678 | used in standard IPython flow. | |
|
1679 | """ | |
|
1680 | if line.lstrip() == line: | |
|
1681 | self.shadowhist.add(line.strip()) | |
|
1682 | lineout = self.prefilter(line,self.more) | |
|
1683 | ||
|
1684 | if line.strip(): | |
|
1685 | if self.more: | |
|
1686 | self.input_hist_raw[-1] += '%s\n' % line | |
|
1687 | else: | |
|
1688 | self.input_hist_raw.append('%s\n' % line) | |
|
1689 | ||
|
1690 | ||
|
1691 | self.more = self.push(lineout) | |
|
1692 | if (self.SyntaxTB.last_syntax_error and | |
|
1693 | self.rc.autoedit_syntax): | |
|
1694 | self.edit_syntax_error() | |
|
1695 | ||
|
1696 | def interact_with_readline(self): | |
|
1697 | """ Demo of using interact_handle_input, interact_prompt | |
|
1698 | ||
|
1699 | This is the main read-eval-print loop. If you need to implement your own (e.g. for GUI), | |
|
1700 | it should work like this. | |
|
1701 | """ | |
|
1702 | self.readline_startup_hook(self.pre_readline) | |
|
1703 | while not self.exit_now: | |
|
1704 | self.interact_prompt() | |
|
1705 | line = line = raw_input_original().decode(self.stdin_encoding) | |
|
1706 | self.interact_handle_input(line) | |
|
1707 | ||
|
1708 | ||
|
1650 | 1709 | def interact(self, banner=None): |
|
1651 | 1710 | """Closely emulate the interactive Python console. |
|
1652 | 1711 |
General Comments 0
You need to be logged in to leave comments.
Login now