32 | | import code |
33 | | # Set up a dictionary to serve as the environment for the shell, so |
34 | | # that tab completion works on objects that are imported at runtime. |
35 | | # See ticket 5082. |
36 | | imported_objects = {} |
37 | | try: # Try activating rlcompleter, because it's handy. |
38 | | import readline |
| 33 | try: |
| 34 | if use_plain: |
| 35 | raise ImportError |
| 36 | import bpython |
| 37 | # Older versions of bpython do not support embed(). When |
| 38 | # specifying the --bpython flag, an attributeError is raised |
| 39 | # telling the user to upgrade. Otherwise, fall back to the |
| 40 | # plain interpreter. |
| 41 | try: |
| 42 | bpython.embed() |
| 43 | except AttributeError: |
| 44 | if use_bpython: |
| 45 | raise AttributeError("Your version of bpython does not support embedding. Please upgrade to the latest version.") |
| 46 | else: |
| 47 | raise ImportError |
40 | | pass |
41 | | else: |
42 | | # We don't have to wrap the following import in a 'try', because |
43 | | # we already know 'readline' was imported successfully. |
44 | | import rlcompleter |
45 | | readline.set_completer(rlcompleter.Completer(imported_objects).complete) |
46 | | readline.parse_and_bind("tab:complete") |
| 49 | # When specifying the --bpython flag and the import fails, |
| 50 | # do not fall back to the plain interpreter. |
| 51 | if use_bpython: |
| 52 | raise ImportError("You do not have bpython installed") |
| 53 | import code |
| 54 | # Set up a dictionary to serve as the environment for the shell, so |
| 55 | # that tab completion works on objects that are imported at runtime. |
| 56 | # See ticket 5082. |
| 57 | imported_objects = {} |
| 58 | try: # Try activating rlcompleter, because it's handy. |
| 59 | import readline |
| 60 | except ImportError: |
| 61 | pass |
| 62 | else: |
| 63 | # We don't have to wrap the following import in a 'try', because |
| 64 | # we already know 'readline' was imported successfully. |
| 65 | import rlcompleter |
| 66 | readline.set_completer(rlcompleter.Completer(imported_objects).complete) |
| 67 | readline.parse_and_bind("tab:complete") |
48 | | # We want to honor both $PYTHONSTARTUP and .pythonrc.py, so follow system |
49 | | # conventions and get $PYTHONSTARTUP first then import user. |
50 | | if not use_plain: |
51 | | pythonrc = os.environ.get("PYTHONSTARTUP") |
52 | | if pythonrc and os.path.isfile(pythonrc): |
53 | | try: |
54 | | execfile(pythonrc) |
55 | | except NameError: |
56 | | pass |
| 69 | # We want to honor both $PYTHONSTARTUP and .pythonrc.py, so follow system |
| 70 | # conventions and get $PYTHONSTARTUP first then import user. |
| 71 | if not use_plain: |
| 72 | pythonrc = os.environ.get("PYTHONSTARTUP") |
| 73 | if pythonrc and os.path.isfile(pythonrc): |
| 74 | try: |
| 75 | execfile(pythonrc) |
| 76 | except NameError: |
| 77 | pass |