mò
;‘ÑEc           @   sŽ   d  Z  d k l Z d k Z d k Z e i d j p
 t d ‚ d k l Z d e	 f d „  ƒ  YZ
 d	 „  Z d
 e f d „  ƒ  YZ d „  Z d S(   s–  
package initialization.

You use the functionality of this package by putting

    from py.initpkg import initpkg
    initpkg(__name__, exportdefs={
        'name1.name2' : ('./path/to/file.py', 'name')
        ...
    })

into your package's __init__.py file.  This will
lead your package to only expose the names of all
your implementation files that you explicitely
specify.  In the above example 'name1' will
become a Module instance where 'name2' is
bound in its namespace to the 'name' object
in the relative './path/to/file.py' python module.
Note that you can also use a '.c' file in which
case it will be compiled via distutils-facilities
on the fly.

(   s
   generatorsNi   i    s$   py lib requires python 2.2 or higher(   s
   ModuleTypet   Packagec           B   se   t  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z g  d „ Z	 d	 „  Z
 d
 „  Z RS(   Nc         C   s  t  i | } | i | j p t ‚ | |  _ | |  _ | |  _ t	 | d ƒ p t d | ‚ |  | _
 | d d } t | ƒ |  _ | |  i _ t i i | i ƒ |  i _ g  } | i D] } | t i i | ƒ q¹ ~ |  i _ |  i | _ t | |  i ƒ | ` d  S(   Nt   __package__s"   unsupported reinitialization of %rt   .t   __(   t   syst   modulest   namet	   pkgmodulet   __name__t   AssertionErrort   selft
   exportdefst   modulet   hasattrR   t   implnamet
   ModuleTypet
   implmodulet   ost   patht   abspatht   __file__t   _[1]t   __path__t   pR   t	   setmodule(   R
   R   R   R   R   R   R   (    (    t,   /data/htdocs/projects/kupusite/py/initpkg.pyt   __init__#   s    				6c   	      C   s$  | \ } } | i d ƒ pY d k } | i i |  i i	 ƒ } | i | d t ƒ} | i i | | ƒ } | i ƒ  Sn | i d ƒ p t d | f ‚ |  i | d  ƒ } t | t ƒ p | Sn | } xV | i d ƒ D]E } y t | | ƒ } Wq× t j
 o t d | | f ƒ ‚ q× Xq× W| S(	   s6    resolve a combined filesystem/python extpy-ish path. s   .pyNt   abss   ./s&   %r is not an implementation path (XXX)iýÿÿÿR   s   resolving %r failed: %s(   t   extpyisht   fspatht   modpatht   endswitht   pyR   t   localR
   R   R   t   et   dirpatht   Truet   extpyt   resolvet
   startswithR	   t	   _loadimplt
   isinstancet   strt   currentt   splitt   xt   getattrt   AttributeError(	   R
   R   R"   R    R+   R   R   R-   R   (    (    R   t   _resolve9   s(     	! c         C   s¡   | i i d ƒ p d  Sn d  k } | i  i |  i i ƒ i	 ƒ  } | i | ƒ p d  Sn | i d d ƒ i | ƒ i | i ƒ } d i |  i i g | ƒ } | S(   Ns   .pyt   extt    R   (   R   R1   R'   t   NoneR    R!   R
   R   R   R#   t   baset   reltot   newR,   t   sept   namest   joinR   t
   dottedname(   R
   R   R:   R    R4   R8   (    (    R   t   getimportnameR   s    	'c         C   sz   g  } | i d ƒ D]+ } | o | d j o | | i ƒ  q q ~ } d i |  i i	 g | ƒ } t | d d d g ƒ S(   s,    load implementation for the given relfile. t   /R   t   __doc__N(   R   t   relfileR,   R-   t   stript   partsR9   R
   R   R   R   t
   __import__R3   (   R
   R>   R   R@   R   R-   (    (    R   R(   ]   s     Hc         C   s   |  i i ƒ  S(   N(   R
   R   t   items(   R
   (    (    R   t   exportitemsd   s    c         C   s=   d k  l } | |  i i ƒ i ƒ  } | i ƒ  p t ‚ | S(   N(   s   local(	   t   py.pathR!   R
   R   R   R#   R4   t   checkR	   (   R
   R4   R!   (    (    R   t   getpathg   s    c         c   sY   d k  l } |  i ƒ  } x9 | i | d d d d ƒ d | d d ƒ ƒD]
 } | VqG Wd  S(	   N(   s   checkert   filei   t   notexts   .pyct   rect   dotfilei    (   t   py.__.path.commont   checkerR
   RF   R4   t   visitR-   (   R
   R-   R4   RL   (    (    R   t
   _iterfilesm   s     c         C   sn   | o | d Sn d k l } | ƒ  } x' |  i ƒ  D] } | i | i ƒ  ƒ q6 W| i | i	 ƒ  ƒ | d S(   s6    return sha hexdigest for files contained in package. i    (   s   shaN(
   t   cachet   shat   sumR
   RN   R-   t   updatet   readt   appendt	   hexdigest(   R
   RO   RP   RQ   R-   (    (    R   t   shahexdigestt   s     	 c         C   sÑ   d k  } d k } y d k l } Wn  t j
 o d k l } n X| i i ƒ  i ƒ  } | ƒ  } | i
 | d d | i ƒ} z: x3 |  i ƒ  D]% } | i t | ƒ | i | ƒ ƒ q WWd | i ƒ  X| i ƒ  S(   s>    return string representing a zipfile containing the package. N(   s   StringIOt   wt   compression(   t   zipfileR    t	   cStringIOt   StringIOt   ImportErrorR   RF   R#   R4   t   outft   ZipFilet   ZIP_DEFLATEDt   fR
   RN   R-   t   writeR*   R5   t   closet   getvalue(   R
   R`   R[   R    RY   R4   R]   R-   (    (    R   t
   getzipdata   s"     			 ' c         C   sh   d  k  } | i i |  i i ƒ i ƒ  } y | i ƒ  i	 SWn) t
 t t f j
 o
 ‚  n d Sn Xd  S(   Nt   unknown(   R    R   t   svnwcR
   R   R   R#   R   t   infot   revt   KeyboardInterruptt   MemoryErrort
   SystemExit(   R
   R    R   (    (    R   t   getrev“   s    	(   R   t
   __module__R   R0   R;   R(   RC   RF   RN   RV   Rd   Rl   (    (    (    R   R    "   s   								c         C   s   | t i |  <d  S(   N(   R   R   R   R   (   R   R   (    (    R   R      s    t   Modulec           B   sD   t  Z d „  Z d „  Z d „  Z d „  Z d „  Z e e ƒ Z [ RS(   Nc         C   s   | |  _ | |  _ h  |  _ d  S(   N(   t   pkgR
   R   R   R   t   __map__(   R
   Ro   R   (    (    R   R   ¦   s    		c         C   s¦   d |  i j o- |  i d d | f } |  i i | ƒ } nV y |  i | } Wn% t j
 o t } t
 | ƒ ‚ n X|  i i | ƒ } |  i | =t |  | | ƒ | S(   Nt   *i    (   R
   Rp   R   R%   R   R0   t   resultt   KeyErrorR$   t   __tracebackhide__R/   t   setattr(   R
   R   Rt   Rr   R%   (    (    R   t   __getattr__«   s    
c         C   sª   t  | d ƒ oR | i i d ƒ p d  Sn y t | d |  i ƒ Wqb t t f j
 o qb Xn t  | d ƒ o4 y t | d | ƒ Wq¦ t t f j
 o q¦ Xn d  S(   NRm   s   py.__t	   __bases__R   (
   R   Rr   Rm   R'   Ru   R
   R   R/   t	   TypeErrorR   (   R
   Rr   R   (    (    R   t   _deprecated_fixinspection¼   s    	c         C   s   d |  i f S(   Ns   <Module %r>(   R
   R   (   R
   (    (    R   t   __repr__Í   s    c         C   s¹   t  i d } | i |  ƒ } | d  j	 oŒ d |  i j oG x$ |  i i ƒ  D] } t
 |  | ƒ qI W|  i p t d |  i ‚ qµ |  i d d } | i |  i i | d  ƒ i ƒ n | S(   Nt   __dict__Rq   s   %r not emptyi    iýÿÿÿ(   R   R{   t	   dictdescrt   __get__R
   t   dictR3   Rp   t   keysR   R   R	   t   fsnameRR   R   R(   (   R
   R   R~   R€   R|   (    (    R   t   getdictÐ   s      $(	   R   Rm   R   Rv   Ry   Rz   R   t   propertyR{   (    (    (    R   Rn   ¥   s   					c         K   sß  t  |  | ƒ } x* | i ƒ  D] \ } } t | | | ƒ q Wh  |  | i	 <} g  } xQ| i ƒ  D]C\ } } | i d ƒ }	 |	 } | d d j o | i ƒ  } n d } |  } xk | D]c } | } | d | 7} | | j o< t | | ƒ | | <} t | | | | ƒ t | | ƒ q· q· W| | } t | d ƒ p8 | | i	 j p
 t d ‚ | i | |	 d | f ƒ qa | d d j o | i | ƒ | _ qa | | i | <qa Wx0 | D]( \ } }
 } t | |
 | i | ƒ ƒ q¯Wd  S(   NR   i   Rq   Rp   s.   only root modules are allowed to be non-lazy. iÿÿÿÿR=   (    R    t   pkgnameR   Ro   t   kwRB   R   t   valueRu   R   t   seent   deferred_importsRC   t   pypathR%   R,   t   pypartst   modpartst   popt   lastmodpartR+   t   previousRn   t   modR   R   R	   RT   R0   R=   Rp   t   pypart(   Rƒ   R   R„   R…   R†   R   RŒ   R+   R‡   R‰   R   RŠ   RŽ   R   R%   Rˆ   Ro   (    (    R   t   initpkgå   s@       
 (   i   i   i    (   R=   t
   __future__t
   generatorsR   R   t   version_infoR	   t   typesR   t   objectR    R   Rn   R   (   R   R    Rn   R   R’   R   R   R   (    (    R   t   ?   s   		{	@
