Django

Code

Changeset 7991

Show
Ignore:
Timestamp:
07/19/08 14:32:01 (4 months ago)
Author:
mtredinnick
Message:

First part of setting request.path correctly.

Still needs:

  • testing
  • docs changes
  • some way of fixing reverse().
Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/django/core/handlers/base.py

    r7988 r7991  
    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 
     
    171173        return response 
    172174 
     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). 
     181 
     182    Note: this isn't used by the mod_python handler, since the equivalent of 
     183    SCRIPT_NAME isn't available there. 
     184    """ 
     185    # If mod_rewrite had a whack at the URL, Apache set SCRIPT_URL to 
     186    # SCRIPT_NAME before applying any rewrites. 
     187    script_url = force_unicode(environ.get('SCRIPT_URL', '')) 
     188    if script_url: 
     189        return script_url 
     190    return force_unicode(environ.get('SCRIPT_NAME', '')) 
     191 
  • django/trunk/django/core/handlers/modpython.py

    r7814 r7991  
    1717        self._req = req 
    1818        self.path = force_unicode(req.uri) 
     19        root = req.get_options().get('django.root', '') 
     20        self._django_root = root 
     21        # req.path_info isn't necessarily computed correctly in all 
     22        # circumstances (it's out of mod_python's control a bit), so we use 
     23        # req.uri and some string manipulations to get the right value. 
     24        if root and req.uri.startswith(root): 
     25            self.path_info = force_unicode(req.uri[len(root):]) 
     26        else: 
     27            self.path_info = self.path 
    1928 
    2029    def __repr__(self): 
     
    101110                'CONTENT_TYPE':      self._req.content_type, # This may be wrong 
    102111                'GATEWAY_INTERFACE': 'CGI/1.1', 
    103                 'PATH_INFO':         self._req.path_info, 
     112                'PATH_INFO':         self.path_info, 
    104113                'PATH_TRANSLATED':   None, # Not supported 
    105114                'QUERY_STRING':      self._req.args, 
     
    109118                'REMOTE_USER':       self._req.user, 
    110119                'REQUEST_METHOD':    self._req.method, 
    111                 'SCRIPT_NAME':       None, # Not supported 
     120                'SCRIPT_NAME':       self._django_root, 
    112121                'SERVER_NAME':       self._req.server.server_hostname, 
    113122                'SERVER_PORT':       self._req.server.port, 
  • django/trunk/django/core/handlers/wsgi.py

    r7814 r7991  
    88from django import http 
    99from django.core import signals 
    10 from django.core.handlers.base import BaseHandler 
     10from django.core.handlers import base 
    1111from django.dispatch import dispatcher 
    1212from django.utils import datastructures 
     
    7575class WSGIRequest(http.HttpRequest): 
    7676    def __init__(self, environ): 
     77        script_name = base.get_script_name() 
     78        path_info = force_unicode(environ.get('PATH_INFO', '/')) 
    7779        self.environ = environ 
    78         self.path = force_unicode(environ['PATH_INFO']) 
     80        self.path_info = path_info 
     81        self.path = '%s%s' % (script_name, path_info) 
    7982        self.META = environ 
     83        self.META['PATH_INFO'] = path_info 
     84        self.META['SCRIPT_NAME'] = script_name 
    8085        self.method = environ['REQUEST_METHOD'].upper() 
    8186 
     
    179184    raw_post_data = property(_get_raw_post_data) 
    180185 
    181 class WSGIHandler(BaseHandler): 
     186class WSGIHandler(base.BaseHandler): 
    182187    initLock = Lock() 
    183188    request_class = WSGIRequest 
  • django/trunk/django/core/urlresolvers.py

    r7805 r7991  
    292292    return get_resolver(urlconf).resolve(path) 
    293293 
    294 def reverse(viewname, urlconf=None, args=None, kwargs=None): 
     294def reverse(viewname, urlconf=None, args=None, kwargs=None, prefix=u'/'): 
    295295    args = args or [] 
    296296    kwargs = kwargs or {} 
    297     return iri_to_uri(u'/' + get_resolver(urlconf).reverse(viewname, *args, **kwargs)) 
     297    return iri_to_uri(prefix + 
     298            get_resolver(urlconf).reverse(viewname, *args, **kwargs)) 
    298299 
    299300def clear_url_caches(): 
  • django/trunk/django/http/__init__.py

    r7814 r7991  
    3232        self.GET, self.POST, self.COOKIES, self.META, self.FILES = {}, {}, {}, {}, {} 
    3333        self.path = '' 
     34        self.path_info = '' 
    3435        self.method = None 
    3536 
     
    443444    else: 
    444445        return s 
     446 
  • django/trunk/django/test/client.py

    r7858 r7991  
    191191            'QUERY_STRING':      '', 
    192192            'REQUEST_METHOD':    'GET', 
    193             'SCRIPT_NAME':       None
     193            'SCRIPT_NAME':       ''
    194194            'SERVER_NAME':       'testserver', 
    195195            'SERVER_PORT':       80,