ó
Ý²k^c           @` sB  d  Z  d d l m Z m Z m Z y d d l m Z m Z Wn' e k
 re d d l	 m Z m Z n Xd d l
 m
 Z
 d d l m Z d d l m Z m Z 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 m Z m Z d	 d l m  Z  m! Z! m" Z" m# Z# m$ Z$ m% Z% m& Z& m' Z' d	 d l( m) Z) m* Z* d	 d l+ m, Z, d	 d l- m. Z. d	 d l/ m0 Z0 e e1 ƒ Z2 d d d d d d d d d d d d d d g Z3 d  Z4 d! Z5 d e6 f d" „  ƒ  YZ7 d e7 f d# „  ƒ  YZ8 e8 Z9 d e7 f d$ „  ƒ  YZ: e: Z; d e7 f d% „  ƒ  YZ< d e7 f d& „  ƒ  YZ= d e7 f d' „  ƒ  YZ> d e7 f d( „  ƒ  YZ? d e7 f d) „  ƒ  YZ@ d* e@ f d+ „  ƒ  YZA d e7 f d, „  ƒ  YZB d e7 f d- „  ƒ  YZC d. eD f d/ „  ƒ  YZE e' eE ƒ d e6 f d0 „  ƒ  Yƒ ZF d eF f d1 „  ƒ  YZG d2 e6 f d3 „  ƒ  YZH d4 e f d5 „  ƒ  YZI d6 S(7   sé  
This module provides serializable, validatable, type-enforcing domain objects and data
transfer objects. It has many of the same motivations as the python
`Marshmallow <http://marshmallow.readthedocs.org/en/latest/why.html>`_ package. It is most
similar to `Schematics <http://schematics.readthedocs.io/>`_.

========
Tutorial
========

Chapter 1: Entity and Field Basics
----------------------------------

    >>> class Color(Enum):
    ...     blue = 0
    ...     black = 1
    ...     red = 2
    >>> class Car(Entity):
    ...     weight = NumberField(required=False)
    ...     wheels = IntField(default=4, validation=lambda x: 3 <= x <= 4)
    ...     color = EnumField(Color)

    >>> # create a new car object
    >>> car = Car(color=Color.blue, weight=4242.46)
    >>> car
    Car(weight=4242.46, color=0)

    >>> # it has 4 wheels, all by default
    >>> car.wheels
    4

    >>> # but a car can't have 5 wheels!
    >>> #  the `validation=` field is a simple callable that returns a
    >>> #  boolean based on validity
    >>> car.wheels = 5
    Traceback (most recent call last):
    ValidationError: Invalid value 5 for wheels

    >>> # we can call .dump() on car, and just get back a standard
    >>> #  python dict actually, it's an ordereddict to match attribute
    >>> #  declaration order
    >>> type(car.dump())
    <class '...OrderedDict'>
    >>> car.dump()
    OrderedDict([('weight', 4242.46), ('wheels', 4), ('color', 0)])

    >>> # and json too (note the order!)
    >>> car.json()
    '{"weight": 4242.46, "wheels": 4, "color": 0}'

    >>> # green cars aren't allowed
    >>> car.color = "green"
    Traceback (most recent call last):
    ValidationError: 'green' is not a valid Color

    >>> # but black cars are!
    >>> car.color = "black"
    >>> car.color
    <Color.black: 1>

    >>> # car.color really is an enum, promise
    >>> type(car.color)
    <enum 'Color'>

    >>> # enum assignment can be with any of (and preferentially)
    >>> #   (1) an enum literal,
    >>> #   (2) a valid enum value, or
    >>> #   (3) a valid enum name
    >>> car.color = Color.blue; car.color.value
    0
    >>> car.color = 1; car.color.name
    'black'

    >>> # let's do a round-trip marshalling of this thing
    >>> same_car = Car.from_json(car.json())  # or equally Car.from_json(json.dumps(car.dump()))
    >>> same_car == car
    True

    >>> # actually, they're two different instances
    >>> same_car is not car
    True

    >>> # this works too
    >>> cloned_car = Car(**car.dump())
    >>> cloned_car == car
    True

    >>> # while we're at it, these are all equivalent too
    >>> car == Car.from_objects(car)
    True
    >>> car == Car.from_objects({"weight": 4242.46, "wheels": 4, "color": 1})
    True
    >>> car == Car.from_json('{"weight": 4242.46, "color": 1}')
    True

    >>> # .from_objects() even lets you stack and combine objects
    >>> class DumbClass:
    ...     color = 0
    ...     wheels = 3
    >>> Car.from_objects(DumbClass(), dict(weight=2222, color=1))
    Car(weight=2222, wheels=3, color=0)
    >>> # and also pass kwargs that override properties pulled
    >>> #  off any objects
    >>> Car.from_objects(DumbClass(), {'weight': 2222, 'color': 1}, color=2, weight=33)
    Car(weight=33, wheels=3, color=2)


Chapter 2: Entity and Field Composition
---------------------------------------

    >>> # now let's get fancy
    >>> # a ComposableField "nests" another valid Entity
    >>> # a ListField's first argument is a "generic" type,
    >>> #   which can be a valid Entity, any python primitive
    >>> #   type, or a list of Entities/types
    >>> class Fleet(Entity):
    ...     boss_car = ComposableField(Car)
    ...     cars = ListField(Car)

    >>> # here's our fleet of company cars
    >>> company_fleet = Fleet(boss_car=Car(color='red'), cars=[car, same_car, cloned_car])
    >>> company_fleet.pretty_json()  #doctest: +SKIP
    {
      "boss_car": {
        "wheels": 4
        "color": 2,
      },
      "cars": [
        {
          "weight": 4242.46,
          "wheels": 4
          "color": 1,
        },
        {
          "weight": 4242.46,
          "wheels": 4
          "color": 1,
        },
        {
          "weight": 4242.46,
          "wheels": 4
          "color": 1,
        }
      ]
    }

    >>> # the boss' car is red of course (and it's still an Enum)
    >>> company_fleet.boss_car.color.name
    'red'

    >>> # and there are three cars left for the employees
    >>> len(company_fleet.cars)
    3


