diff options
| author | kx <kx@radix.pro> | 2024-06-04 06:43:08 +0300 |
|---|---|---|
| committer | kx <kx@radix.pro> | 2024-06-04 06:43:08 +0300 |
| commit | 7e2ccccace24636f29ddc210b94606abd4c7e42b (patch) | |
| tree | 545d43ea12671048956cafeb12303e84d601e571 /BaseTools/Source/Python/Common/caching.py | |
| parent | 27b044605cd5f6b33a3d231576003850b3fe305b (diff) | |
| download | edk2-trunk.tar.xz | |
Renormalized end-of-lines from master@27b044605cd5f6b33a3d231576003850b3fe305btrunk
Diffstat (limited to 'BaseTools/Source/Python/Common/caching.py')
| -rw-r--r-- | BaseTools/Source/Python/Common/caching.py | 82 |
1 files changed, 41 insertions, 41 deletions
diff --git a/BaseTools/Source/Python/Common/caching.py b/BaseTools/Source/Python/Common/caching.py index fda30f7321..681740c1f6 100644 --- a/BaseTools/Source/Python/Common/caching.py +++ b/BaseTools/Source/Python/Common/caching.py @@ -1,41 +1,41 @@ -## @file
-# help with caching in BaseTools
-#
-# Copyright (c) 2018, Intel Corporation. All rights reserved.<BR>
-#
-# SPDX-License-Identifier: BSD-2-Clause-Patent
-#
-
-## Import Modules
-#
-
-# for class function
-class cached_class_function(object):
- def __init__(self, function):
- self._function = function
- def __get__(self, obj, cls):
- def CallMeHere(*args,**kwargs):
- Value = self._function(obj, *args,**kwargs)
- obj.__dict__[self._function.__name__] = lambda *args,**kwargs:Value
- return Value
- return CallMeHere
-
-# for class property
-class cached_property(object):
- def __init__(self, function):
- self._function = function
- def __get__(self, obj, cls):
- Value = obj.__dict__[self._function.__name__] = self._function(obj)
- return Value
-
-# for non-class function
-class cached_basic_function(object):
- def __init__(self, function):
- self._function = function
- # wrapper to call _do since <class>.__dict__ doesn't support changing __call__
- def __call__(self,*args,**kwargs):
- return self._do(*args,**kwargs)
- def _do(self,*args,**kwargs):
- Value = self._function(*args,**kwargs)
- self.__dict__['_do'] = lambda self,*args,**kwargs:Value
- return Value
+## @file +# help with caching in BaseTools +# +# Copyright (c) 2018, Intel Corporation. All rights reserved.<BR> +# +# SPDX-License-Identifier: BSD-2-Clause-Patent +# + +## Import Modules +# + +# for class function +class cached_class_function(object): + def __init__(self, function): + self._function = function + def __get__(self, obj, cls): + def CallMeHere(*args,**kwargs): + Value = self._function(obj, *args,**kwargs) + obj.__dict__[self._function.__name__] = lambda *args,**kwargs:Value + return Value + return CallMeHere + +# for class property +class cached_property(object): + def __init__(self, function): + self._function = function + def __get__(self, obj, cls): + Value = obj.__dict__[self._function.__name__] = self._function(obj) + return Value + +# for non-class function +class cached_basic_function(object): + def __init__(self, function): + self._function = function + # wrapper to call _do since <class>.__dict__ doesn't support changing __call__ + def __call__(self,*args,**kwargs): + return self._do(*args,**kwargs) + def _do(self,*args,**kwargs): + Value = self._function(*args,**kwargs) + self.__dict__['_do'] = lambda self,*args,**kwargs:Value + return Value |
