]>
git.proxmox.com Git - mirror_edk2.git/blob - BaseTools/Source/Python/Common/caching.py
2 # help with caching in BaseTools
4 # Copyright (c) 2018, Intel Corporation. All rights reserved.<BR>
6 # This program and the accompanying materials
7 # are licensed and made available under the terms and conditions of the BSD License
8 # which accompanies this distribution. The full text of the license may be found at
9 # http://opensource.org/licenses/bsd-license.php
11 # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
19 class cached_class_function(object):
20 def __init__(self
, function
):
21 self
._function
= function
22 def __get__(self
, obj
, cls
):
23 def CallMeHere(*args
,**kwargs
):
24 Value
= self
._function
(obj
, *args
,**kwargs
)
25 obj
.__dict
__[self
._function
.__name
__] = lambda *args
,**kwargs
:Value
30 class cached_property(object):
31 def __init__(self
, function
):
32 self
._function
= function
33 def __get__(self
, obj
, cls
):
34 Value
= obj
.__dict
__[self
._function
.__name
__] = self
._function
(obj
)
37 # for non-class function
38 class cached_basic_function(object):
39 def __init__(self
, function
):
40 self
._function
= function
41 # wrapper to call _do since <class>.__dict__ doesn't support changing __call__
42 def __call__(self
,*args
,**kwargs
):
43 return self
._do
(*args
,**kwargs
)
44 def _do(self
,*args
,**kwargs
):
45 Value
= self
._function
(*args
,**kwargs
)
46 self
.__dict
__['_do'] = lambda self
,*args
,**kwargs
:Value