Django

Code

Show
Ignore:
Timestamp:
08/05/08 12:15:33 (5 months ago)
Author:
jbronn
Message:

gis: Merged revisions 7981-8001,8003-8011,8013-8033,8035-8036,8038-8039,8041-8063,8065-8076,8078-8139,8141-8154,8156-8214 via svnmerge from trunk.

Files:

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  
    44from django.core import signals 
    55from django.dispatch import dispatcher 
     6from django.utils.encoding import force_unicode 
    67 
    78class BaseHandler(object): 
     
    7475        resolver = urlresolvers.RegexURLResolver(r'^/', urlconf) 
    7576        try: 
    76             callback, callback_args, callback_kwargs = resolver.resolve(request.path) 
     77            callback, callback_args, callback_kwargs = resolver.resolve( 
     78                    request.path_info) 
    7779 
    7880            # Apply view middleware 
     
    108110                return debug.technical_404_response(request, e) 
    109111            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()) 
    112117        except exceptions.PermissionDenied: 
    113118            return http.HttpResponseForbidden('<h1>Permission denied</h1>') 
     
    119124            exc_info = sys.exc_info() 
    120125            receivers = dispatcher.send(signal=signals.got_request_exception, request=request) 
    121  
    122             if settings.DEBUG_PROPAGATE_EXCEPTIONS: 
    123                 raise 
    124126            return self.handle_uncaught_exception(request, resolver, exc_info) 
    125127 
     
    136138        from django.conf import settings 
    137139        from django.core.mail import mail_admins 
     140 
     141        if settings.DEBUG_PROPAGATE_EXCEPTIONS: 
     142            raise 
    138143 
    139144        if settings.DEBUG: 
     
    168173        return response 
    169174 
     175def 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  
    55from django.core import signals 
    66from django.core.handlers.base import BaseHandler 
     7from django.core.urlresolvers import set_script_prefix 
    78from django.dispatch import dispatcher 
    89from django.utils import datastructures 
     
    1617    def __init__(self, req): 
    1718        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. 
    1824        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'/' 
    1939 
    2040    def __repr__(self): 
     
    101121                'CONTENT_TYPE':      self._req.content_type, # This may be wrong 
    102122                'GATEWAY_INTERFACE': 'CGI/1.1', 
    103                 'PATH_INFO':         self._req.path_info, 
     123                'PATH_INFO':         self.path_info, 
    104124                'PATH_TRANSLATED':   None, # Not supported 
    105125                'QUERY_STRING':      self._req.args, 
     
    109129                'REMOTE_USER':       self._req.user, 
    110130                'REQUEST_METHOD':    self._req.method, 
    111                 'SCRIPT_NAME':       None, # Not supported 
     131                'SCRIPT_NAME':       self.django_root, 
    112132                'SERVER_NAME':       self._req.server.server_hostname, 
    113133                'SERVER_PORT':       self._req.server.port, 
     
    154174            self.load_middleware() 
    155175 
     176        set_script_prefix(req.get_options().get('django.root', '')) 
    156177        dispatcher.send(signal=signals.request_started) 
    157178        try: 
  • django/branches/gis/django/core/handlers/wsgi.py

    r7836 r8215  
    88from django import http 
    99from django.core import signals 
    10 from django.core.handlers.base import BaseHandler 
     10from django.core.handlers import base 
     11from django.core.urlresolvers import set_script_prefix 
    1112from django.dispatch import dispatcher 
    1213from django.utils import datastructures 
     
    7576class WSGIRequest(http.HttpRequest): 
    7677    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'/' 
    7786        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) 
    7989        self.META = environ 
     90        self.META['PATH_INFO'] = path_info 
     91        self.META['SCRIPT_NAME'] = script_name 
    8092        self.method = environ['REQUEST_METHOD'].upper() 
    8193 
     
    179191    raw_post_data = property(_get_raw_post_data) 
    180192 
    181 class WSGIHandler(BaseHandler): 
     193class WSGIHandler(base.BaseHandler): 
    182194    initLock = Lock() 
    183195    request_class = WSGIRequest 
     
    195207            self.initLock.release() 
    196208 
     209        set_script_prefix(base.get_script_name(environ)) 
    197210        dispatcher.send(signal=signals.request_started) 
    198211        try: