ó
Ņ¬Qc           @   sŅ   d  Z  d d l m Z e d d d d d l m Z d d l Z d d l Z d d l Z d d l Z d e	 f d	     YZ
 d
 e f d     YZ d d d  Z d d  Z d d  Z d   Z d d  Z d S(   s@   macresource - Locate and open the resources needed for a script.i’’’’(   t   warnpy3ks*   In 3.x, the macresource module is removed.t
   stackleveli   (   t   ResNt   ArgumentErrorc           B   s   e  Z RS(    (   t   __name__t
   __module__(    (    (    sA   /Users/tom/newbuild/install/lib/python2.7/plat-mac/macresource.pyR      s    t   ResourceFileNotFoundErrorc           B   s   e  Z RS(    (   R   R   (    (    (    sA   /Users/tom/newbuild/install/lib/python2.7/plat-mac/macresource.pyR      s    c   
      C   sč  | d k r$ | d k r$ t d  n  t |  t d  k rp y t j |  |  } Wn t j k
 rh q” Xd Sn1 y t j |  |  } Wn t j k
 r n Xd S| sŚ d | k rĶ | j d  d d } qŚ | d } n  g  } | d k rū t j	 g } n  | t
 j k rDt
 j | } t | d  rDt j j | j  g } qDn  | j t
 j  xB | D]1 } t j j | |  } t j j |  r[Pq[q[Wt |  t |  }	 t |  t d  k rŅt j |  |  } n t j |  |  } |	 S(	   s  Open a resource file, if needed. restype and resid
    are required parameters, and identify the resource for which to test. If it
    is available we are done. If it is not available we look for a file filename
    (default: modname with .rsrc appended) either in the same folder as
    where modname was loaded from, or otherwise across sys.path.

    Returns the refno of the resource file opened (or None)s;   Either filename or modname argument (or both) must be giveni   t   .i’’’’s   .rsrct   __main__t   __file__N(   t   NoneR   t   typeR   t   GetResourcet   Errort   GetNamedResourcet   splitt   ost   curdirt   syst   modulest   hasattrt   patht   dirnameR	   t   extendt   joint   existsR   t   open_pathname(
   t   restypet   residt   filenamet   modnamet   ht
   searchdirst   modt   dirt   pathnamet   refno(    (    sA   /Users/tom/newbuild/install/lib/python2.7/plat-mac/macresource.pyt   need   sF    		i    c         C   sw   y t  j |  d d  } Wn, t  j k
 rG } | d d k rL   qL n X| St |  d | }  t  j |  d d  } d S(   sQ   Open a resource file given by pathname, possibly decoding an
    AppleSingle fileu    i   i    i9’’’t   verboseN(   R   t   FSOpenResourceFileR   t   _decode(   R#   R&   R$   t   arg(    (    sA   /Users/tom/newbuild/install/lib/python2.7/plat-mac/macresource.pyR   M   s    
c         C   sb   y t  j |  d d  } Wn, t  j k
 rG } | d d k rL   qL n X| St |  d | }  |  S(   s©   Return the pathname for a resource file (either DF or RF based).
    If the pathname given already refers to such a file simply return it,
    otherwise first decode it.u    i   i    i9’’’R&   (   R   R'   R   R(   (   R#   R&   R$   R)   (    (    sA   /Users/tom/newbuild/install/lib/python2.7/plat-mac/macresource.pyt   resource_pathname_   s    
c           C   s   t  d d d d d t d S(   sN   Open the resource file containing the error code to error message
    mapping.t   Estri   R   s   errors.rsrcR   N(   R%   R   (    (    (    sA   /Users/tom/newbuild/install/lib/python2.7/plat-mac/macresource.pyt   open_error_resourcer   s    c         C   są   |  d } t  j j |  rD t  j |  j t  j |   j k rD | St t  d  r  t  j t  j j |   t  j t  j	 B r  d d  l
 } | j d  \ } } n  | rŗ d G|  Gd G| GHn  d d  l } | j |  | d d | S(	   Ns   .df.rsrct   accessi’’’’s   .rsrct   Decodingt   tot   resonlyi   (   R   R   R   t   statt   st_mtimeR   R-   R   t   W_OKt   X_OKt   tempfilet   mkstempt   applesinglet   decode(   R#   R&   t   newpathnameR5   t   fdR7   (    (    sA   /Users/tom/newbuild/install/lib/python2.7/plat-mac/macresource.pyR(   w   s    
$)(   t   __doc__t   warningsR    t   CarbonR   R   R   t   MacOSt
   macostoolst	   TypeErrorR   t   ImportErrorR   R
   R%   R   R*   R,   R(   (    (    (    sA   /Users/tom/newbuild/install/lib/python2.7/plat-mac/macresource.pyt   <module>   s   >	