Package mvpa :: Package misc :: Module vproperty

[hide private]
[frames] | no frames]

# Source Code for Module mvpa.misc.vproperty

     1  # emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*-
     2  # vi: set ft=python sts=4 ts=4 sw=4 et:
     3  ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ##
     4  #
     5  #   See COPYING file distributed along with the PyMVPA package for the
     6  #   copyright and license terms.
     7  #
     8  ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ##
     9  """C++-like virtual properties"""
    10
    11  __docformat__ = 'restructuredtext'
    12
    13
    14 -class VProperty(object):
    15      """Provides "virtual" property: uses derived class's method
    16      """
    17
    18 -    def __init__(self, fget=None, fset=None, fdel=None, doc=''):
    19          for attr in ('fget', 'fset'):
    20              func = locals()[attr]
    21              if callable(func):
    22                  setattr(self, attr, func.func_name)
    23          setattr(self, '__doc__', doc)
    24
    25 -    def __get__(self, obj=None, type=None):
    26          if not obj:
    27              return 'property'
    28          if self.fget:
    29              return getattr(obj, self.fget)()
    30
    31 -    def __set__(self, obj, arg):
    32          if self.fset:
    33              return getattr(obj, self.fset)(arg)
    34