Ñò
—ã=Pc        
   @   s’   d  Z  d d k Z d d k l Z d d k l Z d d k Td d k l Z d d k l	 Z	 d d k
 l Z e e ƒ Z d	 e f d
 „  ƒ  YZ d S(   sF   
Contains transport interface (classes) and reference implementation.
iÿÿÿÿN(   t
   gettempdir(   t   urlparse(   t   *(   t   datetime(   t	   timedelta(   t	   getLoggert	   FileCachec           B   s†   e  Z d  Z d Z d Z d Z d d	 „ Z d
 „  Z d „  Z	 d „  Z
 d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z RS(   s|  
    A file-based URL cache.
    @cvar fnprefix: The file name prefix.
    @type fnprefix: str
    @cvar fnsuffix: The file name suffix.
    @type fnsuffix: str
    @ivar duration: The cached file duration which defines how
        long the file will be cached.
    @type duration: (unit, value)
    @ivar location: The directory for the cached files.
    @type location: str
    t   sudst   httpt   monthst   weekst   dayst   hourst   minutest   secondsc         K   sL   | d j o t i i t ƒ  d ƒ } n | |  _ d |  _ |  i |   d S(   s^  
        @param location: The directory for the cached files.
        @type location: str
        @param duration: The cached file duration which defines how
            long the file will be cached.  A duration=0 means forever.
            The duration may be: (months|weeks|days|hours|minutes|seconds).
        @type duration: {unit:value}
        R   i    N(   Ni    (   t   Nonet   ost   patht   joint   tmpt   locationt   durationt   setduration(   t   selfR   R   (    (    sS   /usr/local/lib/python2.6/dist-packages/suds-0.3.7-py2.6.egg/suds/transport/cache.pyt   __init__2   s
    			c         K   se   t  | ƒ d j oN | i ƒ  d } | d |  i j o t d t |  i ƒ ƒ ‚ n | |  _ n |  S(   s_  
        Set the caching duration which defines how long the 
        file will be cached.
        @param duration: The cached file duration which defines how
            long the file will be cached.  A duration=0 means forever.
            The duration may be: (months|weeks|days|hours|minutes|seconds).
        @type duration: {unit:value}
        i   i    s   must be: %s(   t   lent   itemst   unitst	   Exceptiont   strR   (   R   R   t   arg(    (    sS   /usr/local/lib/python2.6/dist-packages/suds-0.3.7-py2.6.egg/suds/transport/cache.pyR   A   s    	c         C   s   | |  _  d S(   s   
        Set the location (directory) for the cached files.
        @param location: The directory for the cached files.
        @type location: str
        N(   R   (   R   R   (    (    sS   /usr/local/lib/python2.6/dist-packages/suds-0.3.7-py2.6.egg/suds/transport/cache.pyt   setlocationQ   s    c         C   sR   y. t  i i |  i ƒ p t  i |  i ƒ n Wn t i |  i d d ƒn X|  S(   sM   
        Make the I{location} directory if it doesn't already exits.
        t   exc_infoi   (   R   R   t   isdirR   t   makedirst   logt   debug(   R   (    (    sS   /usr/local/lib/python2.6/dist-packages/suds-0.3.7-py2.6.egg/suds/transport/cache.pyt   mktmpY   s    c         C   sn   yL |  i  | ƒ } |  i | d ƒ } | i | i ƒ  ƒ | i ƒ  t | ƒ SWn t i | d d ƒ| SXd  S(   Nt   wR    i   (   t   _FileCache__fnt   opent   writet   readt   closeR#   R$   (   R   t   urlt   fpt   fnt   f(    (    sS   /usr/local/lib/python2.6/dist-packages/suds-0.3.7-py2.6.egg/suds/transport/cache.pyt   putd   s    
c         C   s;   y- |  i  | ƒ } |  i | ƒ |  i | ƒ SWn n Xd  S(   N(   R'   t   validateR(   (   R   R,   R.   (    (    sS   /usr/local/lib/python2.6/dist-packages/suds-0.3.7-py2.6.egg/suds/transport/cache.pyt   geto   s    c         C   s—   |  i  d d j  o d St i t i i | ƒ ƒ } h |  i  d |  i  d 6} | t |   } | t i ƒ  j  o! t i	 d | ƒ t i
 | ƒ n d S(   sŠ   
        Validate that the file has not expired based on the I{duration}.
        @param fn: The file name.
        @type fn: str
        i   Ni    s   %s expired, deleted(   R   t   dtt   fromtimestampR   R   t   getctimeR   t   nowR#   R$   t   remove(   R   R.   t   createdt   dt   expired(    (    sS   /usr/local/lib/python2.6/dist-packages/suds-0.3.7-py2.6.egg/suds/transport/cache.pyR1   w   s    c         C   s”   x t  i |  i ƒ D]y } t  i i | ƒ o q n | i |  i ƒ oF | i |  i ƒ o3 t	 i
 d | ƒ t  i t  i i |  i | ƒ ƒ q q Wd  S(   Ns   deleted: %s(   R   t   listdirR   R   R!   t
   startswitht   fnprefixt   endswitht   fnsuffixR#   R$   R7   R   (   R   R.   (    (    sS   /usr/local/lib/python2.6/dist-packages/suds-0.3.7-py2.6.egg/suds/transport/cache.pyt   clear†   s     &c         G   s   |  i  ƒ  t | | Œ S(   sK   
        Open the cache file making sure the directory is created.
        (   R%   R(   (   R   R.   t   args(    (    sS   /usr/local/lib/python2.6/dist-packages/suds-0.3.7-py2.6.egg/suds/transport/cache.pyR(   Ž   s    
c         C   s[   |  i  | ƒ o t d ƒ ‚ n d |  i t t | ƒ ƒ |  i f } t i i |  i	 | ƒ S(   Ns   URL %s, ignoreds   %s-%s.%s(
   t   _FileCache__ignoredR   R=   t   abst   hashR?   R   R   R   R   (   R   R,   R.   (    (    sS   /usr/local/lib/python2.6/dist-packages/suds-0.3.7-py2.6.egg/suds/transport/cache.pyt   __fn•   s    %c         C   s   t  | ƒ d } | d j S(   s    ignore urls based on protocol i    t   file(   s   file(   R   (   R   R,   t   protocol(    (    sS   /usr/local/lib/python2.6/dist-packages/suds-0.3.7-py2.6.egg/suds/transport/cache.pyt	   __ignored›   s    (   R	   R
   R   R   R   R   N(   t   __name__t
   __module__t   __doc__R=   R?   R   R   R   R   R   R%   R0   R2   R1   R@   R(   R'   RB   (    (    (    sS   /usr/local/lib/python2.6/dist-packages/suds-0.3.7-py2.6.egg/suds/transport/cache.pyR       s   									(   RK   R   t   tempfileR    R   R   t   suds.transportR   R3   R   t   loggingR   RI   R#   t   CacheR   (    (    (    sS   /usr/local/lib/python2.6/dist-packages/suds-0.3.7-py2.6.egg/suds/transport/cache.pyt   <module>   s   
