U
    ?h°  ã                   @   sT   d Z ddlZddlZddlZej ej e¡¡ZdZ	dd„ Z
d
dd„Zddd	„ZdS )zG This module contains generic code to find and load a dynamic library.
é    NFc                 C   sJ   |   ¡ } tj d¡r|  d¡S tj d¡r4|  d¡S |  d¡pDd| kS dS )zƒReturns True if the given filename looks like a dynamic library.
    Based on extension, but cross-platform and more flexible.
    Úwinz.dllÚdarwinz.dylibz.soz.so.N)ÚlowerÚsysÚplatformÚ
startswithÚendswith)Úfname© r
   úF/var/www/html/venv/lib/python3.8/site-packages/imageio/core/findlib.pyÚ	looks_lib   s    

r   c              	      s.  |pg }ddddddg}ddd	d
dg}dd„ |D ƒ}t tdƒrP|dd„ |D ƒ7 }tj d¡‰ ‡ fdd„dD ƒ}|| | | }g }|D ]"}tj |¡r†||kr†| |¡ q†g }|D ]d}	t |	¡}
tt	|
ƒƒ}
t	|
t
d}
| D ]8}|
D ].}| ¡  |¡rät|ƒrä| tj |	|¡¡ qäqÜq²dd„ |D ƒ}||fS )z¢Generate a list of candidate filenames of what might be the dynamic
    library corresponding with the given list of names.
    Returns (lib_dirs, lib_paths)
    z/libz/usr/libz/usr/lib/x86_64-linux-gnuz/usr/lib/aarch64-linux-gnuz/usr/local/libz/opt/local/libÚbinÚlibZDLLszLibrary/binZsharedc                 S   s   g | ]}t j tj|¡‘qS r
   )ÚosÚpathÚjoinr   Úprefix©Ú.0Údr
   r
   r   Ú
<listcomp>3   s     z+generate_candidate_libs.<locals>.<listcomp>Úbase_prefixc                 S   s   g | ]}t j tj|¡‘qS r
   )r   r   r   r   r   r   r
   r
   r   r   5   s     ú~c                    s   g | ]}t j ˆ |¡‘qS r
   )r   r   r   r   ©Zhome_dirr
   r   r   9   s     )r   )Úkeyc                 S   s   g | ]}t j |¡r|‘qS r
   )r   r   Úisfile)r   Zlpr
   r
   r   r   Q   s      )Úhasattrr   r   r   Ú
expanduserÚisdirÚappendÚlistdirÚreversedÚsortedÚlenr   r   r   r   )Ú	lib_namesÚlib_dirsZsys_lib_dirsZpy_sub_dirsZpy_lib_dirsZuser_lib_dirsZpotential_lib_dirsÚldÚ	lib_pathsÚlib_dirÚfilesZlib_namer	   r
   r   r   Úgenerate_candidate_libs    s<    ú


r*   c                 C   st  t | tƒst‚t |tƒst‚|dk	r2t |tƒs2t‚dd„ | D ƒ} dd„ |D ƒ}|r\|d }n| rj| d }ntdƒ‚tr‚g g  }}nt||ƒ\}}| | }tj d¡r¬t	j
}nt	j}d}g }|D ]X}z| |¡}W  qW q¾ tk
r }	 z|| kr| ||	f¡ W 5 d}	~	X Y q¾X q¾|dkrl|rRdd„ |D ƒ}
d	}t||d
 |
¡f ƒ‚nd}t||d |¡f ƒ‚||fS )aÕ  load_lib(exact_lib_names, lib_names, lib_dirs=None)

    Load a dynamic library.

    This function first tries to load the library from the given exact
    names. When that fails, it tries to find the library in common
    locations. It searches for files that start with one of the names
    given in lib_names (case insensitive). The search is performed in
    the given lib_dirs and a set of common library dirs.

    Returns ``(ctypes_library, library_path)``
    Nc                 S   s   g | ]}|r|‘qS r
   r
   ©r   Únr
   r
   r   r   h   s      zload_lib.<locals>.<listcomp>c                 S   s   g | ]}|r|‘qS r
   r
   r+   r
   r
   r   r   i   s      r   zNo library name given.r   c                 S   s    g | ]\}}d |t |ƒf ‘qS )z%s:
%s)Ústr)r   r   Úer
   r
   r   r   •   s     z\One or more %s libraries were found, but could not be loaded due to the following errors:
%sz

z)Could not find a %s library in any of:
%sÚ
)Ú
isinstanceÚlistÚAssertionErrorÚ
ValueErrorÚSYSTEM_LIBS_ONLYr*   r   r   r   ÚctypesÚwindllZcdllZLoadLibraryÚ	Exceptionr   ÚOSErrorr   )Zexact_lib_namesr$   r%   Zthe_lib_namer'   ÚloaderZthe_libÚerrorsr	   ÚerrZerr_txtÚmsgr
   r
   r   Úload_libU   sH    



"
ÿr=   )N)N)Ú__doc__r   r   r5   r   ÚabspathÚdirnameÚ__file__ZLOCALDIRr4   r   r*   r=   r
   r
   r
   r   Ú<module>   s   
5