Comments (0)

Files changed (1)

File pythonrc.py Modified

View file
  • Ignore whitespace
  • Hide word diff
 import os
 import sys
 import pprint
+import datetime
+from code import InteractiveConsole
+
 
 try:
     import readline
 except ImportError:
-    print 'Module readline not available.'
+    print('Module readline not available.')
 else:
     import rlcompleter
     readline.parse_and_bind('tab: complete')
 
 
 def my_displayhook(value):
+    global pprint  # Needed since Django 1.5, WTF?
  1. Peter Sanchez author

    For some reason, ONLY in Django 1.5 environment, is this needed. I'm probably missing something, but that was the only difference. Same virtualenv, same modules, same everything. The only difference is Django 1.4.5 and Django 1.5. So odd.

     if value is not None:
         try:
             import __builtin__
 
 
 if 'DJANGO_SETTINGS_MODULE' in os.environ:
+    from django.db.models import Q
+    from django.conf import settings as S
+    from django.test.client import Client
     from django.db.models.loading import get_models
-    from django.test.client import Client
     from django.test.utils import setup_test_environment, \
                                   teardown_test_environment
-    from django.conf import settings as S
 
     class DjangoModels(object):
         'Loop through all the models in INSTALLED_APPS and import them.'
         def __init__(self):
+            global get_models  # Needed since Django 1.5, WTF?
  1. Peter Sanchez author

    For some reason, ONLY in Django 1.5 environment, is this needed. I'm probably missing something, but that was the only difference. Same virtualenv, same modules, same everything. The only difference is Django 1.4.5 and Django 1.5. So odd.

             for m in get_models():
                 setattr(self, m.__name__, m)
 
     A = DjangoModels()
     C = Client()
 
-    setup_test_environment()
+    #setup_test_environment()
     S.DEBUG_PROPAGATE_EXCEPTIONS = True
 
     WELCOME += '''
 Warning: DEBUG_PROPAGATE_EXCEPTIONS has been set to True.
 '''
 
-
-# Start an external editor with \e
-# http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/438813/
-
-EDITOR = os.environ.get('EDITOR', 'vim')
-EDIT_CMD = '\e'
-
-from tempfile import mkstemp
-from code import InteractiveConsole
-
-class EditableBufferInteractiveConsole(InteractiveConsole):
-    def __init__(self, *args, **kwargs):
-        self.last_buffer = [] # This holds the last executed statement
-        InteractiveConsole.__init__(self, *args, **kwargs)
-
-    def runsource(self, source, *args):
-        self.last_buffer = [ source.encode('utf-8') ]
-        return InteractiveConsole.runsource(self, source, *args)
-
-    def raw_input(self, *args):
-        line = InteractiveConsole.raw_input(self, *args)
-        if line == EDIT_CMD:
-            fd, tmpfl = mkstemp('.py')
-            os.write(fd, b'\n'.join(self.last_buffer))
-            os.close(fd)
-            os.system('%s %s' % (EDITOR, tmpfl))
-            line = open(tmpfl).read()
-            os.unlink(tmpfl)
-            tmpfl = ''
-            lines = line.split( '\n' )
-            for i in range(len(lines) - 1): self.push( lines[i] )
-            line = lines[-1]
-        return line
-
-# clean up namespace
-#del sys
-#del os
-
-c = EditableBufferInteractiveConsole(locals=locals())
  1. Peter Sanchez author

    Again, this is an issue ONLY in Django 1.5 (because the InteractiveConsole was not available in init, runsource and raw_input).. I just removed this all together because I never used it, not even once. So I didn't mind it being gone.

+c = InteractiveConsole(locals=locals())
 c.interact(banner=WELCOME)
 
-# Exit the Python shell on exiting the InteractiveConsole
-#import sys
 sys.exit()
-