
    Vi]1                        S r SSKrSSKJr  SSKJrJrJrJrJrJ	r	J
r
JrJr  SSKJrJrJrJrJrJr   \  \" \SS5      b  \R0                  r " S S	\5      rS
 r " S S\5      rSS jr\R=                  5        V s/ s H  n \" U \ 5      (       d  M  U PM     sn r!\! V Vs/ s H6  n \"" U \#" \! Vs/ s H  nX\ \4;  d  M  UPM     sn5      5      (       a  M4  U PM8     snn r$\#" \%" \$5      \%" \&\'\(\\ /5      -
  5      r)S r*S r+\" S\+SS9   " S S\5      r,SS jr-S r.S r/\" S\/SS9  g! \ a    \r Nf = fs  sn f s  snf s  snn f )a_  By default, glom aims to safely return a transformed copy of your
data. But sometimes you really need to transform an existing object.

When you already have a large or complex bit of nested data that you
are sure you want to modify in-place, glom has you covered, with the
:func:`~glom.assign` function, and the :func:`~glom.Assign` specifier
type.

    N)pprint   )	PathTSSpecglomUnregisteredTarget	GlomErrorPathAccessErrorUP)TTyperegister_opTargetRegistrybbreprPathAssignError
_assign_op__dict__c                       \ rS rSrSrS rSrg)PathDeleteError   a  This :exc:`GlomError` subtype is raised when an assignment fails,
stemming from an :func:`~glom.delete` call or other
:class:`~glom.Delete` usage.

