3 \�me� � @ s� d dl Z d dlmZ d dlmZmZ d dlmZ eed�dd�Z deeee e d�d d �Zeee d�dd �Zdeee eee e d�dd�ZdS )� N)� ModuleType)�Optional�Sequence)�util)�module_name�returnc C s t j| �S )N)� importlib� import_module)r � r �/usr/lib/python3.6/importer.pyr s r )r �attrsr c C s: d}|s|S t j| �}x|D ]}t||�r|d7 }qW |S )Nr � )r r �hasattr)r r Zfound_attrs�mod�attrr r r �_count_attrs s r )�mod_namer c C s� d| j � kr| dd� } | jd�s,d| � �} i }tjjd�}|r�|jr�x|jD ]}|jtj|�� qNW x$|j� D ]}|j � | j � krp|S qpW | S )zECheck the importable datasource modules for a case-insensitive match.znocloud-netN� Z DataSourcezcloudinit.sources���) �lower� startswithr r � find_spec�submodule_search_locations�updateZget_modules_from_dir�values)r �modules�spec�dir�moduler r r �"match_case_insensitive_module_name# s r )� base_name�search_paths�required_attrsr c C sn |sg }g }g }xT|D ]L}dj td|| g��}|j|� tjj|�sFqt||�t|�kr|j|� qW ||fS )zFinds specified modules�.N)�join�filter�appendr r r r �len)r r! r"