ó
åŽ‹]c           @   sÍ   d  d l  Z  d  d l m Z m Z m Z m Z d  d l m Z m Z m	 Z	 m
 Z
 m Z m Z d  d l m Z m Z d e f d „  ƒ  YZ e  j e ƒ d e e f d „  ƒ  Yƒ Z d	 e j f d
 „  ƒ  YZ d S(   iÿÿÿÿN(   t   CheckedTypet   _restore_picklet   InvariantExceptiont   store_invariants(   t
   set_fieldst
   check_typet   is_field_ignore_extra_complaintt   PFIELD_NO_INITIALt	   serializet   check_global_invariants(   t   PMapt   pmapt   _PRecordMetac           B   s   e  Z d  „  Z RS(   c         C   s—   t  | | d d ƒt | | d d ƒ t d „  | d j ƒ  Dƒ ƒ | d <t d „  | d j ƒ  Dƒ ƒ | d <d
 | d	 <t t |  ƒ j |  | | | ƒ S(   Nt   namet   _precord_fieldst   _precord_invariantst   __invariant__c         s   s$   |  ] \ } } | j  r | Vq d  S(   N(   t	   mandatory(   t   .0R   t   field(    (    s2   lib/python2.7/site-packages/pyrsistent/_precord.pys	   <genexpr>   s    t   _precord_mandatory_fieldsc         s   s3   |  ]) \ } } | j  t k	 r | | j  f Vq d  S(   N(   t   initialR   (   R   t   kR   (    (    s2   lib/python2.7/site-packages/pyrsistent/_precord.pys	   <genexpr>   s    t   _precord_initial_valuest	   __slots__(    (   R   R   t   sett   itemst   dictt   superR   t   __new__(   t   mcsR   t   basest   dct(    (    s2   lib/python2.7/site-packages/pyrsistent/_precord.pyR   
   s    $$
(   t   __name__t
   __module__R   (    (    (    s2   lib/python2.7/site-packages/pyrsistent/_precord.pyR   	   s   t   PRecordc           B   s\   e  Z d  Z d „  Z d „  Z d „  Z d „  Z e d e	 d „ ƒ Z
 d „  Z d d „ Z RS(	   su  
    A PRecord is a PMap with a fixed set of specified fields. Records are declared as python classes inheriting
    from PRecord. Because it is a PMap it has full support for all Mapping methods such as iteration and element
    access using subscript notation.

    More documentation and examples of PRecord usage is available at https://github.com/tobgu/pyrsistent
    c         K   sí   d | k r< d | k r< t  t |  ƒ j |  | d | d ƒ S| j d d  ƒ } | j d t ƒ } | } |  j rž t d „  |  j j ƒ  Dƒ ƒ } | j	 | ƒ n  t
 |  t ƒ  d | d | ƒ} x$ | j ƒ  D] \ } } | | | <qÉ W| j ƒ  S(   Nt   _precord_sizet   _precord_bucketst   _factory_fieldst   _ignore_extrac         s   s6   |  ], \ } } | t  | ƒ r' | ƒ  n | f Vq d  S(   N(   t   callable(   R   R   t   v(    (    s2   lib/python2.7/site-packages/pyrsistent/_precord.pys	   <genexpr>/   s   (   R   R#   R   t   popt   Nonet   FalseR   R   R   t   updatet   _PRecordEvolverR   t
   persistent(   t   clst   kwargst   factory_fieldst   ignore_extrat   initial_valuest   eR   R)   (    (    s2   lib/python2.7/site-packages/pyrsistent/_precord.pyR   #   s    $		c         O   s4   | r' t  t |  ƒ j | d | d ƒ S|  j | ƒ S(   s  
        Set a field in the record. This set function differs slightly from that in the PMap
        class. First of all it accepts key-value pairs. Second it accepts multiple key-value
        pairs to perform one, atomic, update of multiple fields.
        i    i   (   R   R#   R   R-   (   t   selft   argsR1   (    (    s2   lib/python2.7/site-packages/pyrsistent/_precord.pyR   9   s    	!c         C   s   t  |  j |  ƒ S(   s4   
        Returns an evolver of this object.
        (   R.   t	   __class__(   R6   (    (    s2   lib/python2.7/site-packages/pyrsistent/_precord.pyt   evolverG   s    c         C   s/   d j  |  j j d j d „  |  j ƒ  Dƒ ƒ ƒ S(   Ns   {0}({1})s   , c         s   s-   |  ]# \ } } d  j  | t | ƒ ƒ Vq d S(   s   {0}={1}N(   t   formatt   repr(   R   R   R)   (    (    s2   lib/python2.7/site-packages/pyrsistent/_precord.pys	   <genexpr>O   s    (   R:   R8   R!   t   joinR   (   R6   (    (    s2   lib/python2.7/site-packages/pyrsistent/_precord.pyt   __repr__M   s    c            sK   t  ˆ  |  ƒ r ˆ  S| r5 ‡  f d †  |  j Dƒ ‰  n  |  d | d | ˆ   S(   s<  
        Factory method. Will create a new PRecord of the current type and assign the values
        specified in kwargs.

        :param ignore_extra: A boolean which when set to True will ignore any keys which appear in kwargs that are not
                             in the set of fields on the PRecord.
        c            s)   i  |  ] } | ˆ  k r ˆ  | | “ q S(    (    (   R   R   (   R1   (    s2   lib/python2.7/site-packages/pyrsistent/_precord.pys
   <dictcomp>^   s   	 R&   R'   (   t
   isinstanceR   (   R0   R1   R&   R3   (    (   R1   s2   lib/python2.7/site-packages/pyrsistent/_precord.pyt   createQ   s
    	c         C   s   t  |  j t |  ƒ f f S(   N(   R   R8   R   (   R6   (    (    s2   lib/python2.7/site-packages/pyrsistent/_precord.pyt
   __reduce__b   s    c            s#   t  ‡  ‡ f d †  ˆ j ƒ  Dƒ ƒ S(   sƒ   
        Serialize the current PRecord using custom serializer functions for fields where
        such have been supplied.
        c         3   s7   |  ]- \ } } | t  ˆ j | j ˆ  | ƒ f Vq d  S(   N(   R   R   t
   serializer(   R   R   R)   (   R:   R6   (    s2   lib/python2.7/site-packages/pyrsistent/_precord.pys	   <genexpr>k   s    (   R   R   (   R6   R:   (    (   R:   R6   s2   lib/python2.7/site-packages/pyrsistent/_precord.pyR   f   s    N(   R!   R"   t   __doc__R   R   R9   R=   t   classmethodR+   R,   R?   R@   R   (    (    (    s2   lib/python2.7/site-packages/pyrsistent/_precord.pyR#      s   					R.   c           B   s8   e  Z d	 Z d
 e d „ Z d „  Z d „  Z d „  Z RS(   t   _destination_clst   _invariant_error_codest   _missing_fieldsR&   R'   c         C   sG   t  t |  ƒ j | ƒ | |  _ g  |  _ g  |  _ | |  _ | |  _ d  S(   N(   R   R.   t   __init__RD   RE   RF   R&   R'   (   R6   R0   t   original_pmapR&   R'   (    (    s2   lib/python2.7/site-packages/pyrsistent/_precord.pyRG   q   s    				c         C   s   |  j  | | ƒ d  S(   N(   R   (   R6   t   keyt   original_value(    (    s2   lib/python2.7/site-packages/pyrsistent/_precord.pyt   __setitem__y   s    c         C   s?  |  j  j j | ƒ } | r|  j d  k s9 | |  j k rº yC t t | |  j ƒ rl | j | d |  j ƒ} n | j | ƒ } WqÀ t	 k
 r¶ } |  j
 | j 7_
 |  j | j 7_ |  SXn | } t |  j  | | | ƒ | j | ƒ \ } } | s|  j
 j | ƒ n  t t |  ƒ j | | ƒ St d j | |  j  j ƒ ƒ ‚ d  S(   NR3   s/   '{0}' is not among the specified fields for {1}(   RD   R   t   getR&   R+   R   R#   R'   t   factoryR   RE   t   invariant_errorsRF   t   missing_fieldsR   t	   invariantt   appendR   R.   R   t   AttributeErrorR:   R!   (   R6   RI   RJ   R   t   valueR5   t   is_okt
   error_code(    (    s2   lib/python2.7/site-packages/pyrsistent/_precord.pyR   |   s$    c            sõ   |  j  ‰  |  j ƒ  } t t |  ƒ j ƒ  } | s@ t | ˆ  ƒ r^ ˆ  d | j d | j ƒ } n | } ˆ  j r¨ |  j	 t
 ‡  f d †  ˆ  j t | j ƒ  ƒ Dƒ ƒ 7_	 n  |  j sº |  j	 rá t t
 |  j ƒ t
 |  j	 ƒ d ƒ ‚ n  t | ˆ  j ƒ | S(   NR%   R$   c         3   s$   |  ] } d  j  ˆ  j | ƒ Vq d S(   s   {0}.{1}N(   R:   R!   (   R   t   f(   R0   (    s2   lib/python2.7/site-packages/pyrsistent/_precord.pys	   <genexpr>    s    s   Field invariant failed(   RD   t   is_dirtyR   R.   R/   R>   t   _bucketst   _sizeR   RF   t   tupleR   t   keysRE   R   R	   R   (   R6   RW   t   pmt   result(    (   R0   s2   lib/python2.7/site-packages/pyrsistent/_precord.pyR/   –   s    		%(   RD   RE   RF   R&   R'   N(	   R!   R"   R   R+   R,   RG   RK   R   R/   (    (    (    s2   lib/python2.7/site-packages/pyrsistent/_precord.pyR.   n   s
   		(   t   sixt   pyrsistent._checked_typesR    R   R   R   t   pyrsistent._field_commonR   R   R   R   R   R	   t   pyrsistent._pmapR
   R   t   typeR   t   add_metaclassR#   t   _EvolverR.   (    (    (    s2   lib/python2.7/site-packages/pyrsistent/_precord.pyt   <module>   s   ".S