ó
àÆ÷Xc           @` sc   d  d l  m Z m Z m Z d  d l Z d  d l j j Z e j	 d ƒ Z
 d e f d „  ƒ  YZ d S(   i    (   t   absolute_importt   print_functiont   divisionNs   theano.gof.callcachet	   CallCachec           B` s8   e  Z d d  „ Z d d „ Z d d d „ Z d „  Z RS(   c         C` ss   | |  _  yI | d  k r' t d ƒ ‚ n  t | d ƒ  } t j | ƒ |  _ Wd  QXWn t k
 rn i  |  _ n Xd  S(   Ns   bad filenamet   r(   t   filenamet   Nonet   IOErrort   opent   picklet   loadt   cache(   t   selfR   t   f(    (    s4   /tmp/pip-build-X4mzal/theano/theano/gof/callcache.pyt   __init__	   s    	c         C` sG   | d k r |  j } n  t | d ƒ  } t j |  j | ƒ Wd QXd S(   s3   
        Cache "filename" as a pickle file
        t   wN(   R   R   R   R	   t   dumpR   (   R   R   R   (    (    s4   /tmp/pip-build-X4mzal/theano/theano/gof/callcache.pyt   persist   s    c         C` sƒ   | d k r! | t | ƒ f } n  | |  j k r_ t j d t |  j ƒ ƒ | | Œ  |  j | <n t j d t |  j ƒ ƒ |  j | S(   sñ   
        Retrieve item from the cache(if available)
        based on a key

        Parameters:
        ----------
        key
            parameter to retrieve cache item
        fn,args
            key to retrieve if "key" is None
        s   cache miss %is   cache hit %iN(   R   t   tupleR   t   _loggert   debugt   len(   R   t   fnt   argst   key(    (    s4   /tmp/pip-build-X4mzal/theano/theano/gof/callcache.pyt   call   s    c         C` sJ   y |  j  r |  j ƒ  n  Wn) t k
 rE } t j d |  j  | ƒ n Xd  S(   Ns   persist failed %s %s(   R   R   t	   ExceptionR   t   error(   R   t   e(    (    s4   /tmp/pip-build-X4mzal/theano/theano/gof/callcache.pyt   __del__1   s
    	N(    (   t   __name__t
   __module__R   R   R   R   R   (    (    (    s4   /tmp/pip-build-X4mzal/theano/theano/gof/callcache.pyR      s   
	(   t
   __future__R    R   R   t   loggingt   six.moves.cPicklet   movest   cPickleR	   t	   getLoggerR   t   objectR   (    (    (    s4   /tmp/pip-build-X4mzal/theano/theano/gof/callcache.pyt   <module>   s   