U
    L¬÷dµ	  ã                   @   s–   d dl Z d dlmZ d dlmZmZ d dlmZ eedœdd„Z	deeee  e
dœd	d
„Zeee dœdd„Zdeee eee  edœdd„ZdS )é    N)Ú
ModuleType)ÚOptionalÚSequence)Úutil)Úmodule_nameÚreturnc                 C   s
   t  | ¡S )N)Ú	importlibÚimport_module)r   © r
   ú4/usr/lib/python3/dist-packages/cloudinit/importer.pyr	      s    r	   )r   Úattrsr   c                 C   s6   d}|s|S t  | ¡}|D ]}t||ƒr|d7 }q|S )Nr   é   )r   r	   Úhasattr)r   r   Zfound_attrsÚmodÚattrr
   r
   r   Ú_count_attrs   s    


r   )Úmod_namer   c                 C   sŒ   d|   ¡ kr| dd… } |  d¡s,d| › } i }tj d¡}|rˆ|jrˆ|jD ]}| t |¡¡ qL| ¡ D ]}|  ¡ |   ¡ krj|  S qj| S )zECheck the importable datasource modules for a case-insensitive match.znocloud-netNéüÿÿÿZ
DataSourcezcloudinit.sources)	ÚlowerÚ
startswithr   r   Ú	find_specÚsubmodule_search_locationsÚupdateZget_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   sj   |sg }g }g }|D ]L}d  td|| gƒ¡}| |¡ tj |¡sDqt||ƒt|ƒkr| |¡ q||fS )zFinds specified modulesÚ.N)ÚjoinÚfilterÚappendr   r   r   r   Úlen)r   r    r!   Zlookup_pathsZfound_pathsÚpathÚ	full_pathr
   r
   r   Úfind_module7   s    
r)   )N)N)r   Útypesr   Útypingr   r   Z	cloudinitr   Ústrr	   Úintr   r   Útupler)   r
   r
   r
   r   Ú<module>   s$    ÿ 
þ ý
ü