1# Copyright 2016 Free Software Foundation, Inc. 2# This file is part of GNU Radio 3# 4# GNU Radio Companion is free software; you can redistribute it and/or 5# modify it under the terms of the GNU General Public License 6# as published by the Free Software Foundation; either version 2 7# of the License, or (at your option) any later version. 8# 9# GNU Radio Companion is distributed in the hope that it will be useful, 10# but WITHOUT ANY WARRANTY; without even the implied warranty of 11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12# GNU General Public License for more details. 13# 14# You should have received a copy of the GNU General Public License 15# along with this program; if not, write to the Free Software 16# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 17 18import functools 19 20 21class lazy_property(object): 22 23 def __init__(self, func): 24 self.func = func 25 functools.update_wrapper(self, func) 26 27 def __get__(self, instance, owner): 28 if instance is None: 29 return self 30 value = self.func(instance) 31 setattr(instance, self.func.__name__, value) 32 return value 33 34 35def nop_write(prop): 36 """Make this a property with a nop setter""" 37 def nop(self, value): 38 pass 39 return prop.setter(nop) 40