Ñò
‹T6Jc           @   só   d  d k  Z  d  d k 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  d k l Z d e f d	 „  ƒ  YZ d
 e f d „  ƒ  YZ d e i f d „  ƒ  YZ d e i f d „  ƒ  YZ d e i f d „  ƒ  YZ d S(   iÿÿÿÿN(   t   datetime(   t   settings(   t   DjangoJSONEncoder(   t   models(   t
   simplejson(   t   smart_unicodet   Base64DecodedValuec           B   s   e  Z d  Z RS(   s   
    A subclass of string that can be identified by Base64Field, in order
    to prevent double-encoding or double-decoding.
    (   t   __name__t
   __module__t   __doc__(    (    (    s4   /var/www/Pootle/external_apps/djblets/util/fields.pyR   %   s   t   Base64FieldCreatorc           B   s&   e  Z d  „  Z d „  Z d d „ Z RS(   c         C   s   | |  _  d  S(   N(   t   field(   t   selfR   (    (    s4   /var/www/Pootle/external_apps/djblets/util/fields.pyt   __init__.   s    c         C   s   | i  | i i ƒ } | d  j	 o t | ƒ d j } t | t ƒ p | o  t i | ƒ | i	 |  i
 i <n | | i	 |  i
 i <t | d |  i
 i t ƒ d  S(   Nu    s
   %s_initted(   t   _get_pk_valt	   __class__t   _metat   NoneR   t
   isinstanceR   t   base64t   encodestringt   __dict__R   t   namet   setattrt   True(   R   t   objt   valuet   pk_valt   pk_set(    (    s4   /var/www/Pootle/external_apps/djblets/util/fields.pyt   __set__1   s     c         C   sY   | d  j o t d ƒ ‚ n | i |  i i } | d  j o d  St t i | ƒ ƒ Sd  S(   Ns%   Can only be accessed via an instance.(   R   t   AttributeErrorR   R   R   R   R   t   decodestring(   R   R   t   typeR   (    (    s4   /var/www/Pootle/external_apps/djblets/util/fields.pyt   __get__<   s    N(   R   R   R   R   R   R!   (    (    (    s4   /var/www/Pootle/external_apps/djblets/util/fields.pyR
   -   s   		t   Base64Fieldc           B   sA   e  Z d  Z e Z d „  Z d „  Z d „  Z d „  Z d „  Z	 RS(   s  
    A subclass of TextField that encodes its data as base64 in the database.
    This is useful if you're dealing with unknown encodings and must guarantee
    that no modifications to the text occurs and that you can read/write
    the data in any database with any encoding.
    c         C   s6   t  t |  ƒ i | | ƒ t | |  i t |  ƒ ƒ d  S(   N(   t   superR"   t   contribute_to_classR   R   R
   (   R   t   clsR   (    (    s4   /var/www/Pootle/external_apps/djblets/util/fields.pyR$   Q   s    c         C   s'   t  | t ƒ o t i | ƒ } n | S(   N(   R   R   R   R   (   R   R   (    (    s4   /var/www/Pootle/external_apps/djblets/util/fields.pyt   get_db_prep_valueU   s    c         C   s   t  | |  i t | ƒ ƒ d  S(   N(   R   R   R   (   R   t   instancet   data(    (    s4   /var/www/Pootle/external_apps/djblets/util/fields.pyt   save_form_data[   s    c         C   s,   t  | t ƒ o | St t i | ƒ ƒ Sd  S(   N(   R   R   R   R   (   R   R   (    (    s4   /var/www/Pootle/external_apps/djblets/util/fields.pyt	   to_python^   s    c         C   s5   |  i  | ƒ } t | t ƒ o t i | ƒ S| Sd  S(   N(   t   _get_val_from_objR   R   R   R   (   R   R   R   (    (    s4   /var/www/Pootle/external_apps/djblets/util/fields.pyt   value_to_stringd   s    (
   R   R   R	   R   t   serialize_to_stringR$   R&   R)   R*   R,   (    (    (    s4   /var/www/Pootle/external_apps/djblets/util/fields.pyR"   H   s   				t   ModificationTimestampFieldc           B   s/   e  Z d  Z d d d „ Z d „  Z d „  Z RS(   sC  
    A subclass of DateTimeField that only auto-updates the timestamp when
    updating an existing object or when the value of the field is None. This
    specialized field is equivalent to DateTimeField's auto_now=True, except
    it allows for custom timestamp values (needed for
    serialization/deserialization).
    c         K   s8   | i  h t d 6t d 6ƒ t i i |  | | |  d  S(   Nt   editablet   blank(   t   updatet   FalseR   R   t   DateTimeFieldR   (   R   t   verbose_nameR   t   kwargs(    (    s4   /var/www/Pootle/external_apps/djblets/util/fields.pyR   u   s    	c         C   s^   | p t  | |  i ƒ d  j o$ t i ƒ  } t | |  i | ƒ | St t |  ƒ i | | ƒ S(   N(	   t   getattrt   attnameR   R    t   nowR   R#   R.   t   pre_save(   R   t   modelt   addR   (    (    s4   /var/www/Pootle/external_apps/djblets/util/fields.pyR9   |   s
    !c         C   s   d S(   NR3   (    (   R   (    (    s4   /var/www/Pootle/external_apps/djblets/util/fields.pyt   get_internal_type„   s    N(   R   R   R	   R   R   R9   R<   (    (    (    s4   /var/www/Pootle/external_apps/djblets/util/fields.pyR.   m   s   	t	   JSONFieldc           B   st   e  Z d  Z e Z d
 d
 e ƒ  d „ Z d „  Z d „  Z	 d „  Z
 d
 d „ Z d „  Z d „  Z d „  Z d	 „  Z RS(   s¹   
    A field for storing JSON-encoded data. The data is accessible as standard
    Python data types and is transparently encoded/decoded to/from a JSON
    string in the database.
    c         K   s,   t  i i |  | | d t | | |  _ d  S(   NR0   (   R   t	   TextFieldR   R   t   encoder(   R   R4   R   R?   R5   (    (    s4   /var/www/Pootle/external_apps/djblets/util/fields.pyR      s    c         C   s   d S(   Nt   text(    (   R   (    (    s4   /var/www/Pootle/external_apps/djblets/util/fields.pyt   db_type–   s    c            s…   ‡  f d †  } ‡  f d †  } t  t ˆ  ƒ i | | ƒ t | d ˆ  i | ƒ t | d ˆ  i | ƒ t i i i ˆ  i d | ƒd  S(   Nc            s   ˆ  i  t |  ˆ  i d  ƒ ƒ S(   N(   t   dumpsR6   R7   R   (   t   model_instance(   R   (    s4   /var/www/Pootle/external_apps/djblets/util/fields.pyt   get_jsonš   s    c            s    t  |  ˆ  i ˆ  i | ƒ ƒ d  S(   N(   R   R7   t   loads(   RC   t   json(   R   (    s4   /var/www/Pootle/external_apps/djblets/util/fields.pyt   set_json   s    s   get_%s_jsons   set_%s_jsont   sender(	   R#   R=   R$   R   R   R   t   signalst	   post_initt   connect(   R   R%   R   RD   RG   (    (   R   s4   /var/www/Pootle/external_apps/djblets/util/fields.pyR$   ™   s    c         C   s   |  i  t | |  i d  ƒ ƒ S(   N(   RB   R6   R7   R   (   R   RC   R;   (    (    s4   /var/www/Pootle/external_apps/djblets/util/fields.pyR9   §   s    c         K   sF   |  i  | ƒ } | o |  i | ƒ } n h  } t | |  i | ƒ d  S(   N(   t   value_from_objectRE   R   R7   (   R   R'   R5   R   (    (    s4   /var/www/Pootle/external_apps/djblets/util/fields.pyRJ   ª   s
    c         C   s9   t  | t ƒ p |  i | ƒ } n t t |  ƒ i | ƒ S(   N(   R   t
   basestringRB   R#   R=   t   get_db_prep_save(   R   R   (    (    s4   /var/www/Pootle/external_apps/djblets/util/fields.pyRN   ´   s    c         C   s   |  i  |  i | ƒ ƒ S(   N(   RB   RL   (   R   R   (    (    s4   /var/www/Pootle/external_apps/djblets/util/fields.pyR,   º   s    c         C   s   |  i  i | ƒ S(   N(   R?   t   encode(   R   R(   (    (    s4   /var/www/Pootle/external_apps/djblets/util/fields.pyRB   ½   s    c         C   s   yY t  i | d t i ƒ} t | t ƒ o- t i d | ƒ t  i | d t i ƒ} n Wn t j
 o t	 | ƒ } n X| S(   Nt   encodingsF   JSONField decode error. Expected dictionary, got string for input '%s'(
   R   RE   R   t   DEFAULT_CHARSETR   RM   t   loggingt   warningt
   ValueErrort   eval(   R   t   val(    (    s4   /var/www/Pootle/external_apps/djblets/util/fields.pyRE   À   s    	 N(   R   R   R	   R   R-   R   R   R   RA   R$   R9   RJ   RN   R,   RB   RE   (    (    (    s4   /var/www/Pootle/external_apps/djblets/util/fields.pyR=   ˆ   s   			
			(   R   RR   R    t   django.confR   t   django.core.serializers.jsonR   t	   django.dbR   t   django.utilsR   t   django.utils.encodingR   t   strR   t   objectR
   R>   R"   R3   R.   R=   (    (    (    s4   /var/www/Pootle/external_apps/djblets/util/fields.pyt   <module>   s   %