"Fossies" - the Fresh Open Source Software Archive

Member "LinOTP-release-2.10.5.2/linotpd/src/linotp/lib/module_loader.py" (13 May 2019, 1470 Bytes) of package /linux/misc/LinOTP-release-2.10.5.2.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Python source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. For more information about "module_loader.py" see the Fossies "Dox" file reference documentation.

    1 # -*- coding: utf-8 -*-
    2 #
    3 #    LinOTP - the open source solution for two factor authentication
    4 #    Copyright (C) 2010 - 2019 KeyIdentity GmbH
    5 #
    6 #    This file is part of LinOTP server.
    7 #
    8 #    This program is free software: you can redistribute it and/or
    9 #    modify it under the terms of the GNU Affero General Public
   10 #    License, version 3, as published by the Free Software Foundation.
   11 #
   12 #    This program is distributed in the hope that it will be useful,
   13 #    but WITHOUT ANY WARRANTY; without even the implied warranty of
   14 #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   15 #    GNU Affero General Public License for more details.
   16 #
   17 #    You should have received a copy of the
   18 #               GNU Affero General Public License
   19 #    along with this program.  If not, see <http://www.gnu.org/licenses/>.
   20 #
   21 #
   22 #    E-mail: linotp@keyidentity.com
   23 #    Contact: www.linotp.org
   24 #    Support: www.keyidentity.com
   25 #
   26 """ contains utility functions to load dynamic modules """
   27 
   28 
   29 import importlib
   30 import pkgutil
   31 import sys
   32 
   33 
   34 def import_submodules(package_name):
   35     """ Import all submodules of a module, recursively
   36 
   37     :param package_name: Package name
   38     :type package_name: str
   39     :rtype: dict[types.ModuleType]
   40     """
   41     package = sys.modules[package_name]
   42     p_list = {}
   43     for _loader, name, _is_pkg in pkgutil.walk_packages(package.__path__):
   44         p_list[name] = importlib.import_module(package_name + '.' + name)
   45 
   46     return p_list
   47 
   48 # eof #