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

Changeset 1093

Show
Ignore:
Timestamp:
05/07/06 00:52:18
Author:
fumanchu
Message:

New cherrypy.set_config(**kwargs) decorator for setting _cp_config on a method. Also better errors on lookup of request attrs when not in a request.

Files:

Legend:

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

    r1092 r1093  
    33__version__ = '3.0.0alpha' 
    44 
    5 import datetime 
    65import sys 
    76import types 
     
    2827    from cherrypy._cpthreadinglocal import local 
    2928 
    30 # Create a threadlocal object to hold the request and response 
    31 # objects. In this way, we can easily dump those objects when 
    32 # we stop/start a new HTTP conversation, yet still refer to 
    33 # them as module-level globals in a thread-safe way. 
     29# Create a threadlocal object to hold the request, response, and other 
     30# objects. In this way, we can easily dump those objects when we stop/start 
     31# a new HTTP conversation, yet still refer to them as module-level globals 
     32# in a thread-safe way. 
    3433serving = local() 
    3534 
     
    4039     
    4140    def __getattr__(self, name): 
    42         childobject = getattr(serving, self.__attrname__) 
     41        try: 
     42            childobject = getattr(serving, self.__attrname__) 
     43        except AttributeError: 
     44            raise AttributeError("cherrypy.%s has no properties outside of " 
     45                                 "an HTTP request." % self.__attrname__) 
    4346        return getattr(childobject, name) 
    4447     
    4548    def __setattr__(self, name, value): 
    46         childobject = getattr(serving, self.__attrname__) 
     49        try: 
     50            childobject = getattr(serving, self.__attrname__) 
     51        except AttributeError: 
     52            raise AttributeError("cherrypy.%s has no properties outside of " 
     53                                 "an HTTP request." % self.__attrname__) 
    4754        setattr(childobject, name, value) 
    4855     
    4956    def __delattr__(self, name): 
    50         childobject = getattr(serving, self.__attrname__) 
     57        try: 
     58            childobject = getattr(serving, self.__attrname__) 
     59        except AttributeError: 
     60            raise AttributeError("cherrypy.%s has no properties outside of " 
     61                                 "an HTTP request." % self.__attrname__) 
    5162        delattr(childobject, name) 
    5263 
     
    8394        return expose_ 
    8495 
     96def set_config(**kwargs): 
     97    """Decorator to set _cp_config using the given kwargs.""" 
     98    def wrapper(f): 
     99        f._cp_config = kwargs 
     100        return f 
     101    return wrapper 
     102 
    85103def log(msg='', context='', severity=0, traceback=False): 
    86104    """Syntactic sugar for writing to the (error) log.""" 

Hosted by WebFaction

Log in as guest/cpguest to create tickets