ó
±ÆKc           @   s9  d  Z  d d l Z d d l Z d d l m Z d d l Td d l m Z d d l	 m
 Z
 d d l m Z d d l m Z d d	 l m Z d d
 l m Z y d d l Z Wn d d l Z n Xe e ƒ Z d d d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d S(   s!   
Contains basic caching classes.
iÿÿÿÿN(   t
   gettempdir(   t   *(   t   Parser(   t   Element(   t   datetime(   t	   timedelta(   t   StringIO(   t	   getLoggert   Cachec           B   sD   e  Z d  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z RS(   s!   
    An object object cache.
    c         C   s   t  d ƒ ‚ d S(   s§   
        Get a object from the cache by ID.
        @param id: The object ID.
        @type id: str
        @return: The object, else None
        @rtype: any
        s   not-implementedN(   t	   Exception(   t   selft   id(    (    sD   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/suds/cache.pyt   get,   s    c         C   s   t  d ƒ ‚ d S(   s§   
        Get a object from the cache by ID.
        @param id: The object ID.
        @type id: str
        @return: The object, else None
        @rtype: any
        s   not-implementedN(   R	   (   R
   R   (    (    sD   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/suds/cache.pyt   getf6   s    c         C   s   t  d ƒ ‚ d S(   sª   
        Put a object into the cache.
        @param id: The object ID.
        @type id: str
        @param object: The object to add.
        @type object: any
        s   not-implementedN(   R	   (   R
   R   t   object(    (    sD   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/suds/cache.pyt   put@   s    c         C   s   t  d ƒ ‚ d S(   s©   
        Write a fp into the cache.
        @param id: The object ID.
        @type id: str
        @param fp: File pointer.
        @type fp: file-like object.
        s   not-implementedN(   R	   (   R
   R   t   fp(    (    sD   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/suds/cache.pyt   putfJ   s    c         C   s   t  d ƒ ‚ d S(   st   
        Purge a object from the cache by id.
        @param id: A object ID.
        @type id: str        
        s   not-implementedN(   R	   (   R
   R   (    (    sD   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/suds/cache.pyt   purgeT   s    c         C   s   t  d ƒ ‚ d S(   s3   
        Clear all objects from the cache.
        s   not-implementedN(   R	   (   R
   (    (    sD   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/suds/cache.pyt   clear\   s    (	   t   __name__t
   __module__t   __doc__R   R   R   R   R   R   (    (    (    sD   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/suds/cache.pyR   '   s   	
	
	
	
	t   NoCachec           B   s2   e  Z d  Z d „  Z d „  Z d „  Z d „  Z RS(   s$   
    The passthru object cache.
    c         C   s   d  S(   N(   t   None(   R
   R   (    (    sD   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/suds/cache.pyR   h   s    c         C   s   d  S(   N(   R   (   R
   R   (    (    sD   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/suds/cache.pyR   k   s    c         C   s   d  S(   N(    (   R
   R   R   (    (    sD   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/suds/cache.pyR   n   s    c         C   s   d  S(   N(    (   R
   R   R   (    (    sD   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/suds/cache.pyR   q   s    (   R   R   R   R   R   R   R   (    (    (    sD   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/suds/cache.pyR   c   s
   			t	   FileCachec           B   s¤   e  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 d „  Z d „  Z d „  Z d „  Z RS(   s:  
    A file-based URL cache.
    @cvar fnprefix: The file name prefix.
    @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   monthst   weekst   dayst   hourst   minutest   secondsc         K   sT   | d k r' t j j t ƒ  d ƒ } n  | |  _ d |  _ |  j | �  |  j ƒ  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    (	   R   t   ost   patht   joint   tmpt   locationt   durationt   setdurationt   checkversion(   R
   R%   R&   (    (    sD   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/suds/cache.pyt   __init__ƒ   s    			c         C   s   d S(   sZ   
        Get the file name suffix
        @return: The suffix
        @rtype: str
        t   gcf(    (   R
   (    (    sD   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/suds/cache.pyt   fnsuffix“   s    c         K   sa   t  | ƒ d k r] | j ƒ  d } | d |  j k rQ t d t |  j ƒ ƒ ‚ 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   unitsR	   t   strR&   (   R
   R&   t   arg(    (    sD   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/suds/cache.pyR'   ›   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%   (    (    sD   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/suds/cache.pyt   setlocation«   s    c         C   sP   y, t  j j |  j ƒ s+ t  j |  j ƒ n  Wn t j |  j 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
   (    (    sD   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/suds/cache.pyt   mktmp³   s    c         C   sb   y@ |  j  | ƒ } |  j | d ƒ } | j | ƒ | j ƒ  | SWn t j | d d ƒ| SXd  S(   Nt   wR2   i   (   t   _FileCache__fnt   opent   writet   closeR5   R6   (   R
   R   t   bfrt   fnt   f(    (    sD   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/suds/cache.pyR   ¾   s    
c         C   sx   yV |  j  | ƒ } |  j | d ƒ } | j | j ƒ  ƒ | j ƒ  | j ƒ  t | ƒ SWn t j | d d ƒ| SXd  S(   NR8   R2   i   (   R9   R:   R;   t   readR<   R5   R6   (   R
   R   R   R>   R?   (    (    sD   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/suds/cache.pyR   É   s    

c         C   s;   y- |  j  | ƒ } | j ƒ  } | j ƒ  | SWn n Xd  S(   N(   R   R@   R<   (   R
   R   R?   R=   (    (    sD   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/suds/cache.pyR   Õ   s    
c         C   s;   y- |  j  | ƒ } |  j | ƒ |  j | ƒ SWn n Xd  S(   N(   R9   t   validateR:   (   R
   R   R>   (    (    sD   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/suds/cache.pyR   Þ   s    c         C   s“   |  j  d d k  r d St j t j j | ƒ ƒ } i |  j  d |  j  d 6} | t | �  } | t j ƒ  k  r� t j	 d | ƒ t j
 | ƒ 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   nowR5   R6   t   remove(   R
   R>   t   createdt   dt   expired(    (    sD   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/suds/cache.pyRA   æ   s    c         C   s}   xv t  j |  j ƒ D]b } t  j j | ƒ r1 q n  | j |  j ƒ r t j d | ƒ t  j	 t  j j
 |  j | ƒ ƒ q q Wd  S(   Ns   deleted: %s(   R!   t   listdirR%   R"   R3   t
   startswitht   fnprefixR5   R6   RF   R#   (   R
   R>   (    (    sD   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/suds/cache.pyR   õ   s    c         C   s.   |  j  | ƒ } y t j | ƒ Wn n Xd  S(   N(   R9   R!   RF   (   R
   R   R>   (    (    sD   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/suds/cache.pyR   ý   s
    c         G   s   |  j  ƒ  t | | Œ S(   sK   
        Open the cache file making sure the directory is created.
        (   R7   R:   (   R
   R>   t   args(    (    sD   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/suds/cache.pyR:     s    
c         C   s    t  j j |  j d ƒ } yD |  j | ƒ } | j ƒ  } | j ƒ  | t j k r[ t	 ƒ  ‚ n  Wn= |  j
 ƒ  |  j | d ƒ } | j t j ƒ | j ƒ  n Xd  S(   Nt   versionR8   (   R!   R"   R#   R%   R:   R@   R<   R   t   __version__R	   R   R;   (   R
   R"   R?   RN   (    (    sD   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/suds/cache.pyR(     s    

c         C   s>   | } |  j  ƒ  } d |  j | | f } t j j |  j | ƒ S(   Ns   %s-%s.%s(   R+   RL   R!   R"   R#   R%   (   R
   R   t   namet   suffixR>   (    (    sD   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/suds/cache.pyt   __fn  s    (   s   monthss   weekss   dayss   hourss   minutess   secondsN(   R   R   R   RL   R.   R   R)   R+   R'   R1   R7   R   R   R   R   RA   R   R   R:   R(   R9   (    (    (    sD   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/suds/cache.pyR   u   s$   
														t   DocumentCachec           B   s)   e  Z d  Z d „  Z d „  Z d „  Z RS(   s(   
    Provides xml document caching.
    c         C   s   d S(   Nt   xml(    (   R
   (    (    sD   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/suds/cache.pyR+   &  s    c         C   sZ   y< t  j |  | ƒ } | d  k r% d  St ƒ  } | j | ƒ SWn t  j |  | ƒ n Xd  S(   N(   R   R   R   R   t   parseR   (   R
   R   R   t   p(    (    sD   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/suds/cache.pyR   )  s    	c         C   s/   t  | t ƒ r+ t j |  | t | ƒ ƒ n  | S(   N(   t
   isinstanceR   R   R   R/   (   R
   R   R   (    (    sD   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/suds/cache.pyR   3  s    (   R   R   R   R+   R   R   (    (    (    sD   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/suds/cache.pyRS   !  s   		
t   ObjectCachec           B   s/   e  Z d  Z d Z d „  Z d „  Z d „  Z RS(   sm   
    Provides pickled object caching.
    @cvar protocol: The pickling protocol.
    @type protocol: int
    i   c         C   s   d S(   Nt   px(    (   R
   (    (    sD   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/suds/cache.pyR+   A  s    c         C   sQ   y3 t  j |  | ƒ } | d  k r% d  St j | ƒ SWn t  j |  | ƒ n Xd  S(   N(   R   R   R   t   picklet   loadR   (   R
   R   R   (    (    sD   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/suds/cache.pyR   D  s    c         C   s,   t  j | |  j ƒ } t j |  | | ƒ | S(   N(   RZ   t   dumpst   protocolR   R   (   R
   R   R   R=   (    (    sD   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/suds/cache.pyR   N  s    (   R   R   R   R]   R+   R   R   (    (    (    sD   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/suds/cache.pyRX   9  s
   		
(    (   R   R!   R   t   tempfileR    R$   t   suds.transportt   suds.sax.parserR   t   suds.sax.elementR   R   RB   R   t	   cStringIOR   t   loggingR   t   cPickleRZ   R   R5   R   R   R   RS   RX   (    (    (    sD   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/suds/cache.pyt   <module>   s(   
<¬