1# Copyright (C) 2018 Philipp Hörist <philipp AT hoerist.com> 2# 3# This file is part of nbxmpp. 4# 5# This program is free software; you can redistribute it and/or 6# modify it under the terms of the GNU General Public License 7# as published by the Free Software Foundation; either version 3 8# of the License, or (at your option) any later version. 9# 10# This program 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 this program; If not, see <http://www.gnu.org/licenses/>. 17 18import logging 19 20from nbxmpp.util import LogAdapter 21 22 23class BaseModule: 24 25 _depends = {} 26 27 def __init__(self, client): 28 logger_name = 'nbxmpp.m.%s' % self.__class__.__name__.lower() 29 self._log = LogAdapter(logging.getLogger(logger_name), 30 {'context': client.log_context}) 31 32 def __getattr__(self, name): 33 if name not in self._depends: 34 raise AttributeError('Unknown method: %s' % name) 35 36 module = self._client.get_module(self._depends[name]) 37 return getattr(module, name) 38