Chapter 3: Immutability
-----------------------

    >>> class ImmutableCar(ImmutableEntity):
    ...     wheels = IntField(default=4, validation=lambda x: 3 <= x <= 4)
    ...     color = EnumField(Color)
    >>> icar = ImmutableCar.from_objects({'wheels': 3, 'color': 'blue'})
    >>> icar
    ImmutableCar(wheels=3, color=0)

    >>> icar.wheels = 4
    Traceback (most recent call last):
    AttributeError: Assignment not allowed. ImmutableCar is immutable.

    >>> class FixedWheelCar(Entity):
    ...     wheels = IntField(default=4, immutable=True)
    ...     color = EnumField(Color)
    >>> fwcar = FixedWheelCar.from_objects(icar)
    >>> fwcar.json()
    '{"wheels": 3, "color": 0}'

    >>> # repainting the car is easy
    >>> fwcar.color = Color.red
    >>> fwcar.color.name
    'red'

    >>> # can't really change the number of wheels though
    >>> fwcar.wheels = 18
    Traceback (most recent call last):
    AttributeError: The wheels field is immutable.


Chapter X: The del and null Weeds
---------------------------------

    >>> old_date = lambda: isoparse('1982-02-17')
    >>> class CarBattery(Entity):
    ...     # NOTE: default value can be a callable!
    ...     first_charge = DateField(required=False)  # default=None, nullable=False
    ...     latest_charge = DateField(default=old_date, nullable=True)  # required=True
    ...     expiration = DateField(default=old_date, required=False, nullable=False)

    >>> # starting point
    >>> battery = CarBattery()
    >>> battery
    CarBattery()
    >>> battery.json()
    '{"latest_charge": "1982-02-17T00:00:00", "expiration": "1982-02-17T00:00:00"}'

    >>> # first_charge is not assigned a default value. Once one is assigned, it can be deleted,
    >>> #   but it can't be made null.
    >>> battery.first_charge = isoparse('2016-03-23')
    >>> battery
    CarBattery(first_charge=datetime.datetime(2016, 3, 23, 0, 0))
    >>> battery.first_charge = None
    Traceback (most recent call last):
    ValidationError: Value for first_charge not given or invalid.
    >>> del battery.first_charge
    >>> battery
    CarBattery()

    >>> # latest_charge can be null, but it can't be deleted. The default value is a callable.
    >>> del battery.latest_charge
    Traceback (most recent call last):
    AttributeError: The latest_charge field is required and cannot be deleted.
    >>> battery.latest_charge = None
    >>> battery.json()
    '{"latest_charge": null, "expiration": "1982-02-17T00:00:00"}'

    >>> # expiration is assigned by default, can't be made null, but can be deleted.
    >>> battery.expiration
    datetime.datetime(1982, 2, 17, 0, 0)
    >>> battery.expiration = None
    Traceback (most recent call last):
    ValidationError: Value for expiration not given or invalid.
    >>> del battery.expiration
    >>> battery.json()
    '{"latest_charge": null}'


