| | 1 | """ |
|---|
| | 2 | CherryPy Standard Library |
|---|
| | 3 | """ |
|---|
| | 4 | |
|---|
| | 5 | class 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] |
|---|