mirror of
https://github.com/django/django.git
synced 2025-11-07 07:15:35 +00:00
Fixed #18035 -- Removed deprecated AdminMediaHandler, as per official deprecation timeline. Thanks Jannis Leidel and Ramiro Morales for the review.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@17879 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
@@ -5,7 +5,7 @@ import sys
|
||||
import socket
|
||||
|
||||
from django.core.management.base import BaseCommand, CommandError
|
||||
from django.core.servers.basehttp import AdminMediaHandler, run, WSGIServerException, get_internal_wsgi_application
|
||||
from django.core.servers.basehttp import run, WSGIServerException, get_internal_wsgi_application
|
||||
from django.utils import autoreload
|
||||
|
||||
naiveip_re = re.compile(r"""^(?:
|
||||
@@ -17,7 +17,7 @@ naiveip_re = re.compile(r"""^(?:
|
||||
DEFAULT_PORT = "8000"
|
||||
|
||||
|
||||
class BaseRunserverCommand(BaseCommand):
|
||||
class Command(BaseCommand):
|
||||
option_list = BaseCommand.option_list + (
|
||||
make_option('--ipv6', '-6', action='store_true', dest='use_ipv6', default=False,
|
||||
help='Tells Django to use a IPv6 address.'),
|
||||
@@ -128,15 +128,6 @@ class BaseRunserverCommand(BaseCommand):
|
||||
self.stdout.write("%s\n" % shutdown_message)
|
||||
sys.exit(0)
|
||||
|
||||
class Command(BaseRunserverCommand):
|
||||
option_list = BaseRunserverCommand.option_list + (
|
||||
make_option('--adminmedia', dest='admin_media_path', default='',
|
||||
help='Specifies the directory from which to serve admin media.'),
|
||||
)
|
||||
|
||||
def get_handler(self, *args, **options):
|
||||
"""
|
||||
Serves admin media like old-school (deprecation pending).
|
||||
"""
|
||||
handler = super(Command, self).get_handler(*args, **options)
|
||||
return AdminMediaHandler(handler, options.get('admin_media_path'))
|
||||
# Kept for backward compatibility
|
||||
BaseRunserverCommand = Command
|
||||
|
||||
@@ -22,10 +22,6 @@ from django.core.exceptions import ImproperlyConfigured
|
||||
from django.core.management.color import color_style
|
||||
from django.core.wsgi import get_wsgi_application
|
||||
from django.utils.importlib import import_module
|
||||
from django.utils._os import safe_join
|
||||
from django.views import static
|
||||
|
||||
from django.contrib.staticfiles import handlers
|
||||
|
||||
__all__ = ['WSGIServer', 'WSGIRequestHandler']
|
||||
|
||||
@@ -131,7 +127,7 @@ class WSGIRequestHandler(simple_server.WSGIRequestHandler, object):
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
from django.conf import settings
|
||||
self.admin_media_prefix = urlparse.urljoin(settings.STATIC_URL, 'admin/')
|
||||
self.admin_static_prefix = urlparse.urljoin(settings.STATIC_URL, 'admin/')
|
||||
# We set self.path to avoid crashes in log_message() on unsupported
|
||||
# requests (like "OPTIONS").
|
||||
self.path = ''
|
||||
@@ -173,7 +169,7 @@ class WSGIRequestHandler(simple_server.WSGIRequestHandler, object):
|
||||
|
||||
def log_message(self, format, *args):
|
||||
# Don't bother logging requests for admin images or the favicon.
|
||||
if (self.path.startswith(self.admin_media_prefix)
|
||||
if (self.path.startswith(self.admin_static_prefix)
|
||||
or self.path == '/favicon.ico'):
|
||||
return
|
||||
|
||||
@@ -200,48 +196,6 @@ class WSGIRequestHandler(simple_server.WSGIRequestHandler, object):
|
||||
sys.stderr.write(msg)
|
||||
|
||||
|
||||
class AdminMediaHandler(handlers.StaticFilesHandler):
|
||||
"""
|
||||
WSGI middleware that intercepts calls to the admin media directory, as
|
||||
defined by the STATIC_URL setting, and serves those images.
|
||||
Use this ONLY LOCALLY, for development! This hasn't been tested for
|
||||
security and is not super efficient.
|
||||
|
||||
This is pending for deprecation since 1.3.
|
||||
"""
|
||||
def get_base_dir(self):
|
||||
return os.path.join(django.__path__[0], 'contrib', 'admin', 'static', 'admin')
|
||||
|
||||
def get_base_url(self):
|
||||
from django.conf import settings
|
||||
return urlparse.urljoin(settings.STATIC_URL, 'admin/')
|
||||
|
||||
def file_path(self, url):
|
||||
"""
|
||||
Returns the path to the media file on disk for the given URL.
|
||||
|
||||
The passed URL is assumed to begin with ``self.base_url``. If the
|
||||
resulting file path is outside the media directory, then a ValueError
|
||||
is raised.
|
||||
"""
|
||||
relative_url = url[len(self.base_url[2]):]
|
||||
relative_path = urllib.url2pathname(relative_url)
|
||||
return safe_join(self.base_dir, relative_path)
|
||||
|
||||
def serve(self, request):
|
||||
document_root, path = os.path.split(self.file_path(request.path))
|
||||
return static.serve(request, path, document_root=document_root)
|
||||
|
||||
def _should_handle(self, path):
|
||||
"""
|
||||
Checks if the path should be handled. Ignores the path if:
|
||||
|
||||
* the host is provided as part of the base_url
|
||||
* the request's path isn't under the base path
|
||||
"""
|
||||
return path.startswith(self.base_url[2]) and not self.base_url[1]
|
||||
|
||||
|
||||
def run(addr, port, wsgi_handler, ipv6=False, threading=False):
|
||||
server_address = (addr, port)
|
||||
if threading:
|
||||
|
||||
Reference in New Issue
Block a user