l#g- dZddlZddlZddlZddlZddlZddlZddlmZddl m Z m Z m Z ej eZdede eefddfd Zd e e eefde d fd ZddeddfdZddeddfdZdZdZdS)z> Provides utilities for dynamically loading packages/modules. N)Path) GeneratorListUnion module_name file_pathreturnmodulectj||}tj|}|j||S)z4 Execute and return module from *file_path* ) importlibutilspec_from_file_locationmodule_from_specloader exec_module)rrspecr s S/opt/imunify360/venv/lib/python3.11/site-packages/defence360agent/utils/importer.pyget_module_by_pathrsK > 1 1+y I ID ^ , ,T 2 2FKF### Mpaths)r NNc#Ktj|D]D}|js;t|jj|jdz }t|j|VEdS)z) Yields all modules from *paths* z.pyN)pkgutil iter_modulesispkgr module_finderpathnamer)rr rs rrrsr &u--88| 8,122 5H5H5HHD$V[$77 7 7 788rFrcR tj|}n#t$r|sYdSwxYwtj||j|jr<|}tj |j D]"}tj|d|j!dSdS)z Import *name* module, if *name* is a package import all submodules. If *name* module/package is not found: - raise ModuleNotFoundError if *missing_ok* is False - ignore it if *missing_ok* is True N.) r r find_specModuleNotFoundError import_moduler is_packagerrrsubmodule_search_locations)r missing_okrpackager s rloadr')s~''--    D!!! {di((@*4+JKK @ @F  #w$>$>$>$> ? ? ? ?@@ @ @s " 33packagesc2|D]}t||dS)N)r%)r')r(r%r&s r load_packagesr*>s1-- W,,,,,--rct tj|}n#t$r|cYSwxYwt|||S)zh Return object with *name* from specific *module*. If object was not found return *default* )r r"r!getattr)r rdefaultms rgetr/CsO   #F + +  1dG $ $$s  &&cn tj|}n#t$rYdSwxYw|duS)NF)r r r r!)rrs rexistsr1OsK~''-- uu t s " 00)F)__doc__r importlib.utilloggingosrsyspathlibrtypingrrr getLogger__name__loggerstrrrr'tupler*r/r1rrr?sy  ))))))))))  8 $ $  !&sDy!1       8 c4i ! 8#$ 8 8 8 8@@s@@@@@*--E----- % % %r