Ñò
J‹ÉLc           @   s0  d  Z  d d k Z d d k Z d d k Z d d k Z d d k l Z d d k l Z d d k	 l
 Z
 l Z d d k l Z d d k l Z d d k l Z d d	 k l Z d d
 k l Z d Z d Z d „  Z d e i f d „  ƒ  YZ d e f d „  ƒ  YZ d e
 f d „  ƒ  YZ d e f d „  ƒ  YZ d S(   s.   Fields required for handling translation filesiÿÿÿÿN(   t   settings(   t   models(   t	   FieldFilet	   FileField(   t   factory(   t   LRUCachingDict(   t   multistring(   t   translation_file_updated(   t   factory_classess   __%$%__%$%__%$%__s   __%POOTLE%_$NUMEROUS$__c         C   s-   x& |  D] } t  | ƒ d j o t Sq Wt S(   s•   check if list is exclusively made of empty strings.

    useful for detecting empty multistrings and storing them as a
    simple empty string in db.i    (   t   lent   Falset   True(   t   stringst   string(    (    s1   /var/www/Pootle/local_apps/pootle_store/fields.pyt
   list_empty+   s
     	t   MultiStringFieldc           B   sD   e  Z d  Z e i Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 RS(   s=   a field imitating translate.misc.multistring used for pluralsc         O   s   t  t |  ƒ i | | Ž  d  S(   N(   t   superR   t   __init__(   t   selft   argst   kwargs(    (    s1   /var/www/Pootle/local_apps/pootle_store/fields.pyR   9   s    c         C   s   d S(   Nt	   TextField(    (   R   (    (    s1   /var/www/Pootle/local_apps/pootle_store/fields.pyt   get_internal_type<   s    c         C   s  | p t  d d d ƒSt | t  ƒ o | St | t ƒ of | i t ƒ } | d t j o | d  } t } n t | ƒ d j } t  | d d ƒ} | | _ | St | t	 ƒ o> t  g  } t
 | i ƒ  ƒ D] \ } } | | qÍ ~ d d ƒSt  | d d ƒSd  S(   Nt    t   encodings   UTF-8iÿÿÿÿi   (   R   t
   isinstancet
   basestringt   splitt	   SEPERATORt   PLURAL_PLACEHOLDERR   R	   t   pluralt   dictt   sortedt   items(   R   t   valueR   R   t   mst   _[1]t   keyt   val(    (    s1   /var/www/Pootle/local_apps/pootle_store/fields.pyt	   to_python?   s     

	>c         C   s†   | d  j o d  St | t ƒ o) t | i ƒ o d St i | i ƒ Sn8 t | t ƒ o# t | ƒ o d St i | ƒ Sn | Sd  S(   NR   (   t   NoneR   R   R   R   R   t   joint   list(   R   R"   (    (    s1   /var/www/Pootle/local_apps/pootle_store/fields.pyt   get_db_prep_valueS   s    c         C   sJ   | d j p t  | t ƒ o |  i | ƒ } n t t |  ƒ i | | ƒ S(   Nt   exactt   iexact(   s   exacts   iexact(   R   R   R+   R   R   t   get_db_prep_lookup(   R   t   lookup_typeR"   (    (    s1   /var/www/Pootle/local_apps/pootle_store/fields.pyR.   d   s    (   t   __name__t
   __module__t   descriptionR   t   SubfieldBaset   __metaclass__R   R   R'   R+   R.   (    (    (    s1   /var/www/Pootle/local_apps/pootle_store/fields.pyR   5   s   					t
   StoreTuplec           B   s   e  Z d  Z d „  Z RS(   s¦   Encapsulates toolkit stores in the in memory cache, needed
    since LRUCachingDict is based on a weakref.WeakValueDictionary
    which cannot reference normal tuplesc         C   s   | |  _  | |  _ | |  _ d  S(   N(   t   storet   mod_infot   realpath(   R   R6   R7   R8   (    (    s1   /var/www/Pootle/local_apps/pootle_store/fields.pyR   p   s    		(   R0   R1   t   __doc__R   (    (    (    s1   /var/www/Pootle/local_apps/pootle_store/fields.pyR5   l   s   t   TranslationStoreFieldFilec           B   s°   e  Z d  Z e e i e i ƒ Z d „  Z d „  Z	 e
 e	 ƒ Z d „  Z d „  Z e
 e ƒ Z d „  Z d „  Z d „  Z d „  Z e
 e ƒ Z d	 „  Z e d
 „ Z e d „ Z RS(   s_   FieldFile is the File-like object of a FileField, that is found in a
    TranslationStoreField.c         C   s"   t  i |  i ƒ } | i | i f S(   N(   t   ost   statR8   t   st_mtimet   st_size(   R   t	   file_stat(    (    s1   /var/www/Pootle/local_apps/pootle_store/fields.pyt
   getpomtime{   s    c         C   s   t  i i |  i ƒ S(   N(   R;   t   patht   basenamet   name(   R   (    (    s1   /var/www/Pootle/local_apps/pootle_store/fields.pyt   _get_filename   s    c         C   s3   t  |  d ƒ p t i i |  i ƒ |  _ n |  i S(   s0   return realpath resolving symlinks if neccessaryt	   _realpath(   t   hasattrR;   RA   R8   RE   (   R   (    (    s1   /var/www/Pootle/local_apps/pootle_store/fields.pyt   _get_realpathƒ   s    c         C   s)   t  |  d ƒ p |  i ƒ  S|  i i Sd S(   s@   get real path from cache before attempting to check for symlinkst   _store_tupleN(   RF   RG   RH   R8   (   R   (    (    s1   /var/www/Pootle/local_apps/pootle_store/fields.pyt   _get_cached_realpath‰   s    c         C   s   |  i  ƒ  |  i i S(   sZ   Get translation store from dictionary cache, populate if store not
        already cached.(   t   _update_store_cacheRH   R6   (   R   (    (    s1   /var/www/Pootle/local_apps/pootle_store/fields.pyt
   _get_store‘   s    
c         C   s÷   |  i  ƒ  } t |  d ƒ p |  i i | j oÃ y4 |  i |  i |  _ |  i i | j o
 t ‚ n Wqó t j
 o| t i d |  i ƒ t	 t
 i |  i d |  i i d t ƒ| |  i ƒ |  _ |  i |  i |  i <t i d |  d |  i ƒ qó Xn d S(   sX   Add translation store to dictionary cache, replace old cached
        version if needed.t   _store_typleu   cache miss for %st   ignoret   classest   senderRA   N(   R@   RF   RH   R7   t   _store_cacheRA   t   KeyErrort   loggingt   debugR5   R   t	   getobjectt   fieldRM   R   R8   R   t   send(   R   R7   (    (    s1   /var/www/Pootle/local_apps/pootle_store/fields.pyRJ   —   s    $$c         C   sj   t  |  d ƒ oL |  i ƒ  } |  i i | j o) | |  i _ t i d |  d |  i ƒ qf n |  i ƒ  d S(   s.   Update stored mod_info without reparsing file.RH   RO   RA   N(   RF   R@   RH   R7   R   RV   RA   RJ   (   R   R7   (    (    s1   /var/www/Pootle/local_apps/pootle_store/fields.pyt   _touch_store_cache©   s    !c         C   sd   y |  i  |  i =Wn t j
 o n Xy
 |  ` Wn t j
 o n Xt i d |  d |  i ƒ d S(   s$   Remove translation store from cache.RO   RA   N(   RP   RA   RQ   RH   t   AttributeErrorR   RV   (   R   (    (    s1   /var/www/Pootle/local_apps/pootle_store/fields.pyt   _delete_store_cacheµ   s    
c         C   sY   t  i d |  i ƒ \ } } t i | ƒ |  i i | ƒ t i | |  i	 ƒ |  i
 ƒ  d S(   sf   Saves to temporary file then moves over original file. This
        way we avoid the need for locking.t   suffixN(   t   tempfilet   mkstempt   filenameR;   t   closeR6   t   savefilet   shutilt   moveR8   RW   (   R   t   tmpfilet   tmpfilename(    (    s1   /var/www/Pootle/local_apps/pootle_store/fields.pyt	   savestoreÅ   s
    c         C   s*   t  t |  ƒ i | | | ƒ |  i ƒ  d  S(   N(   R   R:   t   saveRY   (   R   RC   t   contentRe   (    (    s1   /var/www/Pootle/local_apps/pootle_store/fields.pyRe   Î   s    c         C   s/   |  i  ƒ  | o t t |  ƒ i | ƒ n d  S(   N(   RY   R   R:   t   delete(   R   Re   (    (    s1   /var/www/Pootle/local_apps/pootle_store/fields.pyRg   Ó   s    
(   R0   R1   R9   R   R    t   PARSE_POOL_SIZEt   PARSE_POOL_CULL_FREQUENCYRP   R@   RD   t   propertyR]   RG   RI   R8   RK   RJ   RW   RY   R6   Rd   R   Re   Rg   (    (    (    s1   /var/www/Pootle/local_apps/pootle_store/fields.pyR:   u   s    										t   TranslationStoreFieldc           B   s    e  Z d  Z e Z d d „ Z RS(   sd   This is the field class to represent a FileField in a model that
    represents a translation store.c         K   s#   | |  _  t t |  ƒ i |   d S(   s€   ignore: postfix to be stripped from filename when trying to
        determine file format for parsing, useful for .pending filesN(   RM   R   Rk   R   (   R   RM   R   (    (    s1   /var/www/Pootle/local_apps/pootle_store/fields.pyR   ß   s    	N(   R0   R1   R9   R:   t
   attr_classR(   R   (    (    (    s1   /var/www/Pootle/local_apps/pootle_store/fields.pyRk   Ù   s   (   R9   RR   R`   R[   R;   t   django.confR    t	   django.dbR   t   django.db.models.fields.filesR   R   t   translate.storageR   t   translate.misc.lruR   t   translate.misc.multistringR   t   pootle_store.signalsR   t   pootle_store.filetypesR   R   R   R   t   FieldR   t   objectR5   R:   Rk   (    (    (    s1   /var/www/Pootle/local_apps/pootle_store/fields.pyt   <module>   s&   	
7	d