pytilities.attributecollection

Package pytilities :: Module attributecollection |
[hide private]
[frames] | no frames]

# Source Code for Module pytilities.attributecollection

     1  # Copyright (C) 2010 Tim Diels <limyreth@users.sourceforge.net>
     2  #
     3  # This file is part of pytilities.
     4  #
     5  # pytilities is free software: you can redistribute it and/or modify
     6  # it under the terms of the GNU General Public License as published by
     7  # the Free Software Foundation, either version 3 of the License, or
     8  # (at your option) any later version.
     9  #
    10  # pytilities is distributed in the hope that it will be useful,
    11  # but WITHOUT ANY WARRANTY; without even the implied warranty of
    12  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    13  # GNU General Public License for more details.
    14  #
    15  # You should have received a copy of the GNU General Public License
    16  # along with pytilities.  If not, see <http://www.gnu.org/licenses/>.
    17  #
    18
    19  __docformat__ = 'reStructuredText'
    20
    21 -class AttributeCollection(object):
    22      """
    23      Abstract, represents a collection of attributes.
    24
    25      Attribute collections can represent infinite amounts of attributes,
    26      generate them at request, ...
    27
    28      Methods:
    29
    30          - `getattr_`: Try to get the value of an attribute
    31          - `setattr_`: Try to set the value of an attribute
    32          - `delattr_`: Try to delete an attribute
    33      """
    34
    35      # Note: we use an error code return as this is faster than spawning
    36      # exceptions and this may happen quite often, rather than exceptionally
    37 -    def getattr_(self, name):
    38          """
    39          Try to get the value of an attribute
    40
    41          Parameters:
    42
    43              `name` :: string
    44                  name of the attribute to get
    45
    46          Returns whether the attribute was found, and if so, its value
    47          :: (found_attribute::bool, value)
    48          """
    49          raise NotImplementedError('abstract')
    50
    51 -    def setattr_(self, name, value):
    52          """
    53          Try to set the value of an attribute
    54
    55          Parameters:
    56
    57              `name` :: string
    58                  name of the attribute to set
    59
    60              `value`
    61                  the new value
    62
    63          Returns True, if the attribute was found, False otherwise
    64          """
    65          raise NotImplementedError('abstract')
    66
    67 -    def delattr_(self, name):
    68          """
    69          Try to delete an attribute
    70
    71          Parameters:
    72
    73              `name` :: string
    74                  name of the attribute to delete
    75
    76          Returns True, if the attribute was found, False otherwise
    77          """
    78          raise NotImplementedError('abstract')
    79