i    (   t   absolute_importt   divisiont   print_function(   t   Mappingt   Sequence(   t   datetime(   t   reduce(   t   JSONEncodert   dumpst   loads(   t	   getLogger(   t   Enumi   (   t   NULL(   t   isoparse(   t   AttrDictt
   frozendictt   make_immutable(   t   integer_typest
   isiterablet	   iteritemst
   itervaluest   odictt   string_typest	   text_typet   with_metaclass(   t   Raiset   ValidationError(   t   find_or_raise(   t   DumpEncoder(   t	   maybecallt   Entityt   ImmutableEntityt   Fieldt   BooleanFieldt	   BoolFieldt   IntegerFieldt   IntFieldt   NumberFieldt   StringFieldt	   DateFieldt	   EnumFieldt	   ListFieldt   MapFieldt   ComposableFieldt   __key_overrides__sá  

Current deficiencies to schematics:
  - no get_mock_object method
  - no context-dependent serialization or MultilingualStringType
  - name = StringType(serialized_name='person_name', alternate_names=['human_name'])
  - name = StringType(serialize_when_none=False)
  - more flexible validation error messages
  - field validation can depend on other fields
  - 'roles' containing blacklists for .dump() and .json()
    __roles__ = {
        EntityRole.registered_name: Blacklist('field1', 'field2'),
        EntityRole.another_registered_name: Whitelist('field3', 'field4'),
    }


TODO:
  - alternate field names
  - add dump_if_null field option
  - add help/description parameter to Field
  - consider leveraging slots
  - collect all validation errors before raising
  - Allow returning string error message for validation instead of False
  - profile and optimize
  - use boltons instead of dateutil
  - correctly implement copy and deepcopy on fields and Entity, DictSafeMixin
    http://stackoverflow.com/questions/1500718/what-is-the-right-way-to-override-the-copy-deepcopy-operations-on-an-object-in-p


Optional Field Properties:
  - validation = None
  - default = None
  - required = True
  - in_dump = True
  - nullable = False

Behaviors:
  - Nullable is a "hard" setting, in that the value is either always or never allowed to be None.
  - What happens then if required=False and nullable=False?
      - The object can be init'd without a value (though not with a None value).
        getattr throws AttributeError
      - Any assignment must be not None.


  - Setting a value to None doesn't "unset" a value.  (That's what del is for.)  And you can't
    del a value if required=True, nullable=False, default=None.

  - If a field is not required, del does *not* "unmask" the default value.  Instead, del
    removes the value from the object entirely.  To get back the default value, need to recreate
    the object.  Entity.from_objects(old_object)


  - Disabling in_dump is a "hard" setting, in that with it disabled the field will never get
    dumped.  With it enabled, the field may or may not be dumped depending on its value and other
    settings.

  - Required is a "hard" setting, in that if True, a valid value or default must be provided. None
    is only a valid value or default if nullable is True.

  - In general, nullable means that None is a valid value.
    - getattr returns None instead of raising Attribute error
    - If in_dump, field is given with null value.
    - If default is not None, assigning None clears a previous assignment. Future getattrs return
      the default value.
    - What does nullable mean with default=None and required=True? Does instantiation raise
      an error if assignment not made on init? Can IntField(nullable=True) be init'd?

  - If required=False and nullable=False, field will only be in dump if field!=None.
    Also, getattr raises AttributeError.
  - If required=False and nullable=True, field will be in dump if field==None.

  - If in_dump is True, does default value get dumped:
    - if no assignment, default exists
    - if nullable, and assigned None
  - How does optional validation work with nullable and assigning None?
  - When does gettattr throw AttributeError, and when does it return None?



c        	   B` s  e  Z d  Z d Z e e d e e e e d d „ Z e	 d „  ƒ Z
 d „  Z d „  Z d „  Z d „  Z d „  Z d	 „  Z d
 „  Z d „  Z e	 d „  ƒ Z e	 d „  ƒ Z e	 d „  ƒ Z e	 d „  ƒ Z e	 d „  ƒ Z e	 d „  ƒ Z e	 d „  ƒ Z e	 d „  ƒ Z RS(   s§  
    Fields are doing something very similar to boxing and unboxing
    of c#/java primitives.  __set__ should take a "primitive" or "raw" value and create a "boxed"
    or "programatically useable" value of it.  While __get__ should return the boxed value,
    dump in turn should unbox the value into a primitive or raw value.

    Arguments:
        types_ (primitive literal or type or sequence of types):
        default (any, callable, optional):  If default is callable, it's guaranteed to return a
            valid value at the time of Entity creation.
        required (boolean, optional):
        validation (callable, optional):
        dump (boolean, optional):
    i    c	   	      C` sÅ   | |  _  | |  _ | |  _ | |  _ | |  _ | |  _ | |  _ | t k rW t |  _ nO t	 | ƒ ri | n |  j
 d  d  | ƒ |  _ |  j d  |  j
 d  d  t | ƒ ƒ ƒ t j |  _ t j d 7_ d  S(   Ni   (   t	   _requiredt   _validationt   _in_dumpt   _default_in_dumpt	   _nullablet
   _immutablet   _aliasesR   t   _defaultt   callablet   boxt   Nonet   validateR   R    t   _order_helper(	   t   selft   defaultt   requiredt
   validationt   in_dumpt   default_in_dumpt   nullablet	   immutablet   aliases(    (    s:   lib/python2.7/site-packages/conda/_vendor/auxlib/entity.pyt   __init__w  s    							*%c         C` s3   y |  j  SWn! t k
 r. t j d ƒ ‚  n Xd  S(   NsY   The name attribute has not been set for this field. Call set_name at class creation time.(   t   _namet   AttributeErrort   logt   error(   R:   (    (    s:   lib/python2.7/site-packages/conda/_vendor/auxlib/entity.pyt   name‰  s
    c         C` s   | |  _  |  S(   N(   RD   (   R:   RH   (    (    s:   lib/python2.7/site-packages/conda/_vendor/auxlib/entity.pyt   set_name’  s    	c         C` só   y9 | d  k r( t | t ƒ |  j } n | j |  j } Wns t k
 re t j d ƒ t d ƒ ‚ nJ t k
 r® |  j	 t
 k rœ t d j |  j ƒ ƒ ‚ q¯ t |  j	 ƒ } n X| d  k rà |  j rà t d j |  j ƒ ƒ ‚ n  |  j | | | ƒ S(   Ns3   The name attribute has not been set for this field.s    A value for {0} has not been sets   The {0} field has been deleted.(   R7   t   getattrt   KEY_OVERRIDES_MAPRH   t   __dict__RE   RF   RG   t   KeyErrorR;   R   t   formatR   R@   t   unbox(   R:   t   instancet   instance_typet   val(    (    s:   lib/python2.7/site-packages/conda/_vendor/auxlib/entity.pyt   __get__–  s    c         C` s_   |  j  r- | j r- t d j |  j ƒ ƒ ‚ n  |  j | |  j | | j | ƒ ƒ | j |  j <d  S(   Ns   The {0} field is immutable.(	   RA   t   _initdRE   RN   RH   R8   R6   t	   __class__RL   (   R:   RP   RR   (    (    s:   lib/python2.7/site-packages/conda/_vendor/auxlib/entity.pyt   __set__©  s    c         C` s‡   |  j  r- | j r- t d j |  j ƒ ƒ ‚ nV |  j rQ t d j |  j ƒ ƒ ‚ n2 |  j sm d  | j |  j <n | j j	 |  j d  ƒ d  S(   Ns   The {0} field is immutable.s0   The {0} field is required and cannot be deleted.(
   RA   RT   RE   RN   RH   R<   R@   R7   RL   t   pop(   R:   RP   (    (    s:   lib/python2.7/site-packages/conda/_vendor/auxlib/entity.pyt
   __delete__°  s    			c         C` s   | S(   N(    (   R:   RP   RQ   RR   (    (    s:   lib/python2.7/site-packages/conda/_vendor/auxlib/entity.pyR6   ¿  s    c         C` s   | S(   N(    (   R:   RP   RQ   RR   (    (    s:   lib/python2.7/site-packages/conda/_vendor/auxlib/entity.pyRO   Â  s    c         C` s   | S(   N(    (   R:   RP   RQ   RR   (    (    s:   lib/python2.7/site-packages/conda/_vendor/auxlib/entity.pyt   dumpÅ  s    c         C` s†   t  | |  j ƒ r4 |  j d k s0 |  j | ƒ r4 | S| t k rN |  j rN | S| d k rg |  j rg | St t |  d d ƒ | ƒ ‚ d S(   sj   

        Returns:
            True: if val is valid

        Raises:
            ValidationError
        RH   s   undefined nameN(	   t
   isinstancet   _typeR.   R7   R   R<   R@   R   RJ   (   R:   RP   RR   (    (    s:   lib/python2.7/site-packages/conda/_vendor/auxlib/entity.pyR8   È  s    
0c         C` s   |  j  S(   N(   R-   (   R:   (    (    s:   lib/python2.7/site-packages/conda/_vendor/auxlib/entity.pyR<   Û  s    c         C` s   |  j  S(   N(   R[   (   R:   (    (    s:   lib/python2.7/site-packages/conda/_vendor/auxlib/entity.pyt   typeß  s    c         C` s   |  j  S(   N(   R4   (   R:   (    (    s:   lib/python2.7/site-packages/conda/_vendor/auxlib/entity.pyR;   ã  s    c         C` s   |  j  S(   N(   R/   (   R:   (    (    s:   lib/python2.7/site-packages/conda/_vendor/auxlib/entity.pyR>   ç  s    c         C` s   |  j  S(   N(   R0   (   R:   (    (    s:   lib/python2.7/site-packages/conda/_vendor/auxlib/entity.pyR?   ë  s    c         C` s   |  j  S(   N(   t   is_nullable(   R:   (    (    s:   lib/python2.7/site-packages/conda/_vendor/auxlib/entity.pyR@   ï  s    c         C` s   |  j  S(   N(   R1   (   R:   (    (    s:   lib/python2.7/site-packages/conda/_vendor/auxlib/entity.pyR]   ó  s    c         C` s   |  j  S(   N(   R2   (   R:   (    (    s:   lib/python2.7/site-packages/conda/_vendor/auxlib/entity.pyRA   ÷  s    N(    (   t   __name__t
   __module__t   __doc__R9   R   t   TrueR7   t   FalseRC   t   propertyRH   RI   RS   RV   RX   R6   RO   RY   R8   R<   R\   R;   R>   R?   R@   R]   RA   (    (    (    s:   lib/python2.7/site-packages/conda/_vendor/auxlib/entity.pyR    c  s*   										c           B` s   e  Z e Z d  „  Z RS(   c         C` s   | d  k r d  St | ƒ S(   N(   R7   t   bool(   R:   RP   RQ   RR   (    (    s:   lib/python2.7/site-packages/conda/_vendor/auxlib/entity.pyR6   ÿ  s    (   R^   R_   Rd   R[   R6   (    (    (    s:   lib/python2.7/site-packages/conda/_vendor/auxlib/entity.pyR!   ü  s   c           B` s   e  Z e Z RS(    (   R^   R_   R   R[   (    (    (    s:   lib/python2.7/site-packages/conda/_vendor/auxlib/entity.pyR#     s   c           B` s   e  Z e e e f Z RS(    (   R^   R_   R   t   floatt   complexR[   (    (    (    s:   lib/python2.7/site-packages/conda/_vendor/auxlib/entity.pyR%     s   c           B` s   e  Z e Z d  „  Z RS(   c         C` s    t  | t j ƒ r t | ƒ S| S(   N(   RZ   R%   R[   R   (   R:   RP   RQ   RR   (    (    s:   lib/python2.7/site-packages/conda/_vendor/auxlib/entity.pyR6     s    (   R^   R_   R   R[   R6   (    (    (    s:   lib/python2.7/site-packages/conda/_vendor/auxlib/entity.pyR&     s   c           B` s    e  Z e Z d  „  Z d „  Z RS(   c         C` sM   y! t  | t ƒ r t | ƒ S| SWn% t k
 rH } t | d | ƒ‚ n Xd  S(   Nt   msg(   RZ   R   R   t
   ValueErrorR   (   R:   RP   RQ   RR   t   e(    (    s:   lib/python2.7/site-packages/conda/_vendor/auxlib/entity.pyR6     s    !c         C` s   | d  k r d  S| j ƒ  S(   N(   R7   t	   isoformat(   R:   RP   RQ   RR   (    (    s:   lib/python2.7/site-packages/conda/_vendor/auxlib/entity.pyRY     s    (   R^   R_   R   R[   R6   RY   (    (    (    s:   lib/python2.7/site-packages/conda/_vendor/auxlib/entity.pyR'     s   	c        	   B` s;   e  Z e e d e e e e d d  „ Z d „  Z d „  Z RS(   c
   
   	   C` s\   t  | t ƒ s$ t d  d d ƒ‚ n  | |  _ t t |  ƒ j | | | | | | | |	 ƒ d  S(   NRg   s&   enum_class must be an instance of Enum(   t
   issubclassR   R   R7   R[   t   superR(   RC   (
   R:   t
   enum_classR;   R<   R=   R>   R?   R@   RA   RB   (    (    s:   lib/python2.7/site-packages/conda/_vendor/auxlib/entity.pyRC   %  s
    	c         C` sp   | d  k r d  Sy |  j | ƒ SWnH t k
 rk } y |  j | SWql t k
 rg t | d | ƒ‚ ql Xn Xd  S(   NRg   (   R7   R[   Rh   RM   R   (   R:   RP   RQ   RR   t   e1(    (    s:   lib/python2.7/site-packages/conda/_vendor/auxlib/entity.pyR6   -  s    c         C` s   | d  t f k r d  S| j S(   N(   R7   R   t   value(   R:   RP   RQ   RR   (    (    s:   lib/python2.7/site-packages/conda/_vendor/auxlib/entity.pyRY   ;  s    N(    (	   R^   R_   R   Ra   R7   Rb   RC   R6   RY   (    (    (    s:   lib/python2.7/site-packages/conda/_vendor/auxlib/entity.pyR(   #  s   		c        	   B` sS   e  Z e Z e e d e e e e d d  „ Z d „  Z	 d „  Z
 d „  Z d „  Z RS(   c
   
   	   C` s8   | |  _  t t |  ƒ j | | | | | | | |	 ƒ d  S(   N(   t   _element_typeRl   R)   RC   (
   R:   t   element_typeR;   R<   R=   R>   R?   R@   RA   RB   (    (    s:   lib/python2.7/site-packages/conda/_vendor/auxlib/entity.pyRC   B  s    	c         ` sÏ   | d  k r d  St | t ƒ r: t d j |  j ƒ ƒ ‚ n‘ t | ƒ r­ |  j ‰  t ˆ  t ƒ rŠ t	 ˆ  t
 ƒ rŠ |  j ‡  f d †  | Dƒ ƒ S|  j r t | ƒ S|  j | ƒ Sn t | d d j |  j ƒ ƒ‚ d  S(   Ns-   Attempted to assign a string to ListField {0}c         3` s0   |  ]& } t  | ˆ  ƒ r | n	 ˆ  |   Vq d  S(   N(   RZ   (   t   .0t   v(   t   et(    s:   lib/python2.7/site-packages/conda/_vendor/auxlib/entity.pys	   <genexpr>Q  s    Rg   s)   Cannot assign a non-iterable value to {0}(   R7   RZ   R   R   RN   RH   R   Rp   R\   Rk   R   R[   RA   R   (   R:   RP   RQ   RR   (    (   Rt   s:   lib/python2.7/site-packages/conda/_vendor/auxlib/entity.pyR6   H  s    		#c         C` s$   | d  k r  |  j r  |  j ƒ  S| S(   N(   R7   R@   R[   (   R:   RP   RQ   RR   (    (    s:   lib/python2.7/site-packages/conda/_vendor/auxlib/entity.pyRO   X  s    c         C` sC   t  |  j t ƒ r; t |  j t ƒ r; |  j d „  | Dƒ ƒ S| Sd  S(   Nc         s` s   |  ] } | j  ƒ  Vq d  S(   N(   RY   (   Rr   Rs   (    (    s:   lib/python2.7/site-packages/conda/_vendor/auxlib/entity.pys	   <genexpr>]  s    (   RZ   Rp   R\   Rk   R   R[   (   R:   RP   RQ   RR   (    (    s:   lib/python2.7/site-packages/conda/_vendor/auxlib/entity.pyRY   [  s    $c         ` sQ   t  t ˆ ƒ j | | ƒ } | rM ˆ j ‰  ˆ j ‡  ‡ f d †  | Dƒ ƒ n  | S(   Nc         3` s9   |  ]/ } t  | ˆ  ƒ s t t ˆ j | ˆ  ƒ ƒ Vq d  S(   N(   RZ   R   R   RH   (   Rr   t   el(   Rt   R:   (    s:   lib/python2.7/site-packages/conda/_vendor/auxlib/entity.pys	   <genexpr>e  s    (   Rl   R)   R8   Rp   R[   (   R:   RP   RR   (    (   Rt   R:   s:   lib/python2.7/site-packages/conda/_vendor/auxlib/entity.pyR8   a  s
    	#N(    (   R^   R_   t   tupleR[   R   Ra   R7   Rb   RC   R6   RO   RY   R8   (    (    (    s:   lib/python2.7/site-packages/conda/_vendor/auxlib/entity.pyR)   ?  s   				t   MutableListFieldc           B` s   e  Z e Z RS(    (   R^   R_   t   listR[   (    (    (    s:   lib/python2.7/site-packages/conda/_vendor/auxlib/entity.pyRw   j  s   c        	   B` s8   e  Z e Z e e d e e e e d d  „ Z d „  Z	 RS(   c	   	   	   C` s/   t  t |  ƒ j | | | | | | | | ƒ d  S(   N(   Rl   R*   RC   (	   R:   R;   R<   R=   R>   R?   R@   RA   RB   (    (    s:   lib/python2.7/site-packages/conda/_vendor/auxlib/entity.pyRC   q  s    c         C` s„   | d  k r |  j ƒ  St | ƒ rb t | ƒ } t | t ƒ s^ t | d d j |  j ƒ ƒ‚ n  | St | d d j |  j ƒ ƒ‚ d  S(   NRg   s)   Cannot assign a non-iterable value to {0}(	   R7   R[   R   R   RZ   R   R   RN   RH   (   R:   RP   RQ   RR   (    (    s:   lib/python2.7/site-packages/conda/_vendor/auxlib/entity.pyR6   v  s    
N(    (
   R^   R_   R   R[   R   Ra   R7   Rb   RC   R6   (    (    (    s:   lib/python2.7/site-packages/conda/_vendor/auxlib/entity.pyR*   n  s   	c        	   B` s;   e  Z e e d e e e e d d  „ Z d „  Z d „  Z RS(   c
   
   	   C` s8   | |  _  t t |  ƒ j | | | | | | | |	 ƒ d  S(   N(   R[   Rl   R+   RC   (
   R:   t   field_classR;   R<   R=   R>   R?   R@   RA   RB   (    (    s:   lib/python2.7/site-packages/conda/_vendor/auxlib/entity.pyRC   ‡  s    	c         C` sñ   | d  k r d  St | |  j ƒ r& | Sy) t | d ƒ rN | j d ƒ | d <n  Wn t k
 rb n Xt | |  j ƒ r˜ t | |  j ƒ r‹ | S|  j |   St | t ƒ r´ |  j |   St | t ƒ rà t | t ƒ rà |  j | Œ  S|  j | ƒ Sd  S(   NRW   R:   t   slf(	   R7   RZ   R[   t   hasattrRW   RM   R   R   R   (   R:   RP   RQ   RR   (    (    s:   lib/python2.7/site-packages/conda/_vendor/auxlib/entity.pyR6   Ž  s     #c         C` s   | d  k r d  S| j ƒ  S(   N(   R7   RY   (   R:   RP   RQ   RR   (    (    s:   lib/python2.7/site-packages/conda/_vendor/auxlib/entity.pyRY   ¤  s    N(    (	   R^   R_   R   Ra   R7   Rb   RC   R6   RY   (    (    (    s:   lib/python2.7/site-packages/conda/_vendor/auxlib/entity.pyR+   …  s   		t
   EntityTypec           B` sA   e  Z e d  „  ƒ Z d „  Z d „  Z d „  Z e d „  ƒ Z RS(   c         C` sO   y6 g  |  D]' } t  | t ƒ r
 | t k	 r
 | ^ q
 SWn t k
 rJ d SXd  S(   N(    (   Rk   R   t	   NameError(   t   basest   base(    (    s:   lib/python2.7/site-packages/conda/_vendor/auxlib/entity.pyt   __get_entity_subclassesª  s    6c         ` s¯   d „  t  ˆ  ƒ Dƒ } t j | ƒ } | rƒ g  | D]( ‰ t ‡ f d †  | Dƒ ƒ r2 ˆ ^ q2 } t ‡  f d †  | Dƒ ƒ ˆ  t <n t ƒ  ˆ  t <t t |  ƒ j |  | | ˆ  ƒ S(   Nc         s` s;   |  ]1 \ } } t  | t ƒ r | j d  ƒ r | Vq d S(   t   __N(   RZ   R    t
   startswith(   Rr   t   keyRo   (    (    s:   lib/python2.7/site-packages/conda/_vendor/auxlib/entity.pys	   <genexpr>µ  s    	c         3` s*   |  ]  } t  | j j ˆ  ƒ t ƒ Vq d  S(   N(   RZ   RL   t   getR    (   Rr   R   (   Rƒ   (    s:   lib/python2.7/site-packages/conda/_vendor/auxlib/entity.pys	   <genexpr>º  s   c         3` s$   |  ] } | ˆ  j  | ƒ f Vq d  S(   N(   RW   (   Rr   Rƒ   (   t   dct(    s:   lib/python2.7/site-packages/conda/_vendor/auxlib/entity.pys	   <genexpr>¼  s    (   R   R|   t"   _EntityType__get_entity_subclassest   anyt   dictRK   Rl   t   __new__(   t   mcsRH   R~   R…   t   non_field_keyst   entity_subclassest   keys_to_override(    (   R…   Rƒ   s:   lib/python2.7/site-packages/conda/_vendor/auxlib/entity.pyR‰   ²  s    #c         C` s¯   t  t |  ƒ j | | | ƒ t ƒ  } d „  } xO t t j |  ƒ ƒ D]8 } d „  t | j ƒ Dƒ } | j	 t
 | d | ƒƒ qD Wt | ƒ |  _ t |  d ƒ r« |  j ƒ  n  d  S(   Nc         S` s   |  d j  S(   Ni   (   R9   (   t   x(    (    s:   lib/python2.7/site-packages/conda/_vendor/auxlib/entity.pyt   <lambda>Æ  s    c         s` s9   |  ]/ \ } } t  | t ƒ r | | j | ƒ f Vq d  S(   N(   RZ   R    RI   (   Rr   RH   t   field(    (    s:   lib/python2.7/site-packages/conda/_vendor/auxlib/entity.pys	   <genexpr>È  s   	Rƒ   t   __register__(   Rl   R|   RC   R   t   reversedR\   t   mroR   RL   t   updatet   sortedR   t
   __fields__R{   R‘   (   t   clsRH   R~   t   attrt   fieldst   _field_sort_keyt   clzt
   clz_fields(    (    s:   lib/python2.7/site-packages/conda/_vendor/auxlib/entity.pyRC   Â  s    		c         O` s;   t  t |  ƒ j | | Ž  } t | d j |  j ƒ t ƒ | S(   Ns   _{0}__initd(   Rl   R|   t   __call__t   setattrRN   R^   Ra   (   R—   t   argst   kwargsRP   (    (    s:   lib/python2.7/site-packages/conda/_vendor/auxlib/entity.pyR   Ñ  s    c         C` s   |  j  j ƒ  S(   N(   R–   t   keys(   R—   (    (    s:   lib/python2.7/site-packages/conda/_vendor/auxlib/entity.pyR™   Ö  s    (	   R^   R_   t   staticmethodR†   R‰   RC   R   Rc   R™   (    (    (    s:   lib/python2.7/site-packages/conda/_vendor/auxlib/entity.pyR|   ¨  s
   			c           B` sÅ   e  Z e ƒ  Z e Z d  „  Z e d „  ƒ Z e d „  ƒ Z	 e d „  ƒ Z
 d „  Z d „  Z e d „  ƒ Z d d d „ Z d d d „ Z d „  Z e d „  ƒ Z d „  Z d „  Z e d „  ƒ Z RS(   c         ` sQ  x4t  |  j ƒ D]#\ } } y t |  | ˆ  | ƒ Wq t k
 rt ‡  f d †  | j Dƒ d  ƒ } | d  k	 r‰ t |  | ˆ  | ƒ q3| t |  t ƒ k r¾ t |  | t |  t ƒ | ƒ q3| j	 r3| j
 t k r3t | d d j |  j j | ˆ  ƒ ƒ‚ q3q t k
 r2ˆ  | d  k	 s)| j	 r3‚  q3q Xq W|  j sM|  j ƒ  n  d  S(   Nc         3` s!   |  ] } | ˆ  k r | Vq d  S(   N(    (   Rr   t   ls(   R    (    s:   lib/python2.7/site-packages/conda/_vendor/auxlib/entity.pys	   <genexpr>å  s    Rg   s/   {0} requires a {1} field. Instantiated with {2}(   R   R–   Rž   RM   t   nextR3   R7   RJ   RK   R<   R;   R   R   RN   RU   R^   t   _lazy_validateR8   (   R:   R    Rƒ   R   t   alias(    (   R    s:   lib/python2.7/site-packages/conda/_vendor/auxlib/entity.pyRC   à  s$    " 		c         O` s   t  ƒ  } t d „  | f | Dƒ ƒ } xN t |  j ƒ D]= \ } } y t | | | j ƒ | | <Wq6 t k
 rr q6 Xq6 W|  |   S(   Nc         s` s0   |  ]& } t  | t ƒ r$ t | ƒ n | Vq d  S(   N(   RZ   Rˆ   R   (   Rr   t   o(    (    s:   lib/python2.7/site-packages/conda/_vendor/auxlib/entity.pys	   <genexpr>ù  s   (   Rˆ   Rv   R   R–   R   R3   RE   (   R—   t   objectst   override_fieldst	   init_varst   search_mapsRƒ   R   (    (    s:   lib/python2.7/site-packages/conda/_vendor/auxlib/entity.pyt   from_objectsö  s    		c         C` s   |  t  | ƒ   S(   N(   t
   json_loads(   R—   t   json_str(    (    s:   lib/python2.7/site-packages/conda/_vendor/auxlib/entity.pyt	   from_json  s    c         C` s
   |  |   S(   N(    (   R—   t	   data_dict(    (    s:   lib/python2.7/site-packages/conda/_vendor/auxlib/entity.pyt   load  s    c         ` s€   y- t  ‡  f d †  d „  t ˆ  j ƒ Dƒ ƒ WnL t k
 rW } t | ƒ d k r| q| n% t k
 r{ } t d  d | ƒ‚ n Xd  S(   Nc         ` s   t  ˆ  | ƒ S(   N(   RJ   (   t   _RH   (   R:   (    s:   lib/python2.7/site-packages/conda/_vendor/auxlib/entity.pyR     s    c         s` s$   |  ] \ } } | j  r | Vq d  S(   N(   R<   (   Rr   RH   R   (    (    s:   lib/python2.7/site-packages/conda/_vendor/auxlib/entity.pys	   <genexpr>  s    s0   reduce() of empty sequence with no initial valueRg   (   R   R   R–   t	   TypeErrort   strRE   R   R7   (   R:   Ri   (    (   R:   s:   lib/python2.7/site-packages/conda/_vendor/auxlib/entity.pyR8     s    c         ` st   ‡ f d †  ‰ ‡ f d †  ‰  ‡ f d †  } d j  ‡  ‡ f d †  t ˆ j d | ƒDƒ ƒ } d j ˆ j j | ƒ S(   Nc         ` s>   d |  k r t  Sy t ˆ  |  ƒ t SWn t k
 r9 t  SXd  S(   NR   (   Rb   RJ   Ra   RE   (   Rƒ   (   R:   (    s:   lib/python2.7/site-packages/conda/_vendor/auxlib/entity.pyt   _valid  s    c         ` s5   t  ˆ  |  ƒ } t | t ƒ r+ t | j ƒ St | ƒ S(   N(   RJ   RZ   R   t   reprRo   (   Rƒ   RR   (   R:   (    s:   lib/python2.7/site-packages/conda/_vendor/auxlib/entity.pyt   _val$  s    c         ` s)   ˆ  j  j |  ƒ } | d  k	 r% | j Sd S(   Niÿÿÿÿ(   R–   R„   R7   R9   (   Rƒ   R   (   R:   (    s:   lib/python2.7/site-packages/conda/_vendor/auxlib/entity.pyt   _sort_helper(  s    s   , c         3` s3   |  ]) } ˆ | ƒ r d  j  | ˆ  | ƒ ƒ Vq d S(   s   {0}={1}N(   RN   (   Rr   Rƒ   (   R·   Rµ   (    s:   lib/python2.7/site-packages/conda/_vendor/auxlib/entity.pys	   <genexpr>,  s   Rƒ   s   {0}({1})(   t   joinR•   RL   RN   RU   R^   (   R:   R¸   t	   kwarg_str(    (   R·   Rµ   R:   s:   lib/python2.7/site-packages/conda/_vendor/auxlib/entity.pyt   __repr__  s    c         C` s   d  S(   N(    (   R—   (    (    s:   lib/python2.7/site-packages/conda/_vendor/auxlib/entity.pyR‘   1  s    c      	   K` s   t  |  d | d | d t | S(   Nt   indentt
   separatorsR—   (   t
   json_dumpsR   (   R:   R¼   R½   R    (    (    s:   lib/python2.7/site-packages/conda/_vendor/auxlib/entity.pyt   json5  s    i   t   ,s   : c         K` s   |  j  d | d | |  S(   NR¼   R½   (   R¿   (   R:   R¼   R½   R    (    (    s:   lib/python2.7/site-packages/conda/_vendor/auxlib/entity.pyt   pretty_json8  s    c         ` s0   t  ‡  f d †  ‡  f d †  ˆ  j ƒ  Dƒ Dƒ ƒ S(   Nc         3` s\   |  ]R \ } } | t  k	 r | | j k o1 | j r | j | j ˆ  ˆ  j | ƒ f Vq d  S(   N(   R   R;   R?   RH   RY   RU   (   Rr   R   Ro   (   R:   (    s:   lib/python2.7/site-packages/conda/_vendor/auxlib/entity.pys	   <genexpr><  s   	c         3` s*   |  ]  } | t  ˆ  | j t ƒ f Vq d  S(   N(   RJ   RH   R   (   Rr   R   (   R:   (    s:   lib/python2.7/site-packages/conda/_vendor/auxlib/entity.pys	   <genexpr>=  s   (   R   t   _Entity__dump_fields(   R:   (    (   R:   s:   lib/python2.7/site-packages/conda/_vendor/auxlib/entity.pyRY   ;  s    c         C` s;   d |  j  k r4 t d „  t |  j ƒ Dƒ ƒ |  _ n  |  j S(   Nt   __dump_fields_cachec         s` s   |  ] } | j  r | Vq d  S(   N(   R>   (   Rr   R   (    (    s:   lib/python2.7/site-packages/conda/_vendor/auxlib/entity.pys	   <genexpr>E  s    (   RL   Rv   R   R–   t   _Entity__dump_fields_cache(   R—   (    (    s:   lib/python2.7/site-packages/conda/_vendor/auxlib/entity.pyt   __dump_fieldsB  s    %c         ` s?   ˆ j  ˆ  j  k r t Sd ‰ t ‡  ‡ ‡ f d †  ˆ j Dƒ ƒ S(   NI"êÛ|   c         3` s3   |  ]) } t  ˆ | ˆ ƒ t  ˆ  | ˆ ƒ k Vq d  S(   N(   RJ   (   Rr   R   (   t   othert   rando_defaultR:   (    s:   lib/python2.7/site-packages/conda/_vendor/auxlib/entity.pys	   <genexpr>M  s   (   RU   Rb   t   allR–   (   R:   RÆ   (    (   RÆ   RÇ   R:   s:   lib/python2.7/site-packages/conda/_vendor/auxlib/entity.pyt   __eq__I  s
    c         ` s   t  ‡  f d †  ˆ  j Dƒ ƒ S(   Nc         3` s'   |  ] } t  t ˆ  | d  ƒ ƒ Vq d  S(   N(   t   hashRJ   R7   (   Rr   R   (   R:   (    s:   lib/python2.7/site-packages/conda/_vendor/auxlib/entity.pys	   <genexpr>Q  s    (   t   sumR–   (   R:   (    (   R:   s:   lib/python2.7/site-packages/conda/_vendor/auxlib/entity.pyt   __hash__P  s    c         C` s   t  |  d j |  j j ƒ d  ƒ S(   Ns   _{0}__initd(   RJ   RN   RU   R^   R7   (   R:   (    (    s:   lib/python2.7/site-packages/conda/_vendor/auxlib/entity.pyRT   S  s    N(   RÀ   s   : (   R^   R_   R   R–   Rb   R¥   RC   t   classmethodR¬   R¯   R±   R8   R»   R‘   R7   R¿   RÁ   RY   RÂ   RÉ   RÌ   Rc   RT   (    (    (    s:   lib/python2.7/site-packages/conda/_vendor/auxlib/entity.pyR   Û  s    							c           B` s   e  Z d  „  Z d „  Z RS(   c         C` sD   |  j  r' t d j |  j j ƒ ƒ ‚ n  t t |  ƒ j | | ƒ d  S(   Ns)   Assignment not allowed. {0} is immutable.(   RT   RE   RN   RU   R^   Rl   R   t   __setattr__(   R:   t	   attributeRo   (    (    s:   lib/python2.7/site-packages/conda/_vendor/auxlib/entity.pyRÎ   Z  s    		c         C` sA   |  j  r' t d j |  j j ƒ ƒ ‚ n  t t |  ƒ j | ƒ d  S(   Ns'   Deletion not allowed. {0} is immutable.(   RT   RE   RN   RU   R^   Rl   R   t   __delattr__(   R:   t   item(    (    s:   lib/python2.7/site-packages/conda/_vendor/auxlib/entity.pyRÐ   `  s    		(   R^   R_   RÎ   RÐ   (    (    (    s:   lib/python2.7/site-packages/conda/_vendor/auxlib/entity.pyR   X  s   	t   DictSafeMixinc           B` sq   e  Z d  „  Z d „  Z d „  Z d d „ Z d „  Z d „  Z d „  Z	 d „  Z
 d „  Z d	 „  Z d d
 „ Z RS(   c         C` s   t  |  | ƒ S(   N(   RJ   (   R:   RÑ   (    (    s:   lib/python2.7/site-packages/conda/_vendor/auxlib/entity.pyt   __getitem__i  s    c         C` s   t  |  | | ƒ d  S(   N(   Rž   (   R:   Rƒ   Ro   (    (    s:   lib/python2.7/site-packages/conda/_vendor/auxlib/entity.pyt   __setitem__l  s    c         C` s   t  |  | ƒ d  S(   N(   t   delattr(   R:   Rƒ   (    (    s:   lib/python2.7/site-packages/conda/_vendor/auxlib/entity.pyt   __delitem__o  s    c         C` s   t  |  | | ƒ S(   N(   RJ   (   R:   RÑ   R;   (    (    s:   lib/python2.7/site-packages/conda/_vendor/auxlib/entity.pyR„   r  s    c         C` sX   t  |  | d  ƒ } | d  k r" t S|  j | } t | t t f ƒ rT t | ƒ d k St S(   Ni    (	   RJ   R7   Rb   R–   RZ   R*   R)   t   lenRa   (   R:   RÑ   Ro   R   (    (    s:   lib/python2.7/site-packages/conda/_vendor/auxlib/entity.pyt   __contains__u  s    c         c` s,   x% |  j  D] } | |  k r
 | Vq
 q
 Wd  S(   N(   R–   (   R:   Rƒ   (    (    s:   lib/python2.7/site-packages/conda/_vendor/auxlib/entity.pyt   __iter__~  s    c         c` s;   x4 |  j  D]) } | |  k r
 | t |  | ƒ f Vq
 q
 Wd  S(   N(   R–   RJ   (   R:   Rƒ   (    (    s:   lib/python2.7/site-packages/conda/_vendor/auxlib/entity.pyR   ƒ  s    c         C` s
   |  j  ƒ  S(   N(   R   (   R:   (    (    s:   lib/python2.7/site-packages/conda/_vendor/auxlib/entity.pyt   itemsˆ  s    c         C` s   |  j  |  j ƒ    S(   N(   RU   RY   (   R:   (    (    s:   lib/python2.7/site-packages/conda/_vendor/auxlib/entity.pyt   copy‹  s    c         C` s#   | |  k r t  |  | | ƒ n  d  S(   N(   Rž   (   R:   Rƒ   t   default_value(    (    s:   lib/python2.7/site-packages/conda/_vendor/auxlib/entity.pyt
   setdefaultŽ  s    c         K` sŠ   | d  k	 rg t | d ƒ r= xF | D] } | | |  | <q" Wqg x' t | ƒ D] \ } } | |  | <qJ Wn  x | D] } | | |  | <qn Wd  S(   NR¡   (   R7   R{   R   (   R:   t   Et   Ft   kRs   (    (    s:   lib/python2.7/site-packages/conda/_vendor/auxlib/entity.pyR”   ’  s    N(   R^   R_   RÓ   RÔ   RÖ   R7   R„   RØ   RÙ   R   RÚ   RÛ   RÝ   R”   (    (    (    s:   lib/python2.7/site-packages/conda/_vendor/auxlib/entity.pyRÒ   g  s   										t   EntityEncoderc           B` s   e  Z d  „  Z RS(   c         C` sŠ   t  | d ƒ r | j ƒ  St  | d ƒ r2 | j ƒ  St  | d ƒ rK | j ƒ  St  | d ƒ rd | j ƒ  St | t ƒ rz | j St j	 |  | ƒ S(   NRY   t   __json__t   to_jsont   as_json(
   R{   RY   Râ   Rã   Rä   RZ   R   Ro   R   R;   (   R:   t   obj(    (    s:   lib/python2.7/site-packages/conda/_vendor/auxlib/entity.pyR;   ¤  s    



(   R^   R_   R;   (    (    (    s:   lib/python2.7/site-packages/conda/_vendor/auxlib/entity.pyRá   ¢  s   N(J   R`   t
   __future__R    R   R   t   collections.abcR   R   t   ImportErrort   collectionsR   t	   functoolsR   R¿   R   R   R¾   R	   R­   t   loggingR
   t   enumR   t    R   t   _vendor.boltons.timeutilsR   t
   collectionR   R   R   t   compatR   R   R   R   R   R   R   R   t
   exceptionsR   R   t   ishR   t   logzR   t   type_coercionR   R^   RF   t   __all__RK   t   NOTESt   objectR    R!   R"   R#   R$   R%   R&   R'   R(   R)   Rw   R*   R+   R\   R|   R   R   RÒ   Rá   (    (    (    s:   lib/python2.7/site-packages/conda/_vendor/auxlib/entity.pyt   <module>í   sX   :		R™+#3|;