
    siZ                        S r SSKJrJr  SSKJr  SSKJr  SSKJr  SSK	J
r
  SSKJr  SSKJr  SS	KJrJr  SS
KJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJrJr  SSK J!r!  SSK"J#r#  SSK$J%r%  SSK&J'r'  \\" 5       ;  a
  \" \S 5        CC\
" \(5      r)/ SQr*Sr+Sr, " S S5      r- " S S\-5      r.\.r/ " S S \-5      r0\0r1 " S! S"\-5      r2 " S# S$\-5      r3 " S% S&\-5      r4 " S' S(\-5      r5 " S) S*\-5      r6 " S+ S,\65      r7 " S- S.\-5      r8 " S/ S0\-5      r9 " S1 S2\:5      r; " S3 S4\;S59r< " S6 S7\<5      r= " S8 S95      r>\'R~                  " S:S;S<\%R                  S=S>9  g?)@a  
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}'


    )MappingSequence)datetime)Enum)reduce)	getLogger)Path)isoparse)
deepfreeze
frozendict)getFreezeConversionMap)register   )NULL)odict   )
isiterable)AttrDict)RaiseValidationError)find_or_raise)	maybecall)json)
deprecatedc                     U $ N xs    3lib/python3.13/site-packages/conda/auxlib/entity.py<lambda>r!     s    q    )EntityImmutableEntityFieldBooleanField	BoolFieldIntegerFieldIntFieldNumberFieldStringField	DateField	EnumField	ListFieldMapFieldComposableField__key_overrides__a  

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 denylists for .dump() and .json()
    __roles__ = {
        EntityRole.registered_name: Denylist('field1', 'field2'),
        EntityRole.another_registered_name: Allowlist('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                       \ rS rSrSrSr\SSSSSSS4S jr\S	 5       r	S
 r
S rS rS rS rS rS rS r\S 5       r\S 5       r\S 5       r\S 5       r\S 5       r\S 5       r\S 5       r\S 5       rSrg)r%   ij  aw  
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 "programmatically usable" 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):
r   TNFr   c	           
         X l         X0l        X@l        XPl        X`l        Xpl        Xl        U[        L a  [        U l        OV[        U5      (       a  UOU R                  S S U5      U l        U R                  S U R                  S S [        U5      5      5        [        R                  U l        [        =R                  S-  sl        g Nr   )	_required_validation_in_dump_default_in_dump	_nullable
_immutable_aliasesr   _defaultcallableboxvalidater   r%   _order_helper)	selfdefaultrequired
validationin_dumpdefault_in_dumpnullable	immutablealiasess	            r    __init__Field.__init__~  s    !% /!#d? DM'/'8'8GdhhtTSZ>[DMMM$tYw5G HI"00q r"   c                 d     U R                   $ ! [         a    [        R                  S5        e f = f)NzYThe name attribute has not been set for this field. Call set_name at class creation time.)_nameAttributeErrorlogerrorrA   s    r    name
Field.name  s4    	:: 	II > ?	s    !/c                     Xl         U $ r   )rM   )rA   rR   s     r    set_nameField.set_name  s    
r"   c                     Uc  [        U[        5      U R                     nOUR                  U R                     n Uc*  U R                  (       d  [	        SU R                   S35      eU R                  XU5      $ ! [         a!    [
        R                  S5        [	        S5      e[         aD    U R                  [        L a  [	        SU R                   S35      e[        U R                  5      n Nf = f)Nz3The name attribute has not been set for this field.zA value for z has not been setThe z field has been deleted.)getattrKEY_OVERRIDES_MAPrR   __dict__rN   rO   rP   KeyErrorrB   r   r   rG   unboxrA   instanceinstance_typevals       r    __get__Field.__get__  s    	.m->?		J''		2 ;t}} 4		{2J!KLLzz(377  	XIIKL !VWW 	.||t#$|DII;>O%PQQ-		.s    A< A< <A4C32C3c                     U R                   (       a*  UR                  (       a  [        SU R                   S35      eU R	                  UU R                  XR                  U5      5      UR                  U R                  '   g )NrX    field is immutable.)rH   _initdrN   rR   r?   r>   	__class__r[   rA   r_   ra   s      r    __set__Field.__set__  s^    >>hoo 4		{2F!GHH (,}}HHX1137(
$))$r"   c                 p   U R                   (       a*  UR                  (       a  [        SU R                   S35      eU R                  (       a  [        SU R                   S35      eU R
                  (       d  S UR                  U R                  '   g UR                  R                  U R                  S 5        g )NrX   re   z) field is required and cannot be deleted.)rH   rf   rN   rR   rC   rG   r[   pop)rA   r_   s     r    
__delete__Field.__delete__  s    >>hoo 4		{2F!GHH]] 4		{2[!\]]
 ,0Hdii(!!$))T2r"   c                     U$ r   r   r^   s       r    r>   	Field.box      
r"   c                     U$ r   r   r^   s       r    r]   Field.unbox  rq   r"   c                     U$ r   r   r^   s       r    dump
Field.dump  rq   r"   c                    [        X R                  5      (       a%  U R                  b  U R                  U5      (       a  U$ U[        L a  U R                  (       d  U$ Uc  U R
                  (       a  U$ [        [        U SS5      U5      e)zB

Returns:
    True: if val is valid

Raises:
    ValidationError
rR   zundefined name)
isinstance_typer6   r   rC   rG   r   rY   rh   s      r    r?   Field.validate  sm     c::&&D,<,<,DHXHXY\H]H]JD[J[T]]J!'$8H"I3OOr"   c                     U R                   $ r   )r5   rQ   s    r    rC   Field.required      ~~r"   c                     U R                   $ r   ry   rQ   s    r    type
Field.type  s    zzr"   c                     U R                   $ r   )r<   rQ   s    r    rB   Field.default      }}r"   c                     U R                   $ r   )r7   rQ   s    r    rE   Field.in_dump  r   r"   c                     U R                   $ r   )r8   rQ   s    r    rF   Field.default_in_dump  s    $$$r"   c                     U R                   $ r   )is_nullablerQ   s    r    rG   Field.nullable  s    r"   c                     U R                   $ r   )r9   rQ   s    r    r   Field.is_nullable  r}   r"   c                     U R                   $ r   )r:   rQ   s    r    rH   Field.immutable   s    r"   )
r;   r<   r8   r:   r7   rM   r9   r@   r5   r6   )__name__
__module____qualname____firstlineno____doc__r@   r   rJ   propertyrR   rU   rb   ri   rm   r>   r]   ru   r?   rC   r   rB   rE   rF   rG   r   rH   __static_attributes__r   r"   r    r%   r%   j  s   " M#dtteu^`!$  8&
3P&         % %        r"   r%   c                       \ rS rSr\rS rSrg)r&   i  c                 "    Uc  S $ [        U5      $ r   )boolr^   s       r    r>   BooleanField.box  s    {t1S	1r"   r   N)r   r   r   r   r   ry   r>   r   r   r"   r    r&   r&     s    E2r"   r&   c                       \ rS rSr\rSrg)r(   i  r   N)r   r   r   r   intry   r   r   r"   r    r(   r(     s    Er"   r(   c                       \ rS rSr\\\4rSrg)r*   i  r   N)	r   r   r   r   r   floatcomplexry   r   r   r"   r    r*   r*     s    %!Er"   r*   c                       \ rS rSr\rS rSrg)r+   i  c                 Z    [        U[        R                  5      (       a  [        U5      $ U$ r   )rx   r*   ry   strr^   s       r    r>   StringField.box  s#    %c;+<+<==s3xF3Fr"   r   N)r   r   r   r   r   ry   r>   r   r   r"   r    r+   r+     s    EGr"   r+   c                   $    \ rS rSr\rS rS rSrg)r,   i!  c                 ~     [        U[        5      (       a  [        U5      $ U$ ! [         a  n[	        X4S9eS nAff = fNmsg)rx   r   r
   
ValueErrorr   )rA   r_   r`   ra   es        r    r>   DateField.box$  s=    	.$.sC$8$88C=AcA 	.!#--	.s   $ $ 
<	7<c                 ,    Uc  S $ UR                  5       $ r   )	isoformatr^   s       r    ru   DateField.dump*  s    {t77r"   r   N)	r   r   r   r   r   ry   r>   ru   r   r   r"   r    r,   r,   !  s    E.8r"   r,   c                   H   ^  \ rS rSr\SSSSSSS4U 4S jjrS rS rS	rU =r	$ )
r-   i.  TNFr   c
           
      t   > [        U[        5      (       d
  [        S SS9eXl        [        T
U ]  X#XEXgX5        g )Nz&enum_class must be an instance of Enumr   )
issubclassr   r   ry   superrJ   )rA   
enum_classrB   rC   rD   rE   rF   rG   rH   rI   rg   s             r    rJ   EnumField.__init__0  s9    *d++!$,TUU
zOy	
r"   c                     Uc  g  U R                  U5      $ ! [         a1  n U R                   U   s S nA$ ! [         a
    [        X4S9ef = fS nAff = fr   )ry   r   r\   r   )rA   r_   r`   ra   e1s        r    r>   EnumField.box9  sY    ;	3::c?" 	33zz#& 3%c223		3s#    
A6AA

AAc                 6    US [         4;   a  S $ UR                  $ r   )r   valuer^   s       r    ru   EnumField.dumpG  s    tTl*t9		9r"   r   
r   r   r   r   r   rJ   r>   ru   r   __classcell__rg   s   @r    r-   r-   .  s*    +/$4teu^`
3: :r"   r-   c                   ^   ^  \ rS rSr\r\SSSSSSS4U 4S jjrS rS r	S	 r
U 4S
 jrSrU =r$ )r.   iK  TNFr   c
           
      6   > Xl         [        T
U ]	  X#XEXgX5        g r   )_element_typer   rJ   )rA   element_typerB   rC   rD   rE   rF   rG   rH   rI   rg   s             r    rJ   ListField.__init__N  s    )zOy	
r"   c                   ^ Uc  g [        U[        5      (       a  [        SU R                   35      e[	        U5      (       a~  U R
                  m[        T[        5      (       a0  [        T[        5      (       a  U R                  U4S jU 5       5      $ U R                  (       a  [        U5      $ U R                  U5      $ [        USU R                   3S9e)Nz*Attempted to assign a string to ListField c              3   Z   >#    U  H   n[        UT5      (       a  UOT" S0 UD6v   M"     g 7fNr   )rx   ).0vets     r    	<genexpr> ListField.box.<locals>.<genexpr>_  s(     !Ss!z!R'8'8!bg1g"Es   (+&Cannot assign a non-iterable value to r   )rx   r   r   rR   r   r   r   r   r#   ry   rH   r   )rA   r_   r`   ra   r   s       @r    r>   ListField.boxU  s    ;S!!!<TYYKH  __##B"d##
2v(>(>zz!Ss!SSS*...z#MdjjoM!A$))M r"   c                 N    Uc!  U R                   (       d  U R                  5       $ U$ r   )rG   ry   r^   s       r    r]   ListField.unboxg  s    "{4==tzz|IcIr"   c                     [        U R                  [        5      (       a7  [        U R                  [        5      (       a  U R                  S U 5       5      $ U$ )Nc              3   @   #    U  H  oR                  5       v   M     g 7fr   ru   )r   r   s     r    r   !ListField.dump.<locals>.<genexpr>l  s     41ffhhs   )rx   r   r   r   r#   ry   r^   s       r    ru   ListField.dumpj  sB    d(($//Jt?Q?QSY4Z4Z::4444Jr"   c                    >^ ^ [         TT ]  X5      nU(       a(  T R                  mT R                  UU 4S jU 5       5        U$ )Nc              3      >#    U  H8  n[        UT5      (       a  M  [        [        TR                  UT5      5      v   M:     g 7fr   )rx   r   r   rR   )r   elr   rA   s     r    r   %ListField.validate.<locals>.<genexpr>t  s8      23R(R0 Au_TYYB?@@3s
   A'A)r   r?   r   ry   )rA   r_   ra   r   rg   s   `  @r    r?   ListField.validatep  s=    gx-##BJJ 23 2 2
r"   )r   )r   r   r   r   tuplery   r   rJ   r>   r]   ru   r?   r   r   r   s   @r    r.   r.   K  s:    E-1DTteu^`
$J r"   r.   c                       \ rS rSr\rSrg)MutableListFieldiy  r   N)r   r   r   r   listry   r   r   r"   r    r   r   y  s    Er"   r   c                   F   ^  \ rS rSr\r\SSSSSSS4U 4S jjrS rSr	U =r
$ )r/   i}  TNFr   c	           
      *   > [         T	U ]  XX4XVXx5        g r   )r   rJ   )
rA   rB   rC   rD   rE   rF   rG   rH   rI   rg   s
            r    rJ   MapField.__init__  s     	zOy	
r"   c                     Uc  U R                  5       $ [        U5      (       a9  [        U5      n[        U[        5      (       d  [        USU R                   3S9eU$ [        USU R                   3S9e)Nr   r   )ry   r   r   rx   r   r   rR   r^   s       r    r>   MapField.box  su    ;::<__S/Cc7++%Edii[Q  J!A$))M r"   )r   r   r   r   r   ry   r   rJ   r>   r   r   r   s   @r    r/   r/   }  s1    E 
 r"   r/   c                   H   ^  \ rS rSr\SSSSSSS4U 4S jjrS rS rS	rU =r	$ )
r0   i  TNFr   c
           
      6   > Xl         [        T
U ]	  X#XEXgX5        g r   )ry   r   rJ   )rA   field_classrB   rC   rD   rE   rF   rG   rH   rI   rg   s             r    rJ   ComposableField.__init__  s     
zOy	
r"   c                     Uc  g [        X0R                  5      (       a  U$  [        US5      (       a  UR                  S5      US'   [        X0R                  5      (       a.  [        X0R                  5      (       a  U$ U R                  " S0 UD6$ [        U[
        5      (       a  U R                  " S0 UD6$ [        U[        5      (       a$  [        U[        5      (       d  U R                  " U6 $ U R                  U5      $ ! [         a     Nf = f)Nrl   rA   slfr   )rx   ry   hasattrrl   r\   r   r   r   r^   s       r    r>   ComposableField.box  s    ;c::&&J3&&!$CJ #zz**(jj99sPtzz?PC?PPC))zz(C((C**:c33G3Gzz3''zz#&  s   %D   
DDc                 ,    Uc  S $ UR                  5       $ r   r   r^   s       r    ru   ComposableField.dump  s    {t2
2r"   r   r   r   s   @r    r0   r0     s*    ,04Dteu^`
',3 3r"   r0   c                   `   ^  \ rS rSr\S 5       rU 4S jrU 4S jrU 4S jr\	S 5       r
SrU =r$ )
EntityTypei  c                      U  Vs/ s H'  n[        U[        5      (       d  M  U[        Ld  M%  UPM)     sn$ s  snf ! [         a     gf = fr   )r   r#   	NameError)basesbases     r    __get_entity_subclasses"EntityType.__get_entity_subclasses  sD    	%*^UTjv.FD4W]K]DU^^^ 		s#   < 777< < 
A	A	c                 d  >^ S UR                  5        5       n[        R                  U5      nU(       aY  U V^s/ s H!  m[        U4S jU 5       5      (       d  M  TPM#     nnU Vs0 s H  ofUR	                  U5      _M     snU[
        '   O	0 U[
        '   [        TU ]  XX#5      $ s  snf s  snf )Nc              3      #    U  H8  u  p[        U[        5      (       a  M  UR                  S 5      (       a  M4  Uv   M:     g7f)__N)rx   r%   
startswith)r   keyr   s      r    r   %EntityType.__new__.<locals>.<genexpr>  s6      
)
eU+ 47NN44H C)s   AA	Ac              3   v   >#    U  H.  n[        UR                  R                  T5      [        5      v   M0     g 7fr   )rx   r[   getr%   )r   r   r   s     r    r   r     s2      'F3D4 (2$--2C2CC2H%'P'P3Ds   69)itemsr   "_EntityType__get_entity_subclassesanyrl   rZ   r   __new__)	mcsrR   r   dctnon_field_keysentity_subclassesr   keys_to_overriderg   s	         ` r    r   EntityType.__new__  s    
!iik

 '>>uE/=  G~#& 'F3D'F $F !$~  G DT%TCSC3773<&7CS%TC!"%'C!"ws%55 G &Us   B(B()B-c                 `  > [         TU ]  XU5        [        5       nS n[        [        R                  U 5      5       H<  nS UR                  R                  5        5       nUR                  [        XuS95        M>     [        U5      U l        [        U S5      (       a  U R                  5         g g )Nc                      U S   R                   $ r4   )r@   r   s    r    r!   %EntityType.__init__.<locals>.<lambda>  s    AaD$6$6r"   c              3   x   #    U  H0  u  p[        U[        5      (       d  M  XR                  U5      4v   M2     g 7fr   )rx   r%   rU   r   rR   fields      r    r   &EntityType.__init__.<locals>.<genexpr>  s1      #7KDeU+ -~~d+,#7s   ::r   __register__)r   rJ   r   reversedr   mror[   r   updatesortedr   
__fields__r   r  )	clsrR   r   attrfields_field_sort_keyclz
clz_fieldsrg   s	           r    rJ   EntityType.__init__  s    d+6DHHSM*C#&<<#5#5#7J
 MM&AB + $F+3'' (r"   c                 ^   > [         TU ]  " U0 UD6n[        USU R                   S3S5        U$ )N___initdT)r   __call__setattrr   )r  argskwargsr_   rg   s       r    r  EntityType.__call__  s5    7#T4V4Acll^73T:r"   c                 6    U R                   R                  5       $ r   )r  keysr  s    r    r  EntityType.fields  s    ~~""$$r"   r   )r   r   r   r   staticmethodr   r   rJ   r  r   r  r   r   r   s   @r    r   r     s8     6&"
 % %r"   r   c                       \ rS rSr\" 5       rSrS r\S 5       r	\S 5       r
\S 5       rS rS r\S	 5       rSS jrSS jrS r\S 5       rS rS r\S 5       rSrg
)r#   i  Fc           
        ^ U R                   R                  5        H  u  p# [        XTU   5        M     U R                  (       d  U R!                  5         g g ! [         a    [	        U4S jUR
                   5       S 5      nUb  [        XTU   5         M{  U[        U [        5      ;   a   [        X[        U [        5      U   5         M  UR                  (       aF  UR                  [        L a/  [        USR                  U R                  R                  UT5      S9e GM   GM
  [         a    TU   c  UR                  (       a  e  GM/  f = f)Nc              3   6   >#    U  H  oT;   d  M
  Uv   M     g 7fr   r   )r   lsr"  s     r    r   "Entity.__init__.<locals>.<genexpr>  s     J>R6\bb>s   		z,{} requires a {} field. Instantiated with {}r   )r  r   r   r\   nextr;   rY   rZ   rC   rB   r   r   formatrg   r   _lazy_validater?   )rA   r"  r   r  aliass    `   r    rJ   Entity.__init__  s   ////1JC6#;/ 2& ""MMO #!  J5>>JDQ$Dve}5GD*;<<Dwt5F'G'LM^^(=)#VDNN$;$;S&I  )>^ # #;*enn /=s$   A<E1EAE&!EEc                     0 n[        S U4U-    5       5      nU R                  R                  5        H  u  pV [        XTUR                  5      X5'   M      U " S0 UD6$ ! [
         a     M7  f = f)a  Construct a new object of type ``cls`` from existing objects or dicts.

Allows the creation of new objects of concrete :class:`Entity` subclasses by
combining information from several sources. This can be any combination of
objects and dictionaries passed in as positional arguments. When looking for
the value of the fields of the :class:`Entity` subclass, the first object
that provides an attribute (or, in the case of a dict an entry) that has the
name of the field or one of its aliases will take precedence. Any keyword
arguments passed in will override this and take precedence.

Args:
    cls(:class:`Entity` subclass): The class to create, usually determined by call, e.g. ``PrefixRecord.from_objects(...)``.
    *objects(tuple(object or dict)): Any combination of objects and dicts in order of decending precedence.
    **override_fields(dict(str, object)): Any individual fields overriding possible contents from ``*objects``.
c              3   f   #    U  H'  n[        U[        5      (       a  [        U5      OUv   M)     g 7fr   )rx   dictr   )r   os     r    r   &Entity.from_objects.<locals>.<genexpr>(  s-      E&B ,6a+>+>HQKAE&Bs   /1r   )r   r  r   r   r;   rN   )r  objectsoverride_fields	init_varssearch_mapsr   r  s          r    from_objectsEntity.from_objects  s    " 	 E'6&87&BE E....0JC!.s!P	 1 Y " s   A
A+*A+c                 :    U " S0 [         R                  " U5      D6$ r   )r   loads)r  json_strs     r    	from_jsonEntity.from_json2  s    *TZZ)**r"   c                     U " S0 UD6$ r   r   )r  	data_dicts     r    loadEntity.load6  s    Yr"   c                    ^   [        U 4S jS T R                  R                  5        5       5        g ! [         a  n[	        U5      S:X  a   S nAg  S nAg S nAf[
         a  n[        S US9eS nAff = f)Nc                    > [        TU5      $ r   rY   )r  rR   rA   s     r    r!   !Entity.validate.<locals>.<lambda>>  s    d 3r"   c              3   P   #    U  H  u  pUR                   (       d  M  Uv   M     g 7fr   )rC   r  s      r    r   "Entity.validate.<locals>.<genexpr>?  s     S)@+$ENN)@s   &	&z0reduce() of empty sequence with no initial valuer   )r   r  r   	TypeErrorr   rN   r   )rA   r   s   ` r    r?   Entity.validate:  sf    		/3S)>)>)@S  	1vKK L 	/!$A..	/s    /3 
A2AA2#
A--A2c                    ^ ^^ U 4S jmU 4S jmU 4S jnSR                  UU4S j[        T R                  US9 5       5      nT R                  R                   SU S3$ )	Nc                 N   > SU ;   a  g [        TU 5        g! [         a     gf = f)Nr   FT)rY   rN   )r   rA   s    r    _validEntity.__repr__.<locals>._validH  s3     s{c"! s    
$$c                    > [        TU 5      n[        U[        5      (       a  [        UR                  5      $ [        U5      $ r   )rY   rx   r   reprr   )r   ra   rA   s     r    _valEntity.__repr__.<locals>._valT  s2    $$C&0d&;&;4		?JcJr"   c                 \   > TR                   R                  U 5      nUb  UR                  $ S$ )N)r  r   r@   )r   r  rA   s     r    _sort_helper%Entity.__repr__.<locals>._sort_helperX  s-    OO'',E*/*;5&&CCr"   z, c              3   \   >#    U  H!  nT" U5      (       d  M  U S T" U5       3v   M#     g7f)=Nr   )r   r   rU  rQ  s     r    r   "Entity.__repr__.<locals>.<genexpr>\  s0      
,SSW]^aWb se1T#YK ,Ss   ,,r  ())joinr  r[   rg   r   )rA   rY  	kwarg_strrU  rQ  s   `  @@r    __repr__Entity.__repr__G  s\    
		K	D II 
,24==l,S
 
	 ..))*!I;a88r"   c                     g r   r   r&  s    r    r  Entity.__register__a  s    r"   Nc                 4    [         R                  " U 4XS.UD6$ N)indent
separatorsr   dumpsrA   rh  ri  r"  s       r    r   Entity.jsone      zz$OvOOOr"   c                 4    [         R                  " U 4XS.UD6$ rg  rj  rl  s       r    pretty_jsonEntity.pretty_jsonh  rn  r"   c                 ^   ^  [        U 4S jU 4S jT R                  5        5        5       5      $ )Nc              3      >#    U  H\  u  pU[         Ld  M  X!R                  L a  UR                  (       d  M1  UR                  UR	                  TTR
                  U5      4v   M^     g 7fr   )r   rB   rF   rR   ru   rg   )r   r  r   rA   s      r    r   Entity.dump.<locals>.<genexpr>l  sa      S*MT) K 49MM3I;@;P;P	 Kejj%**T4>>5"IJ*Ms   A'A'0A'c              3   ^   >#    U  H"  nU[        TUR                  [        5      4v   M$     g 7fr   )rY   rR   r   r   r  rA   s     r    r   rt  m  s+      *M7Ke ,1'$

D2Q*R7Ks   *-)r   _Entity__dump_fieldsrQ   s   `r    ru   Entity.dumpk  s6     S*M7;7I7I7K*MS S 	Sr"   c                     SU R                   ;  a/  [        S U R                  R                  5        5       5      U l        U R                  $ )N__dump_fields_cachec              3   J   #    U  H  oR                   (       d  M  Uv   M     g 7fr   )rE   )r   r  s     r    r   'Entity.__dump_fields.<locals>.<genexpr>u  s      ,#:%mm#:s   #	#)r[   r   r  values_Entity__dump_fields_cacher&  s    r    __dump_fieldsEntity.__dump_fieldsr  sC     4&+ ,#&>>#8#8#:, 'C# &&&r"   c                    ^ ^^ T R                   TR                   :w  a  gSm[        UUU 4S jT R                   5       5      $ )NFl   "jy c              3   Z   >#    U  H   n[        TUT5      [        TUT5      :H  v   M"     g 7fr   rI  )r   r  otherrando_defaultrA   s     r    r    Entity.__eq__.<locals>.<genexpr>~  s0      1 /u 46'%P]:^^ /r   )rg   allr  )rA   r  r  s   ``@r    __eq__Entity.__eq__z  s9    >>U__,# 1 $1 1 	1r"   c                 B   ^  [        U 4S jT R                   5       5      $ )Nc              3   P   >#    U  H  n[        [        TUS 5      5      v   M     g 7fr   )hashrY   rv  s     r    r   "Entity.__hash__.<locals>.<genexpr>  s"     Q4eT233s   #&)sumr  rQ   s   `r    __hash__Entity.__hash__  s    QQQQr"   c                 L    [        U SU R                  R                   S3S 5      $ )Nr  r  )rY   rg   r   rQ   s    r    rf   Entity._initd  s%    tq!8!8 9A4HHr"   r   )NN)r   ),z: )r   r   r   r   r   r  r0  rJ   classmethodr<  rA  rE  r?   rb  r  r   rp  ru   rw  r  r  r   rf   r   r   r"   r    r#   r#     s    JN.    6 + +    /94  PPS ' '1R I Ir"   r#   )	metaclassc                   4   ^  \ rS rSrU 4S jrU 4S jrSrU =r$ )r$   i  c                    > U R                   (       a#  [        SU R                  R                   S35      e[        TU ]  X5        g )NzAssignment not allowed.  is immutable.)rf   rN   rg   r   r   __setattr__)rA   	attributer   rg   s      r    r  ImmutableEntity.__setattr__  s=    ;; *4>>+B+B*C>R  	I-r"   c                    > U R                   (       a#  [        SU R                  R                   S35      e[        TU ]  U5        g )NzDeletion not allowed. r  )rf   rN   rg   r   r   __delattr__)rA   itemrg   s     r    r  ImmutableEntity.__delattr__  s8    ;; #9$..:Q:Q9RR`!abbD!r"   r   )r   r   r   r   r  r  r   r   r   s   @r    r$   r$     s    ." "r"   r$   c                   X    \ rS rSrS rS rS rSS jrS rS r	S	 r
S
 rS rSS jrSrg)DictSafeMixini  c                     [        X5      $ r   rI  )rA   r  s     r    __getitem__DictSafeMixin.__getitem__  s    t""r"   c                     [        XU5        g r   r   )rA   r   r   s      r    __setitem__DictSafeMixin.__setitem__  s    5!r"   c                     [        X5        g r   )delattrrA   r   s     r    __delitem__DictSafeMixin.__delitem__  s
    r"   Nc                     [        XU5      $ r   rI  )rA   r  rB   s      r    r   DictSafeMixin.get  s    t7++r"   c                     [        XS 5      nUc  gU R                  U   n[        U[        [        45      (       a  [        U5      S:  $ g)NFr   T)rY   r  rx   r/   r.   len)rA   r  r   r  s       r    __contains__DictSafeMixin.__contains__  sG    D)=%eh	233u:>!r"   c              #   H   #    U R                    H  nX;   d  M
  Uv   M     g 7fr   )r  r  s     r    __iter__DictSafeMixin.__iter__  s     ??C{	 #s   "	"c              #   ^   #    U R                    H  nX;   d  M
  U[        X5      4v   M     g 7fr   )r  rY   r  s     r    r   DictSafeMixin.items  s(     ??C{74--- #s   --c                 B    U R                   " S0 U R                  5       D6$ r   )rg   ru   rQ   s    r    copyDictSafeMixin.copy  s    ~~,		,,r"   c                 (    X;  a  [        XU5        g g r   r  )rA   r   default_values      r    
setdefaultDictSafeMixin.setdefault  s    ?D}- r"   c                     Ub   UR                  5        H	  u  p4X@U'   M     U H	  nX#   X'   M     g ! [         a    U H	  u  p4X@U'   M      N+f = fr   )r   rN   )rA   EFkr   s        r    r  DictSafeMixin.update  s`    
 = GGIDAG &
 AdDG  "  DAG  s   2 AAr   r   )r   r   r   r   r  r  r  r   r  r  r   r  r  r  r   r   r"   r    r  r    s4    #",
.
-.r"   r  z26.3z26.9EntityEncoderz;Use `conda.common.serialize.json.CondaJSONEncoder` instead.)addendumN)Ar   collections.abcr   r   r   enumr   	functoolsr   loggingr   pathlibr	   boltons.timeutilsr
   r   r   r   _getFreezeConversionMapr   	_register r   compatr   common.compatr   
collectionr   
exceptionsr   r   ishr   type_coercionr   common.serializer   deprecationsr   r   rO   __all__rZ   NOTESr%   r&   r'   r(   r)   r*   r+   r,   r-   r.   r   r/   r0   r   r   r#   r$   r  constantCondaJSONEncoderr   r"   r    <module>r     sy  kZ .      & - H ,   &   .  $ # %&(( dL! ( O	dX Xv25 2 	5  "% "G% G
8 
8: ::+ +\y  u  F 3e  3F5% 5%pKIz KI\"f "5 5p   

Jr"   