Changeset 8215 for django/branches/gis/django/core/handlers
- Timestamp:
- 08/05/08 12:15:33 (5 months ago)
- Files:
-
- django/branches/gis (modified) (1 prop)
- django/branches/gis/django/core/handlers/base.py (modified) (6 diffs)
- django/branches/gis/django/core/handlers/modpython.py (modified) (5 diffs)
- django/branches/gis/django/core/handlers/wsgi.py (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/branches/gis
- Property svnmerge-integrated changed from /django/trunk:1-7978 to /django/trunk:1-8214
django/branches/gis/django/core/handlers/base.py
r7979 r8215 4 4 from django.core import signals 5 5 from django.dispatch import dispatcher 6 from django.utils.encoding import force_unicode 6 7 7 8 class BaseHandler(object): … … 74 75 resolver = urlresolvers.RegexURLResolver(r'^/', urlconf) 75 76 try: 76 callback, callback_args, callback_kwargs = resolver.resolve(request.path) 77 callback, callback_args, callback_kwargs = resolver.resolve( 78 request.path_info) 77 79 78 80 # Apply view middleware … … 108 110 return debug.technical_404_response(request, e) 109 111 else: 110 callback, param_dict = resolver.resolve404() 111 return callback(request, **param_dict) 112 try: 113 callback, param_dict = resolver.resolve404() 114 return callback(request, **param_dict) 115 except: 116 return self.handle_uncaught_exception(request, resolver, sys.exc_info()) 112 117 except exceptions.PermissionDenied: 113 118 return http.HttpResponseForbidden('<h1>Permission denied</h1>') … … 119 124 exc_info = sys.exc_info() 120 125 receivers = dispatcher.send(signal=signals.got_request_exception, request=request) 121 122 if settings.DEBUG_PROPAGATE_EXCEPTIONS:123 raise124 126 return self.handle_uncaught_exception(request, resolver, exc_info) 125 127 … … 136 138 from django.conf import settings 137 139 from django.core.mail import mail_admins 140 141 if settings.DEBUG_PROPAGATE_EXCEPTIONS: 142 raise 138 143 139 144 if settings.DEBUG: … … 168 173 return response 169 174 175 def get_script_name(environ): 176 """ 177 Returns the equivalent of the HTTP request's SCRIPT_NAME environment 178 variable. If Apache mod_rewrite has been used, returns what would have been 179 the script name prior to any rewriting (so it's the script name as seen 180 from the client's perspective), unless DJANGO_USE_POST_REWRITE is set (to 181 anything). 182 """ 183 from django.conf import settings 184 if settings.FORCE_SCRIPT_NAME is not None: 185 return force_unicode(settings.FORCE_SCRIPT_NAME) 186 187 # If Apache's mod_rewrite had a whack at the URL, Apache set either 188 # SCRIPT_URL or REDIRECT_URL to the full resource URL before applying any 189 # rewrites. Unfortunately not every webserver (lighttpd!) passes this 190 # information through all the time, so FORCE_SCRIPT_NAME, above, is still 191 # needed. 192 script_url = environ.get('SCRIPT_URL', u'') 193 if not script_url: 194 script_url = environ.get('REDIRECT_URL', u'') 195 if script_url: 196 return force_unicode(script_url[:-len(environ.get('PATH_INFO', ''))]) 197 return force_unicode(environ.get('SCRIPT_NAME', u'')) 198 django/branches/gis/django/core/handlers/modpython.py
r7836 r8215 5 5 from django.core import signals 6 6 from django.core.handlers.base import BaseHandler 7 from django.core.urlresolvers import set_script_prefix 7 8 from django.dispatch import dispatcher 8 9 from django.utils import datastructures … … 16 17 def __init__(self, req): 17 18 self._req = req 19 # FIXME: This isn't ideal. The request URI may be encoded (it's 20 # non-normalized) slightly differently to the "real" SCRIPT_NAME 21 # and PATH_INFO values. This causes problems when we compute path_info, 22 # below. For now, don't use script names that will be subject to 23 # encoding/decoding. 18 24 self.path = force_unicode(req.uri) 25 root = req.get_options().get('django.root', '') 26 self.django_root = root 27 # req.path_info isn't necessarily computed correctly in all 28 # circumstances (it's out of mod_python's control a bit), so we use 29 # req.uri and some string manipulations to get the right value. 30 if root and req.uri.startswith(root): 31 self.path_info = force_unicode(req.uri[len(root):]) 32 else: 33 self.path_info = self.path 34 if not self.path_info: 35 # Django prefers empty paths to be '/', rather than '', to give us 36 # a common start character for URL patterns. So this is a little 37 # naughty, but also pretty harmless. 38 self.path_info = u'/' 19 39 20 40 def __repr__(self): … … 101 121 'CONTENT_TYPE': self._req.content_type, # This may be wrong 102 122 'GATEWAY_INTERFACE': 'CGI/1.1', 103 'PATH_INFO': self. _req.path_info,123 'PATH_INFO': self.path_info, 104 124 'PATH_TRANSLATED': None, # Not supported 105 125 'QUERY_STRING': self._req.args, … … 109 129 'REMOTE_USER': self._req.user, 110 130 'REQUEST_METHOD': self._req.method, 111 'SCRIPT_NAME': None, # Not supported131 'SCRIPT_NAME': self.django_root, 112 132 'SERVER_NAME': self._req.server.server_hostname, 113 133 'SERVER_PORT': self._req.server.port, … … 154 174 self.load_middleware() 155 175 176 set_script_prefix(req.get_options().get('django.root', '')) 156 177 dispatcher.send(signal=signals.request_started) 157 178 try: django/branches/gis/django/core/handlers/wsgi.py
r7836 r8215 8 8 from django import http 9 9 from django.core import signals 10 from django.core.handlers.base import BaseHandler 10 from django.core.handlers import base 11 from django.core.urlresolvers import set_script_prefix 11 12 from django.dispatch import dispatcher 12 13 from django.utils import datastructures … … 75 76 class WSGIRequest(http.HttpRequest): 76 77 def __init__(self, environ): 78 script_name = base.get_script_name(environ) 79 path_info = force_unicode(environ.get('PATH_INFO', u'/')) 80 if not path_info: 81 # Sometimes PATH_INFO exists, but is empty (e.g. accessing 82 # the SCRIPT_NAME URL without a trailing slash). We really need to 83 # operate as if they'd requested '/'. Not amazingly nice to force 84 # the path like this, but should be harmless. 85 path_info = u'/' 77 86 self.environ = environ 78 self.path = force_unicode(environ['PATH_INFO']) 87 self.path_info = path_info 88 self.path = '%s%s' % (script_name, path_info) 79 89 self.META = environ 90 self.META['PATH_INFO'] = path_info 91 self.META['SCRIPT_NAME'] = script_name 80 92 self.method = environ['REQUEST_METHOD'].upper() 81 93 … … 179 191 raw_post_data = property(_get_raw_post_data) 180 192 181 class WSGIHandler( BaseHandler):193 class WSGIHandler(base.BaseHandler): 182 194 initLock = Lock() 183 195 request_class = WSGIRequest … … 195 207 self.initLock.release() 196 208 209 set_script_prefix(base.get_script_name(environ)) 197 210 dispatcher.send(signal=signals.request_started) 198 211 try:
