ó
\K]c           @` s  d  Z  d d l m Z m Z m Z d d l m Z e d k  rZ d d l m Z	 e	 ƒ  Z
 n d d l m Z
 d d l Z d d l Z d d	 l m Z m Z d d
 l m Z m Z d „  Z d e f d „  ƒ  YZ d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d S(   s/   
Serialization support for compiled functions.
i    (   t   print_functiont   divisiont   absolute_importi   (   t	   PYVERSIONi   (   t	   get_magic(   t   MAGIC_NUMBERN(   t   FunctionTypet
   ModuleType(   t   bytecodet   compilerc         G` s   |  j  | Œ  S(   sM   
    Global hook to rebuild a given class from its __reduce__ arguments.
    (   t   _rebuild(   t   clst   args(    (    s.   lib/python2.7/site-packages/numba/serialize.pyt   _rebuild_reduction   s    t
   _ModuleRefc           B` s   e  Z d  „  Z d „  Z RS(   c         C` s   | |  _  d  S(   N(   t   name(   t   selfR   (    (    s.   lib/python2.7/site-packages/numba/serialize.pyt   __init__$   s    c         C` s   t  |  j f f S(   N(   t   _rebuild_moduleR   (   R   (    (    s.   lib/python2.7/site-packages/numba/serialize.pyt
   __reduce__'   s    (   t   __name__t
   __module__R   R   (    (    (    s.   lib/python2.7/site-packages/numba/serialize.pyR   "   s   	c         C` s0   |  d  k r t d ƒ ‚ n  t |  ƒ t j |  S(   Ns   cannot import None(   t   Nonet   ImportErrort
   __import__t   syst   modules(   R   (    (    s.   lib/python2.7/site-packages/numba/serialize.pyR   +   s    
c         C` s€   t  j j |  ƒ } t  j | ƒ } | j ƒ  } x? | j ƒ  D]1 \ } } t | t ƒ r: t | j	 ƒ | | <q: q: W|  j
 | d <| S(   s]   
    Analyse *func* and return a dictionary of global values suitable for
    reduction.
    R   (   R   t   FunctionIdentityt   from_functiont   ByteCodet   get_used_globalst   itemst
   isinstanceR   R   R   R   (   t   funct   func_idt   bct   globst   kt   v(    (    s.   lib/python2.7/site-packages/numba/serialize.pyt#   _get_function_globals_for_reduction2   s    c         C` sM   |  j  r+ g  |  j  D] } | j ^ q } n d } t |  j ƒ | |  j | f S(   s¬   
    Reduce a Python function and its globals to picklable components.
    If there are cell variables (i.e. references to a closure), their
    values will be frozen.
    N(   t   __closure__t   cell_contentsR   t   _reduce_codet   __code__R   (   R!   R$   t   cellt   cells(    (    s.   lib/python2.7/site-packages/numba/serialize.pyt   _reduce_functionC   s    	"c         C` s   t  j t t  j |  ƒ f S(   s7   
    Reduce a code object to picklable components.
    (   t   marshalt   versiont   bc_magict   dumps(   t   code(    (    s.   lib/python2.7/site-packages/numba/serialize.pyR*   O   s    c         ` s   ‡  f d †  S(   s=   
    A dummy function allowing us to build cell objects.
    c           ` s   ˆ  S(   N(    (    (   t   x(    s.   lib/python2.7/site-packages/numba/serialize.pyt   <lambda>Y   t    (    (   R4   (    (   R4   s.   lib/python2.7/site-packages/numba/serialize.pyt   _dummy_closureU   s    c         C` sz   | r t  d „  | Dƒ ƒ } n d } t |  Œ  } | d } y t | ƒ Wn t k
 rc | d =n Xt | | | d | ƒ S(   sA   
    Rebuild a function from its _reduce_function() results.
    c         s` s"   |  ] } t  | ƒ j d  Vq d S(   i    N(   R7   R(   (   t   .0R&   (    (    s.   lib/python2.7/site-packages/numba/serialize.pys	   <genexpr>`   s    R   (    (    (   t   tuplet   _rebuild_codeR   R   R   (   t   code_reducedt   globalsR   t   cell_valuesR-   R3   t   modname(    (    s.   lib/python2.7/site-packages/numba/serialize.pyt   _rebuild_function[   s    
c         C` sS   t  j |  k r+ t d t  j |  f ƒ ‚ n  t | k rF t d ƒ ‚ n  t  j | ƒ S(   s@   
    Rebuild a code object from its _reduce_code() results.
    sH   incompatible marshal version: interpreter has %r, marshalled code has %rs   incompatible bytecode version(   R/   R0   t   RuntimeErrorR1   t   loads(   t   marshal_versiont   bytecode_magict
   marshalled(    (    s.   lib/python2.7/site-packages/numba/serialize.pyR:   m   s    (   i   i   (   t   __doc__t
   __future__R    R   R   t   utilsR   t   impR   t
   _get_magicR1   t   importlib.utilR   R/   R   t   typesR   R   R6   R   R	   R   t   objectR   R   R'   R.   R*   R7   R?   R:   (    (    (    s.   lib/python2.7/site-packages/numba/serialize.pyt   <module>   s&   								