root/masterdriverz/snakeoil-formatters/snakeoil/descriptors.py @ ferringb%2540gmail.com-20070211125906-1gj7u78ll14fnaut

Revision ferringb%2540gmail.com-20070211125906-1gj7u78ll14fnaut, 0.6 kB (checked in by Brian Harring <ferringb@…>, 2 years ago)

fresh reimport, dropping history from pkgcore (no point in lugging around 10+ mb of unrelated bzr history)

Line 
1# Copyright: 2006 Marien Zwart <marienz@gentoo.org>
2# License: GPL2
3
4
5"""Classes implementing the descriptor protocol."""
6
7
8class classproperty(object):
9
10    """Like the builtin C{property} but takes a single classmethod.
11
12    Used like this:
13
14    class Example(object):
15
16        @classproperty
17        def test(cls):
18            # Do stuff with cls here (it is Example or a subclass).
19
20    Now both C{Example.test} and C{Example().test} invoke the getter.
21    A "normal" property only works on instances.
22    """
23
24    def __init__(self, getter):
25        self.getter = getter
26
27    def __get__(self, instance, owner):
28        return self.getter(owner)
Note: See TracBrowser for help on using the browser.