Ticket #9990: shell-1.3-svn-r15506.patch

File shell-1.3-svn-r15506.patch, 3.2 KB (added by bruno desthuilliers <bruno.desthuilliers@…>, 13 years ago)

patch against r15506

  • .py

    old new  
    22from django.core.management.base import NoArgsCommand
    33from optparse import make_option
    44
     5# BD-WSB looks like we need it to be in globals
     6# else the test on readline.get_completer fails ???
     7try:
     8    import readline
     9except ImportError:
     10    pass
     11
    512class Command(NoArgsCommand):
    613    option_list = NoArgsCommand.option_list + (
    714        make_option('--plain', action='store_true', dest='plain',
     
    5966            # that tab completion works on objects that are imported at runtime.
    6067            # See ticket 5082.
    6168            imported_objects = {}
     69
     70            # BD-WSB: if pythonrc already defines a (possibly better) completion,
     71            # this screw up everything, so better to *first* load pythonrc,
     72            # then test if it's necessary to add completion
     73
     74            # XXX : cf http://code.djangoproject.com/ticket/5936
     75            # the plain python shell __would__ use PYTHONSTARTUP and .pythonrc.py
     76            # so WTF ?
     77            # if not use_plain:
     78            pythonrc = os.environ.get("PYTHONSTARTUP")
     79            if pythonrc and os.path.isfile(pythonrc):
     80                try:
     81                    #print "loading pythonrc file %s" % pythonrc
     82                    execfile(pythonrc, imported_objects)
     83                except NameError:
     84                    pass
     85            # This will import .pythonrc.py as a side-effect
     86            import user
     87           
     88            # XXX
    6289            try: # Try activating rlcompleter, because it's handy.
    63                 import readline
    64             except ImportError:
     90                readline
     91            except NameError:
    6592                pass
    6693            else:
    67                 # We don't have to wrap the following import in a 'try', because
    68                 # we already know 'readline' was imported successfully.
    69                 import rlcompleter
    70                 readline.set_completer(rlcompleter.Completer(imported_objects).complete)
    71                 readline.parse_and_bind("tab:complete")
    72 
    73             # We want to honor both $PYTHONSTARTUP and .pythonrc.py, so follow system
    74             # conventions and get $PYTHONSTARTUP first then import user.
    75             if not use_plain:
    76                 pythonrc = os.environ.get("PYTHONSTARTUP")
    77                 if pythonrc and os.path.isfile(pythonrc):
    78                     try:
    79                         execfile(pythonrc)
    80                     except NameError:
    81                         pass
    82                 # This will import .pythonrc.py as a side-effect
    83                 import user
     94                # XXX check if completer is already setup by the pythonrc
     95                # else add a simple completion
     96                if not readline.get_completer():
     97                    # We don't have to wrap the following import in a 'try', because
     98                    # we already know 'readline' was imported successfully.
     99                    import rlcompleter
     100                    readline.set_completer(rlcompleter.Completer(imported_objects).complete)
     101                    readline.parse_and_bind("tab:complete")
     102
    84103            code.interact(local=imported_objects)
Back to Top