1# Copyright 2017 The Chromium OS Authors. All rights reserved. 2# Use of this source code is governed by a BSD-style license that can be 3# found in the LICENSE file. 4 5"""A common module for FAFT client.""" 6 7class LazyInitHandlerProxy: 8 """Proxy of a given handler_class for lazy initialization.""" 9 _loaded = False 10 _obj = None 11 12 def __init__(self, handler_class, *args, **kargs): 13 self._handler_class = handler_class 14 self._args = args 15 self._kargs = kargs 16 17 def _load(self): 18 self._obj = self._handler_class() 19 self._obj.init(*self._args, **self._kargs) 20 self._loaded = True 21 22 def __getattr__(self, name): 23 if not self._loaded: 24 self._load() 25 return getattr(self._obj, name) 26 27 def reload(self): 28 """Reload the handler class.""" 29 self._loaded = False 30