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

Changeset 117

Show
Ignore:
Timestamp:
01/04/05 04:16:12
Author:
cribeiro
Message:

Implemented the ExposeItems utility class. It was originally proposed as a workaround for #65. It allows to publish generic getitem-aware objects (such as lists and dicts) in such a way as not to mess up with the object mapping algorithm.

Files:

Legend:

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

    r8 r117  
     1""" 
     2CherryPy Standard Library 
     3""" 
     4 
     5class ExposeItems: 
     6    """ 
     7    Utility class that exposes a getitem-aware object. It does not provide 
     8    index() or default() methods, and it does not expose the individual item 
     9    objects - just the list or dict that contains them. User-specific index() 
     10    and default() methods can be implemented by inheriting from this class. 
     11     
     12    Use case: 
     13     
     14    from cherrypy.lib import ExposeItems 
     15    ... 
     16    cpg.root.foo = ExposeItems(mylist) 
     17    cpg.root.bar = ExposeItems(mydict) 
     18    """ 
     19    exposed = True 
     20    def __init__(self, items): 
     21        self.items = items 
     22    def __getattr__(self, key): 
     23        return self.items[key] 

Hosted by WebFaction

Log in as guest/cpguest to create tickets