Changeset 5286

Show
Ignore:
Timestamp:
08/28/08 09:15:30 (4 months ago)
Author:
mramm
Message:

Adding docstrings and cleaning up configuration.py

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/tg/configuration.py

    r5285 r5286  
    4343        return AttributeError 
    4444 
    45 class DictWrapper(dict): 
     45class PylonsConfigWrapper(dict): 
    4646    """Simple wrapper for the pylons config object that provides attribute  
    4747    style access to the pylons config dictionary. 
     
    100100        return get_partial_dict('pylons', self.config_proxy.current_conf()) 
    101101 
    102 config = DictWrapper(pylons_config) 
     102#Create a config object that has attribute style lookup built in.  
     103config = PylonsConfigWrapper(pylons_config) 
    103104 
    104105class Bunch(dict): 
     
    130131    that is NECESSARY for proper application function.   
    131132    Deployment specific configuration information should go in  
    132     the config files (eg: development.ini or production.ini)"  
     133    the config files (eg: development.ini or production.ini) 
     134     
     135    AppConfig instances have a number of methods that are meant to be  
     136    overridden by users who wish to have finer grained controll over  
     137    the setup of the WSGI envirnment in which their applcation is run.  
     138     
     139    This is the place to configure custom routes, transaction handling,  
     140    error handling, etc.  
    133141    """ 
    134142     
    135143    def __init__(self): 
     144        """Creates some configuration defaults""" 
     145         
     146        #Create a few bunches we know we'll use 
     147        self.paths = Bunch() 
     148        self.render_functions = Bunch() 
     149         
     150        #Set individual defaults 
    136151        self.stand_alone = True 
    137152        self.default_renderer = 'genshi' 
    138153        self.auth_backend = None 
    139154        self.serve_static = True 
    140         self.paths = Bunch() 
    141         self.render_functions = Bunch() 
     155        self.use_legacy_render = True 
     156 
    142157     
    143158    def setup_paths(self): 
     
    154169 
    155170    def init_config(self, global_conf, app_conf): 
    156         # Initialize config with the basic options 
     171        """Initialize the config object. 
     172         
     173        tg.config is a proxy for pylons.config that allows attribute style 
     174        access, so it's automatically setup when we create the poylons config 
     175         
     176        Besides basic initialization,  this method copies all the values  
     177        in base_config  into the ``tg.config`` object.  
     178        """ 
    157179        pylons_config.init_app(global_conf, app_conf,  
    158180                        package=self.package.__name__, 
     
    192214     
    193215    def setup_mako_renderer(self): 
    194         # Create the Mako TemplateLookup, with the default auto-escaping 
     216        """Setup a renderer and loader for mako templates""" 
    195217        from mako.lookup import TemplateLookup 
    196218        from tg.render import render_mako 
     
    206228         
    207229    def setup_genshi_renderer(self): 
    208         # Create the Genshi TemplateLoader 
     230        """Setup a renderer and loader for Genshi templates""" 
    209231        from genshi.template import TemplateLoader 
    210232        from tg.render import render_genshi 
     
    221243     
    222244    def setup_jinja_renderer(self): 
    223         # Create the Jinja Environment 
     245        """Setup a renderer and loader for Jinja templates""" 
    224246        from jinja import ChoiceLoader, Environment, FileSystemLoader 
    225247        from tg.render import render_jinja 
     
    233255     
    234256    def setup_default_renderer(self): 
     257        """Setup template defaults in the buffed plugin 
     258         
     259        This is only used when use_legacy_renderer is set to True 
     260         
     261        And it will not depricated in the next major turbogears  
     262        release. 
     263        """ 
    235264        #This is specific to buffet, will not be needed later 
    236265        config['buffet.template_engines'].pop() 
     
    240269     
    241270    def setup_sqlalchemy(self): 
    242         # Setup SQLAlchemy database engine 
     271        """Setup SQLAlchemy database engine""" 
    243272        from sqlalchemy import engine_from_config 
    244273        engine = engine_from_config(pylons_config, 'sqlalchemy.') 
     
    287316 
    288317    def add_error_middleware(self, global_conf, app): 
    289         # Handle Python exceptions 
     318        """Adds middleware which handles errors and exceptions""" 
    290319        app = ErrorHandler(app, global_conf, **config['pylons.errorware']) 
    291320 
     
    299328 
    300329    def add_auth_middleware(self, app): 
    301         # configure identity Middleware 
     330        """Configure authorization/authentication""" 
    302331        from tg.ext.repoze.who.middleware import make_who_middleware 
    303332 
     
    312341     
    313342    def add_core_middleware(self, app):     
     343        """Adds support for routes dispatch, sessions, and caching""" 
    314344        app = RoutesMiddleware(app, config['routes.map']) 
    315345        app = SessionMiddleware(app, config) 
     
    318348     
    319349    def add_tosca_middleware(self, app): 
     350        """Configure the ToscaWidgets middleware""" 
    320351        app = tw_middleware(app, { 
    321352            'toscawidgets.framework.default_view':  
     
    342373 
    343374    def add_tm_middleware(self, app): 
     375        """Sets up the transaction managment middleware 
     376         
     377        To abort a transaction inside a TG2 app:: 
     378         
     379          import transaction 
     380          transaction.doom() 
     381         
     382        By default http error responses also roll back transactions,  
     383        but this behavior can be overridden by overiding  
     384        base_config.commit_veto 
     385        """ 
    344386        from repoze.tm import make_tm 
    345387        return make_tm(app, self.commit_veto) 
    346388 
    347389    def add_dbsession_remover_middleware(self, app): 
     390        """Sets up middleware that cleans up the sqlalchmy session 
     391         
     392        The default behavior of TG2 is to clean up the session on  
     393        every request.  Only overide this method if you know what you 
     394        are doing! 
     395         
     396        """ 
    348397        def remover(environ, start_response): 
    349398            try: