Download Install Tutorial Docs FAQ Tools WikiLicense Team IRC Planet Involvement Shop Book

Changeset 1106

Show
Ignore:
Timestamp:
05/11/06 00:48:22
Author:
fumanchu
Message:

Made tree.Application.script_name, and it now defaults to "", not "/".

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/cherrypy/_cprequest.py

    r1102 r1106  
    214214                msg = "HTTP/1.1 requires a 'Host' request header." 
    215215                raise cherrypy.HTTPError(400, msg) 
    216         self.base = "%s://%s" % (self.scheme, self.headers.get('Host', '')) 
     216         
     217        host = self.headers.get('Host', '') 
     218        if not host: 
     219            host = cherrypy.config.get('server.socket_host', '') 
     220        self.base = "%s://%s" % (self.scheme, host) 
    217221     
    218222    def get_resource(self, path): 
  • trunk/cherrypy/_cptree.py

    r1105 r1106  
    55class Application: 
    66     
    7     def __init__(self, root, conf=None): 
     7    def __init__(self, root, script_name="", conf=None): 
    88        self.root = root 
     9        self.script_name = script_name 
    910        self.conf = {} 
    1011        if conf: 
     
    2122        self.apps = {} 
    2223     
    23     def mount(self, root, script_name=None, conf=None): 
     24    def mount(self, root, script_name="", conf=None): 
    2425        """Mount a new app from a root object, script_name, and conf.""" 
    25         app = Application(root, conf) 
    26         if script_name is None: 
    27             script_name = "/" 
     26        if script_name == "/": 
     27            script_name = "" 
     28        app = Application(root, script_name, conf) 
    2829        self.apps[script_name] = app 
    2930        return app 
     
    4243                return None 
    4344         
    44         while path
     45        while True
    4546            if path in self.apps: 
    4647                return path 
    4748             
     49            if path == "": 
     50                return None 
     51             
    4852            # Move one node up the tree and try again. 
    49             if path == "/": 
    50                 break 
    51             path = path[:path.rfind("/")] or "/" 
    52          
    53         return None 
     53            path = path[:path.rfind("/")] 
    5454     
    5555    def url(self, path, script_name=None): 
  • trunk/cherrypy/_cpwsgi.py

    r1100 r1106  
    188188            bind_addr = (conf('server.socket_host'), conf('server.socket_port')) 
    189189         
    190         apps = [] 
    191         for base in cherrypy.tree.apps: 
    192             if base == "/": 
    193                 base = "" 
    194             apps.append((base, wsgiApp)) 
     190        apps = [(base, wsgiApp) for base in cherrypy.tree.apps] 
    195191         
    196192        s = _cpwsgiserver.CherryPyWSGIServer 
  • trunk/cherrypy/lib/cptools.py

    r1102 r1106  
    181181 
    182182def base_url(base=None, use_x_forwarded_host=True): 
    183     """Change the base URL
     183    """Change the base URL (scheme://host[:port])
    184184     
    185185    Useful when running a CP server behind Apache. 
  • trunk/cherrypy/lib/httptools.py

    r1102 r1106  
    312312    # path may be an abs_path (including "http://host.domain.tld"); 
    313313    # Ignore scheme, location, and fragments (so config lookups work). 
    314     # [Therefore, this assumes all hosts are valid for this server.] 
     314    # [Therefore, this assumes all hosts are valid for this server. 
     315    # Note that we are also violating the RFC which says: if the host 
     316    # given in an abs_path, it must override any Host header.] 
    315317    scheme, location, path, params, qs, frag = urlparse(path) 
    316318    if path == "*": 
  • trunk/cherrypy/test/test_objectmapping.py

    r1096 r1106  
    55 
    66 
    7 script_names = ["/", "/users/fred/blog", "/corp/blog"] 
     7script_names = ["", "/users/fred/blog", "/corp/blog"] 
    88 
    99def setup_server(): 
     
    114114     
    115115    for url in script_names: 
    116         conf = {'user': url.split("/")[-2]} 
     116        conf = {'user': (url or "/").split("/")[-2]} 
    117117        cherrypy.tree.mount(Root(), url, {'/': conf}) 
    118118     
     
    199199            # Test that configs don't overwrite each other from diferent apps 
    200200            self.getPage("/confvalue") 
    201             self.assertBody(url.split("/")[-2]) 
     201            self.assertBody((url or "/").split("/")[-2]) 
    202202         
    203203        self.script_name = "" 
  • trunk/cherrypy/test/test_tutorials.py

    r1096 r1106  
    2222        else: 
    2323            module = __import__(target, globals(), locals(), ['']) 
    24         # The above import will probably mount a new app at "/". 
    25         app = cherrypy.tree.apps["/"] 
     24        # The above import will probably mount a new app at "". 
     25        app = cherrypy.tree.apps[""] 
    2626         
    2727        app.root.load_tut_module = load_tut_module 

Hosted by WebFaction

Log in as guest/cpguest to create tickets