Reverted the changes to django from branch/ssw/agenda/v4.70.

- Legacy-Id: 6276
This commit is contained in:
Henrik Levkowetz 2013-09-26 20:02:05 +00:00
parent 5206920a96
commit d737216440
6 changed files with 21 additions and 93 deletions

View file

@ -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<addr>\d{1,3}(?:\.\d{1,3}){3}|\[[a-fA-F0-9:]+\]):)?(?P<port>\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 = {

View file

@ -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

View file

@ -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)

View file

@ -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()

View file

@ -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)

View file

@ -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()