ó
;c›]c           @` s   d  Z  d d l m Z m Z m Z d d l Z d d l Z d d l Z e j j	 e j j
 e ƒ ƒ Z e Z d „  Z d d „ Z d d „ Z d S(   sG    This module contains generic code to find and load a dynamic library.
i    (   t   absolute_importt   print_functiont   divisionNc         C` sg   |  j  ƒ  }  t j j d ƒ r+ |  j d ƒ St j j d ƒ rJ |  j d ƒ S|  j d ƒ pb d |  k Sd S(   s…    Returns True if the given filename looks like a dynamic library.
    Based on extension, but cross-platform and more flexible. 
    t   wins   .dllt   darwins   .dylibs   .sos   .so.N(   t   lowert   syst   platformt
   startswitht   endswith(   t   fname(    (    s3   lib/python2.7/site-packages/imageio/core/findlib.pyt	   looks_lib   s    c         C` s  | p	 g  } d d d d d g } d d d d	 g } g  | D] } t  j j t j | ƒ ^ q: } t t d
 ƒ rŸ | g  | D] } t  j j t j | ƒ ^ qw 7} n  t  j j d ƒ } g  d g D] } t  j j | | ƒ ^ q» } | | | | } g  } x< | D]4 }	 t  j j |	 ƒ rû |	 | k rû | j	 |	 ƒ qû qû Wg  }
 x£ | D]› } t  j
 | ƒ } t t | ƒ ƒ } t | d t ƒ} x_ |  D]W } xN | D]F } | j ƒ  j | ƒ rt | ƒ r|
 j	 t  j j | | ƒ ƒ qqWq€Wq@Wg  |
 D] } t  j j | ƒ ræ| ^ qæ}
 | |
 f S(   s£    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)
    s   /libs   /usr/libs   /usr/lib/x86_64-linux-gnus   /usr/local/libs   /opt/local/libt   libt   DLLss   Library/bint   sharedt   base_prefixt   ~t   key(   t   ost   patht   joinR   t   prefixt   hasattrR   t
   expandusert   isdirt   appendt   listdirt   reversedt   sortedt   lenR   R   R   t   isfile(   t	   lib_namest   lib_dirst   sys_lib_dirst   py_sub_dirst   dt   py_lib_dirst   home_dirt   user_lib_dirst   potential_lib_dirst   ldt	   lib_pathst   lib_dirt   filest   lib_nameR
   t   lp(    (    s3   lib/python2.7/site-packages/imageio/core/findlib.pyt   generate_candidate_libs"   s8    	+2+!++c         C` s8  t  |  t ƒ s t ‚ t  | t ƒ s* t ‚ | d
 k	 rN t  | t ƒ sN t ‚ n  g  |  D] } | rU | ^ qU }  g  | D] } | rt | ^ qt } | rŸ | d } n |  r² |  d } n t d ƒ ‚ t rÔ g  g  } } n t | | ƒ \ } } |  | } t j j	 d ƒ rt
 j } n	 t
 j } d
 } g  } xp | D]h }	 y | j |	 ƒ } PWq-t k
 r”|	 |  k r•t j ƒ  \ }
 } } ~ | j |	 | f ƒ q•q-Xq-W| d
 k r.| rg  | D]" \ } } d | t | ƒ f ^ q²} d d } t | | d j | ƒ f ƒ ‚ q.d } t | | d	 j | ƒ f ƒ ‚ n  | |	 f S(   sã   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)``
    i    s   No library name given.R   s   %s:
%ss)   One or more %s libraries were found, but s3   could not be loaded due to the following errors:
%ss   

s)   Could not find a %s library in any of:
%ss   
N(   t
   isinstancet   listt   AssertionErrort   Nonet
   ValueErrort   SYSTEM_LIBS_ONLYR.   R   R   R   t   ctypest   windllt   cdllt   LoadLibraryt	   Exceptiont   exc_infoR   t   strt   OSErrorR   (   t   exact_lib_namesR   R    t   nt   the_lib_nameR)   t   loadert   the_libt   errorsR
   t   e_typet   e_valuet   e_tbt   lt   et   err_txtt   msg(    (    s3   lib/python2.7/site-packages/imageio/core/findlib.pyt   load_libV   sL    
	/""(   t   __doc__t
   __future__R    R   R   R   R   R5   R   t   abspatht   dirnamet   __file__t   LOCALDIRt   FalseR4   R   R2   R.   RJ   (    (    (    s3   lib/python2.7/site-packages/imageio/core/findlib.pyt   <module>   s   	4