One example would be deleting an out-of-range position in a list::

  >>> delete(["short", "list"], Path(5))
  Traceback (most recent call last):
  ...
  PathDeleteError: could not delete 5 on object at Path(), got error: IndexError(...

Other assignment failures could be due to deleting a read-only
``@property`` or exception being raised inside a ``__delattr__()``.

c                 Z    SU R                   < SU R                  < SU R                  < 3$ )Nzcould not delete z on object at z, got error: )	dest_namepathexc)selfs    `/home/james-whalen/.local/share/pipx/venvs/semgrep/lib/python3.13/site-packages/glom/mutation.pyget_messagePathDeleteError.get_message,   s    >>499dhh8 	9     N)__name__
__module____qualname____firstlineno____doc__r   __static_attributes__r!   r    r   r   r      s    9r    r   c                     UR                   R                  5       nU(       a3  [        US-
  5       H  n[        U/ 5      nM     U H  nU " U5        M     g U " U5        g )Nr   )path_t	__stars__rangesum)funcr   vallayersiinners         r   _apply_for_eachr2   1   sO    [[""$Fvz"Ac2,C #EK  	S	r    c                   .    \ rS rSrSrSS jrS rS rSrg)	Assign<   a   *New in glom 18.3.0*

The ``Assign`` specifier type enables glom to modify the target,
performing a "deep-set" to mirror glom's original deep-get use
case.

``Assign`` can be used to perform spot modifications of large data
structures when making a copy is not desired::

  # deep assignment into a nested dictionary
  >>> target = {'a': {}}
  >>> spec = Assign('a.b', 'value')
  >>> _ = glom(target, spec)
  >>> pprint(target)
  {'a': {'b': 'value'}}

The value to be assigned can also be a :class:`~glom.Spec`, which
is useful for copying values around within the data structure::

  # copying one nested value to another
  >>> _ = glom(target, Assign('a.c', Spec('a.b')))
  >>> pprint(target)
  {'a': {'b': 'value', 'c': 'value'}}

Another handy use of Assign is to deep-apply a function::

  # sort a deep nested list
  >>> target={'a':{'b':[3,1,2]}}
  >>> _ = glom(target, Assign('a.b', Spec(('a.b',sorted))))
  >>> pprint(target)
  {'a': {'b': [1, 2, 3]}}

Like many other specifier types, ``Assign``'s destination path can be
a :data:`~glom.T` expression, for maximum control::

  # changing the error message of an exception in an error list
  >>> err = ValueError('initial message')
  >>> target = {'errors': [err]}
  >>> _ = glom(target, Assign(T['errors'][0].args, ('new message',)))
  >>> str(err)
  'new message'

``Assign`` has built-in support for assigning to attributes of
objects, keys of mappings (like dicts), and indexes of sequences
(like lists). Additional types can be registered through
:func:`~glom.register()` using the ``"assign"`` operation name.

Attempting to assign to an immutable structure, like a
:class:`tuple`, will result in a
:class:`~glom.PathAssignError`. Attempting to assign to a path
that doesn't exist will raise a :class:`~PathAccessError`.

To automatically backfill missing structures, you can pass a
callable to the *missing* argument. This callable will be called
for each path segment along the assignment which is not
present.

   >>> target = {}
   >>> assign(target, 'a.b.c', 'hi', missing=dict)
   {'a': {'b': {'c': 'hi'}}}

Nc                    [        U[        5      (       a  [        R                  " U5      nO>[	        U5      [
        L a  [        U5      nO [        U[        5      (       d  [        S5      e UR                  5       S   u  U l        U l	        Xl        US S U l        U R                  S;  a  [        S5      eX l        Ub  [        U5      (       d  [        SU< 35      eX0l        g ! [         a    [        S5      ef = f)N9path argument must be a .-delimited string, Path, T, or S#path must have at least one element[.Pz,last part of path must be setattr or setitemz%expected missing to be callable, not )
isinstance
basestringr   	from_texttyper   	TypeErroritemsoparg
IndexError
ValueError
_orig_pathr   r.   callablemissing)r   r   r.   rG   s       r   __init__Assign.__init__{   s     dJ''>>$'D$Z5 :DD$''WXX	D $

R 0DGTX "I	77%KLLG$$W VWW  	DBCC	Ds   , C& &C<c           
      r  ^^	^
^^ [        U R                  5      [        L a  T[           " XR                  T5      mOU R                  mU R                  U R
                  U R                  sm
m	mU R                  R                  [        5      (       a$  T[           nU R                  R                  5       nOUnU R                  n T[           " X4T5      nU	U
UUU4S jn[#        UTU5        U$ ! [         a  nU R                  (       d  e U R                  UR                  S-   S  nT[           " U R                  5       [        UTU R                  S9T5      mU R                  R!                  5       UR                     u  m
m	U R                  S UR                   mT[           " UTT5      n S nANS nAff = f)Nr   rG   c           	          > [        U TTTTTS9$ )N)destrA   rB   r.   r   scope)r   )rM   rB   rA   r   rN   r.   s    r   <lambda>Assign.glomit.<locals>.<lambda>   s    j"#3THr    )r>   r.   r   r	   rA   rB   r   
startswithr   r   from_tr   rG   rE   part_idxr4   r@   r2   )r   targetrN   dest_target	dest_pathrM   paeremaining_path_applyrB   rA   r   r.   s     `      @@@@r   glomitAssign.glomit   sa   >T!+fhh6C((C499C99"")K		((*I K		I	9;{u=DH Hd+!  		9<<!__S\\A-=->?N+dllnf^SRVR^R^._afgCoo++-cll;GB??=CLL1D;{D%8D		9s   C. .
F68B4F11F6c           	          U R                   R                  nU R                  c"  U< SU R                  < SU R                  < S3$ U< SU R                  < SU R                  < S[        U R                  5      < S3$ )N(z, )z
, missing=)	__class__r"   rG   rE   r.   r   r   cns     r   __repr__Assign.__repr__   sS    ^^$$<<#%tAA+-t&QUQ]Q]J^__r    )rE   rB   rG   rA   r   r.   N)	r"   r#   r$   r%   r&   rH   rZ   rb   r'   r!   r    r   r4   r4   <   s    =|8B`r    r4   c           	      *    [        U [        XUS95      $ )a  *New in glom 18.3.0*

The ``assign()`` function provides convenient "deep set"
functionality, modifying nested data structures in-place::

  >>> target = {'a': [{'b': 'c'}, {'d': None}]}
  >>> _ = assign(target, 'a.1.d', 'e')  # let's give 'd' a value of 'e'
  >>> pprint(target)
  {'a': [{'b': 'c'}, {'d': 'e'}]}

Missing structures can also be automatically created with the
*missing* parameter. For more information and examples, see the
:class:`~glom.Assign` specifier type, which this function wraps.
rK   )r	   r4   )objr   r.   rG   s       r   assignrg      s     VDw788r    c                     X [        U5      '   g rd   int)rT   idxr.   s      r   _set_sequence_itemrl      s    3s8r    c                     [        U [        5      (       a  g[        [        U SS 5      5      (       a1  [        [        U SS 5      5      (       a  [        $ [
        R                  $ [        $ )NF__setitem__index)
issubclass_UNASSIGNABLE_BASE_TYPESrF   getattrrl   operatorsetitemsetattrtype_objs    r   _assign_autodiscoverrx      sR    (455-677GHgt455%%Nr    rg   F)	auto_funcexactc                   4    \ rS rSrSrS	S jrS rS rS rSr	g)
Delete   a1  
In addition to glom's core "deep-get" and ``Assign``'s "deep-set",
the ``Delete`` specifier type performs a "deep-del", which can
remove items from larger data structures by key, attribute, and
index.

>>> target = {'dict': {'x': [5, 6, 7]}}
>>> glom(target, Delete('dict.x.1'))
{'dict': {'x': [5, 7]}}
>>> glom(target, Delete('dict.x'))
{'dict': {}}

If a target path is missing, a :exc:`PathDeleteError` will be
raised. To ignore missing targets, use the ``ignore_missing``
flag:

>>> glom(target, Delete('does_not_exist', ignore_missing=True))
{'dict': {}}

``Delete`` has built-in support for deleting attributes of
objects, keys of dicts, and indexes of sequences
(like lists). Additional types can be registered through
:func:`~glom.register()` using the ``"delete"`` operation name.

.. versionadded:: 20.5.0
c                    [        U[        5      (       a  [        R                  " U5      nO>[	        U5      [
        L a  [        U5      nO [        U[        5      (       d  [        S5      e UR                  5       S   u  U l        U l	        Xl        US S U l        U R                  S;  a  [        S5      eX l        g ! [         a    [        S5      ef = f)Nr7   r8   r9   r:   z/last part of path must be an attribute or index)r;   r<   r   r=   r>   r   r?   r@   rA   rB   rC   rD   rE   r   ignore_missing)r   r   r   s      r   rH   Delete.__init__  s    dJ''>>$'D$Z5 :DD$''WXX	D $

R 0DGTX "I	77%NOO,  	DBCC	Ds   , B> >Cc                    US:X  a   X	 g US:X  a   [	        X5        g US:X  a#  U[           R                  SU5      n U" X5        g g ! [          a1  nU R                  (       d  [        XPR                  U5      e S nAg S nAff = f! [
         a1  nU R                  (       d  [        XPR                  U5      e S nAg S nAff = f! [         a1  nU R                  (       d  [        XPR                  U5      e S nAg S nAff = f)N[.Pdelete)	rC   r   r   r   delattrAttributeErrorr   get_handler	Exception)r   rM   rA   rB   rN   e_deletes          r   _del_oneDelete._del_one  s    9=I 3Y=" 3YN+77$GG="   =**)!YY<< += " =**)!YY<< +=  =**)!YY<< +=sE   A B C 
B'A>>B
C'B<<C
C?'C::C?c                   ^ ^^^	 T R                   T R                  T R                  sm	mnT R                  R                  [        5      (       a$  T[
           nT R                  R                  5       nOUnT R                  n T[           " XET5      n[        UU	UU 4S jX65        U$ ! [         a  nT R                  (       d  e  S nAU$ S nAff = f)Nc                 ,   > TR                  U TTT5      $ rd   )r   )rM   rB   rA   rN   r   s    r   rO   Delete.glomit.<locals>.<lambda>?  s    tRe)Lr    )rA   rB   r   rQ   r   r   rR   r	   r2   r   r   )
r   rT   rN   r   rU   rV   rM   rW   rB   rA   s
   ` `     @@r   rZ   Delete.glomit1  s    499C99"")K		((*I K		I	Z;{u=D
 LdY  	&& '
 	s   B& &
C0CCc                 V    U R                   R                  nU< SU R                  < S3$ )Nr]   r^   )r_   r"   rE   r`   s     r   rb   Delete.__repr__C  s     ^^$$t//r    )rE   rB   r   rA   r   NF)
r"   r#   r$   r%   r&   rH   r   rZ   rb   r'   r!   r    r   r|   r|      s    4-(=*$0r    r|   c                 (    [        U [        XS95      $ )a\  
The ``delete()`` function provides "deep del" functionality,
modifying nested data structures in-place::

  >>> target = {'a': [{'b': 'c'}, {'d': None}]}
  >>> delete(target, 'a.0.b')
  {'a': [{}, {'d': None}]}

Attempting to delete missing keys, attributes, and indexes will
raise a :exc:`PathDeleteError`. To ignore these errors, use the
*ignore_missing* argument::

  >>> delete(target, 'does_not_exist', ignore_missing=True)
  {'a': [{}, {'d': None}]}

For more information and examples, see the :class:`~glom.Delete`
specifier type, which this convenience function wraps.

.. versionadded:: 20.5.0
)r   )r	   r|   )rf   r   r   s      r   r   r   H  s    * VD@AAr    c                     U [        U5      	 g rd   ri   )rT   rk   s     r   _del_sequence_itemr   `  s    s3xr    c                     [        U [        5      (       a  g[        [        U SS 5      5      (       a1  [        [        U SS 5      5      (       a  [        $ [
        R                  $ [        $ )NF__delitem__ro   )rp   rq   rF   rr   r   rs   delitemr   rv   s    r   _delete_autodiscoverr   d  sR    (455-677GHgt455%%Nr    r   rd   r   )0r&   rs   r   corer   r   r   r   r	   r
   r   r   r   r   r   r   r   r   r   r<   	NameErrorstrrr   __builtins__r   r   r2   objectr4   rg   valuesr;   r>   _ALL_BUILTIN_TYPESrp   tuple_BUILTIN_BASE_TYPESsetdictlistBaseExceptionrq   rl   rx   r|   r   r   r   )vts   00r   <module>r      s     \ \ \ Y Y
 <T*6  ((L9o 9*@`V @`F9$ ".!4!4!6N!6A*Q:Ma!6N "4 U"4Q(E>P 3R>P674?P6P 45>P 3R -S T "4 U  !%8!9#&dM64'P#Q"R S 
 H 4E BX0V X0vB0 H 4E B{
  J~ O3RUsA   D+ =D9D9!E0D> D>EE+D65D6>E