From d737216440e7a7b0abfe343bb9962ee2c969019e Mon Sep 17 00:00:00 2001 From: Henrik Levkowetz Date: Thu, 26 Sep 2013 20:02:05 +0000 Subject: [PATCH] Reverted the changes to django from branch/ssw/agenda/v4.70. - Legacy-Id: 6276 --- django/core/management/commands/runserver.py | 39 +++++-------------- django/core/management/commands/shell.py | 27 +++---------- django/core/management/commands/testserver.py | 4 +- django/core/servers/basehttp.py | 9 +---- django/http/__init__.py | 28 +------------ django/test/testcases.py | 7 ---- 6 files changed, 21 insertions(+), 93 deletions(-) diff --git a/django/core/management/commands/runserver.py b/django/core/management/commands/runserver.py index 9dcee47b9..fc2c694ab 100644 --- a/django/core/management/commands/runserver.py +++ b/django/core/management/commands/runserver.py @@ -1,17 +1,10 @@ from django.core.management.base import BaseCommand, CommandError from optparse import make_option import os -import socket import sys -import re - -naiveip_re = r'^(?:(?P\d{1,3}(?:\.\d{1,3}){3}|\[[a-fA-F0-9:]+\]):)?(?P\d+)$' -DEFAULT_PORT = "8000" class Command(BaseCommand): option_list = BaseCommand.option_list + ( - make_option('--ipv6', '-6', action='store_true', dest='enable_ipv6', default=False, - help='Force the use of IPv6 address.'), make_option('--noreload', action='store_false', dest='use_reloader', default=True, help='Tells Django to NOT use the auto-reloader.'), make_option('--adminmedia', dest='admin_media_path', default='', @@ -27,32 +20,21 @@ class Command(BaseCommand): import django from django.core.servers.basehttp import run, AdminMediaHandler, WSGIServerException from django.core.handlers.wsgi import WSGIHandler - enable_ipv6 = options.get('enable_ipv6') - if enable_ipv6 and not hasattr(socket, 'AF_INET6'): - raise CommandError("Your Python does not support IPv6.") - if args: raise CommandError('Usage is runserver %s' % self.args) if not addrport: addr = '' - port = DEFAULT_PORT + port = '8000' else: - m = re.match(naiveip_re, addrport) - if m is None: - raise CommandError("%r is not a valid port number or address:port pair." % addrport) - addr, port = m.groups() - - if not port.isdigit(): - raise CommandError("%r is not a valid port number." % port) - if addr: - if addr[0] == '[' and addr[-1] == ']': - enable_ipv6 = True - addr = addr[1:-1] - elif enable_ipv6: - raise CommandError("IPv6 addresses must be surrounded with brackets") + try: + addr, port = addrport.split(':') + except ValueError: + addr, port = '', addrport if not addr: addr = '127.0.0.1' - addr = (enable_ipv6 and '::1') or '127.0.0.1' + + if not port.isdigit(): + raise CommandError("%r is not a valid port number." % port) use_reloader = options.get('use_reloader', True) admin_media_path = options.get('admin_media_path', '') @@ -65,8 +47,7 @@ class Command(BaseCommand): print "Validating models..." self.validate(display_num_errors=True) print "\nDjango version %s, using settings %r" % (django.get_version(), settings.SETTINGS_MODULE) - fmt_addr = (enable_ipv6 and '[%s]' % addr) or addr - print "Development server is running at http://%s:%s/" % (fmt_addr, port) + print "Development server is running at http://%s:%s/" % (addr, port) print "Quit the server with %s." % quit_command # django.core.management.base forces the locale to en-us. We should @@ -76,7 +57,7 @@ class Command(BaseCommand): try: handler = AdminMediaHandler(WSGIHandler(), admin_media_path) - run(addr, int(port), handler, enable_ipv6=enable_ipv6) + run(addr, int(port), handler) except WSGIServerException, e: # Use helpful error messages instead of ugly tracebacks. ERRORS = { diff --git a/django/core/management/commands/shell.py b/django/core/management/commands/shell.py index 9f95464df..abb440e69 100644 --- a/django/core/management/commands/shell.py +++ b/django/core/management/commands/shell.py @@ -6,8 +6,6 @@ class Command(NoArgsCommand): option_list = NoArgsCommand.option_list + ( make_option('--plain', action='store_true', dest='plain', help='Tells Django to use plain Python, not IPython.'), - make_option('--test', action='store_true', dest='test', - help='Tells Django to load test environment'), ) help = "Runs a Python interactive interpreter. Tries to use IPython, if it's available." @@ -19,19 +17,6 @@ class Command(NoArgsCommand): from django.db.models.loading import get_models loaded_models = get_models() - use_test = options.get('test', False) - if use_test: - from django import test - print "Setting up test environment" - test.utils.setup_test_environment() # Setup the environment - from django.db import connection - print "Creating test db" - db = connection.creation.create_test_db() # Create the test db - print "Created test db, now loading data" - from django.core.management import call_command - call_command('loaddata', *['list', 'of', 'fixtures', 'here']) # Load fixtures - print "Created test db" - use_plain = options.get('plain', False) try: @@ -72,12 +57,12 @@ class Command(NoArgsCommand): # We want to honor both $PYTHONSTARTUP and .pythonrc.py, so follow system # conventions and get $PYTHONSTARTUP first then import user. - if not use_plain: - pythonrc = os.environ.get("PYTHONSTARTUP") - if pythonrc and os.path.isfile(pythonrc): - try: - execfile(pythonrc) - except NameError: + if not use_plain: + pythonrc = os.environ.get("PYTHONSTARTUP") + if pythonrc and os.path.isfile(pythonrc): + try: + execfile(pythonrc) + except NameError: pass # This will import .pythonrc.py as a side-effect import user diff --git a/django/core/management/commands/testserver.py b/django/core/management/commands/testserver.py index 121c6d9e3..6c75a3e2b 100644 --- a/django/core/management/commands/testserver.py +++ b/django/core/management/commands/testserver.py @@ -7,8 +7,6 @@ class Command(BaseCommand): make_option('--addrport', action='store', dest='addrport', type='string', default='', help='port number or ipaddr:port to run the server on'), - make_option('--ipv6', '-6', action='store_true', dest='enable_ipv6', default=False, - help='Forces IPv6 support.'), ) help = 'Runs a development server with data from the given fixture(s).' args = '[fixture ...]' @@ -32,4 +30,4 @@ class Command(BaseCommand): # a strange error -- it causes this handle() method to be called # multiple times. shutdown_message = '\nServer stopped.\nNote that the test database, %r, has not been deleted. You can explore it on your own.' % db_name - call_command('runserver', addrport=addrport, shutdown_message=shutdown_message, use_reloader=False, enable_ipv6=options['enable_ipv6']) + call_command('runserver', addrport=addrport, shutdown_message=shutdown_message, use_reloader=False) diff --git a/django/core/servers/basehttp.py b/django/core/servers/basehttp.py index 0df0210ee..dae429737 100644 --- a/django/core/servers/basehttp.py +++ b/django/core/servers/basehttp.py @@ -11,7 +11,6 @@ from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer import mimetypes import os import re -import socket import stat import sys import urllib @@ -715,12 +714,8 @@ class AdminMediaHandler(object): start_response(status, headers.items()) return output -class WSGIServerV6(WSGIServer): - address_family = socket.AF_INET6 - -def run(addr, port, wsgi_handler, enable_ipv6=False): +def run(addr, port, wsgi_handler): server_address = (addr, port) - server_class = (enable_ipv6 and WSGIServerV6) or WSGIServer - httpd = server_class(server_address, WSGIRequestHandler) + httpd = WSGIServer(server_address, WSGIRequestHandler) httpd.set_app(wsgi_handler) httpd.serve_forever() diff --git a/django/http/__init__.py b/django/http/__init__.py index 7b508d4f7..83874afa8 100644 --- a/django/http/__init__.py +++ b/django/http/__init__.py @@ -21,9 +21,6 @@ RESERVED_CHARS="!*'();:@&=+$,/?%#[]" absolute_http_url_re = re.compile(r"^https?://", re.I) -class Http403(Exception): - pass - class Http404(Exception): pass @@ -78,15 +75,6 @@ class HttpRequest(object): location = urljoin(current_uri, location) return iri_to_uri(location) - # added by mcr@sandelman.ca - def get_host_protocol(self): - """ - Builds an absolute URI for the server. - """ - current_uri = '%s://%s' % (self.is_secure() and 'https' or 'http', - self.get_host()) - return iri_to_uri(current_uri) - def is_secure(self): return os.environ.get("HTTPS") == "on" @@ -425,22 +413,10 @@ class HttpResponse(object): def _get_content(self): if self.has_header('Content-Encoding'): return ''.join(self._container) - # the /meeting/75/agenda/mip4 test case results in - # self._container == [None] - f1 = '' - try: - f1 = ''.join(self._container) - except: - pass - #import sys - #sys.stdout.write("container: %s" % (self._container)) - return smart_str(f1, self._charset) + return smart_str(''.join(self._container), self._charset) def _set_content(self, value): - if value is None: - self._container = [''] - else: - self._container = [value] + self._container = [value] self._is_string = True content = property(_get_content, _set_content) diff --git a/django/test/testcases.py b/django/test/testcases.py index 71e090af6..7667b0943 100644 --- a/django/test/testcases.py +++ b/django/test/testcases.py @@ -533,9 +533,6 @@ class TestCase(TransactionTestCase): to use TransactionTestCase, if you need transaction management inside a test. """ - # fixtures_loaded is for AgendaTransactionTestCase. - fixtures_loaded = False - def _fixture_setup(self): if not connections_support_transactions(): return super(TestCase, self)._fixture_setup() @@ -548,10 +545,6 @@ class TestCase(TransactionTestCase): databases = [DEFAULT_DB_ALIAS] for db in databases: - # should be a no-op, but another test case method might have left junk. - call_command('flush', verbosity=0, interactive=False, database=db) - TestCase.fixtures_loaded = False - transaction.enter_transaction_management(using=db) transaction.managed(True, using=db) disable_transaction_methods()