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

Changeset 1108

Show
Ignore:
Timestamp:
05/11/06 02:49:04
Author:
fumanchu
Message:

New tree.app.guess_abs_path method.

Files:

Legend:

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

    r1106 r1108  
    1414    def merge(self, conf): 
    1515        config.merge(self.conf, conf) 
     16     
     17    def guess_abs_path(self): 
     18        """Guess the absolute URL from server.socket_host and script_name. 
     19         
     20        When inside a request, the abs_path can be formed via: 
     21            cherrypy.request.base + (cherrypy.request.app.script_name or "/") 
     22         
     23        However, outside of the request we must guess, hoping the deployer 
     24        set socket_host and socket_port correctly. 
     25        """ 
     26        port = int(config.get('server.socket_port', 80)) 
     27        if port in (443, 8443): 
     28            scheme = "https://" 
     29        else: 
     30            scheme = "http://" 
     31        host = config.get('server.socket_host', '') 
     32        if port != 80: 
     33            host += ":%s" % port 
     34        return scheme + host + self.script_name 
    1635 
    1736 

Hosted by WebFaction

Log in as guest/cpguest to create tickets