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

Changeset 1605

Show
Ignore:
Timestamp:
01/26/07 21:54:19
Author:
fumanchu
Message:

Docstrings, plus Application now copies its cls.namespaces into self.namespaces.

Files:

Legend:

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

    r1590 r1605  
    5252        index.exposed = True 
    5353        index._cp_config = {'request.show_tracebacks': False} 
     54 
     55Note, however, that this behavior is only guaranteed for the default 
     56dispatcher. Other dispatchers may have different restrictions on where 
     57you can attach _cp_config attributes. 
    5458 
    5559 
     
    7074                These can only be declared in the global config. 
    7175    tools:      Runs and configures additional request-processing packages. 
     76    wsgi:       Adds WSGI middleware to an Application's "pipeline". 
     77                These can only be declared in the app's root config ("/"). 
    7278    checker:    Controls the 'checker', which looks for common errors in 
    7379                app state (including config) when the engine starts. 
     
    8288or Request level, by adding a named handler to cherrypy.config.namespaces, 
    8389app.namespaces, or cherrypy.engine.request_class.namespaces. The name can 
    84 be any string, and the handler must be either a callable or a context 
    85 manager. 
     90be any string, and the handler must be either a callable or a (Python 2.5 
     91style) context manager. 
    8692""" 
    8793 
  • trunk/cherrypy/_cpdispatch.py

    r1604 r1605  
    4949 
    5050class Dispatcher(object): 
     51    """CherryPy Dispatcher which walks a tree of objects to find a handler. 
     52     
     53    The tree is rooted at cherrypy.request.app.root, and each hierarchical 
     54    component in the path_info argument is matched to a corresponding nested 
     55    attribute of the root object. Matching handlers must have an 'exposed' 
     56    attribute which evaluates to True. The special method name "index" 
     57    matches a URI which ends in a slash ("/"). The special method name 
     58    "default" may match a portion of the path_info (but only when no longer 
     59    substring of the path_info matches some other object). 
     60     
     61    This is the default, built-in dispatcher for CherryPy. 
     62    """ 
    5163     
    5264    def __call__(self, path_info): 
  • trunk/cherrypy/_cptree.py

    r1458 r1605  
    1111    An instance of this class may also be used as a WSGI callable 
    1212    (WSGI application object) for itself. 
     13    """ 
    1314     
    14     root: the top-most container of page handlers for this app. 
    15     script_name: the URL "mount point" for this app; for example, 
    16         if script_name is "/my/cool/app", then the URL 
    17         "http://my.domain.tld/my/cool/app/page1" might be handled 
    18         by a "page1" method on the root object. If script_name is 
    19         explicitly set to None, then CherryPy will attempt to provide 
    20         it each time from request.wsgi_environ['SCRIPT_NAME']. 
    21     config: a dict of {path: pathconf} pairs, where 'pathconf' is itself 
    22         a dict of {key: value} pairs. 
     15    __metaclass__ = cherrypy._AttributeDocstrings 
     16     
     17    root = None 
     18    root__doc = """ 
     19    The top-most container of page handlers for this app. Handlers should 
     20    be arranged in a hierarchy of attributes, matching the expected URI 
     21    hierarchy; the default dispatcher then searches this hierarchy for a 
     22    matching handler. When using a dispatcher other than the default, 
     23    this value may be None.""" 
     24     
     25    config = {} 
     26    config__doc = """ 
     27    A dict of {path: pathconf} pairs, where 'pathconf' is itself a dict 
     28    of {key: value} pairs.""" 
     29     
     30    namespaces = {} 
     31    namespaces__doc = """ 
     32    A dict of config namespace names and handlers. Each config entry should 
     33    begin with a namespace name; the corresponding namespace handler will 
     34    be called once for each config entry in that namespace, and will be 
     35    passed two arguments: the config key (with the namespace removed) 
     36    and the config value. 
     37     
     38    Namespace handlers may be any Python callable; they may also be 
     39    Python 2.5-style 'context managers', in which case their __enter__ 
     40    method should return a callable to be used as the handler. 
     41    See cherrypy.tools (the Toolbox class) for an example. 
    2342    """ 
     43     
     44    log = None 
     45    log__doc = """A LogManager instance. See _cplogging.""" 
     46     
     47    wsgiapp = None 
     48    wsgiapp__doc = """A CPWSGIApp instance. See _cpwsgi.""" 
    2449     
    2550    def __init__(self, root, script_name=""): 
     
    2853        self.script_name = script_name 
    2954        self.wsgiapp = _cpwsgi.CPWSGIApp(self) 
    30         self.namespaces = {"log": lambda k, v: setattr(self.log, k, v), 
    31                            "wsgi": self.wsgiapp.namespace_handler, 
    32                            } 
     55         
     56        self.namespaces = self.namespaces.copy() 
     57        self.namespaces["log"] = lambda k, v: setattr(self.log, k, v) 
     58        self.namespaces["wsgi"] = self.wsgiapp.namespace_handler 
     59         
    3360        self.config = {} 
    3461     
     62    script_name__doc = """ 
     63    The URI "mount point" for this app; for example, if script_name is 
     64    "/my/cool/app", then the URL "http://my.domain.tld/my/cool/app/page1" 
     65    might be handled by a "page1" method on the root object. If script_name 
     66    is explicitly set to None, then the script_name will be provided 
     67    for each call from request.wsgi_environ['SCRIPT_NAME'].""" 
    3568    def _get_script_name(self): 
    3669        if self._script_name is None: 
     
    4073    def _set_script_name(self, value): 
    4174        self._script_name = value 
    42     script_name = property(fget=_get_script_name, fset=_set_script_name) 
     75    script_name = property(fget=_get_script_name, fset=_set_script_name, 
     76                           doc=script_name__doc) 
    4377     
    4478    def merge(self, config): 
     
    5993    (WSGI application object), in which case it dispatches to all 
    6094    mounted apps. 
     95    """ 
    6196     
    62     apps: a dict of the form {script name: application}, where "script name" 
    63         is a string declaring the URL mount point (no trailing slash), 
    64         and "application" is an instance of cherrypy.Application (or an 
    65         arbitrary WSGI callable if you happen to be using a WSGI server). 
    66     """ 
     97    apps = {} 
     98    apps__doc = """ 
     99    A dict of the form {script name: application}, where "script name" 
     100    is a string declaring the URI mount point (no trailing slash), and 
     101    "application" is an instance of cherrypy.Application (or an arbitrary 
     102    WSGI callable if you happen to be using a WSGI server).""" 
    67103     
    68104    def __init__(self): 

Hosted by WebFaction

Log in as guest/cpguest to create tickets