
    O=d"                     R   d Z ddlZddlmZmZmZmZ ddlmZ ddl	m
Z
 ddlZddlmZ ddlZddlZ e            ZeeefZd ej                                        D             ZdZd	 Zd
 Zd ZddZd ZefdZefdZefdZ efdZ!d Z"ddZ#d Z$d Z% G d de          Z&d Z'dS )z-Generic utility methods not part of main API.    N)HashableIterableMappingSequence)Decimalwraps)getfullargspecc                 D    i | ]\  }}t          |t                    ||S  )
isinstancer   ).0keyvalues      8D:\Sites\api_v1\venv\Lib\site-packages\pydash/helpers.py
<dictcomp>r      s/    bbb:3jQVX`FaFabE3bbb    )__globals____builtins__c                     t          |          }d|v r|d         nt          | |          }t          ||g          } | |d|          S )zaInspect argspec of `iteratee` function and only pass the supported arguments when calling
    it.argcountN)lengetargcountmin)iterateeargskwargsmaxargsr   argstops         r   callitr       sZ     $iiG%/6%9%9vj!!{8U\?]?]H7H%&&G8T(7(^$$r   c                     t          | d          r| j        S t          | t                    st	          j        |           rd}n$d}	 t          | |          }n# t          $ r Y nw xY w|S )z+Return argument count of iteratee function.	_argcount   )hasattrr"   r   typepyd
is_builtin_getargcount	TypeError)r   r   r   s      r   r   r   %   s    x%% " !!(D!! 	S^H%=%= 		#Hg66HH 	 	 	D	 Os   A 
A%$A%c                 \   d }	 t          j        |           }t          d |j                                        D                       st          |j                  }n# t          t          t          f$ r Y nw xY w|,t          |           }|r|j
        st          |j                  }||}|S )Nc              3   J   K   | ]}|j         t          j        j        k    V  d S N)kindinspect	ParameterVAR_POSITIONAL)r   params     r   	<genexpr>z_getargcount.<locals>.<genexpr>F   s@       
 
?DEJ'+::
 
 
 
 
 
r   )r.   	signatureany
parametersvaluesr   r)   
ValueErrorAttributeErrorr
   varargsr   )r   r   r   sigargspecs        r   r(   r(   :   s    H+
 ))  
 
HKH]H]H_H_
 
 
 
 
 	+ 3>**H z>2     ** 	)7? 	)7<((HOs   A A76A7Fc              #     K   |t           j        }d}n%t          j        |          }t          |d          }t	          |           }|rt          t          |                    }|D ]\  }}t          |||| |          ||| fV   dS )z3Return iterative iteratee based on collection type.Nr#      )r   )r   )r&   identityr   r   iteratorreversedtupler    )objr   reversecbkr   itemsr   items           r   iteriterateerG   X   s      ll8$$sA...SMME 'u&& M M	TS$S8<<<dCLLLLLM Mr   c                    t          | t                    r|                                 S t          | d          r|                                 S t          | d          r!t          |                                           S t          | t                    rt          |           S t          | di                                           S )z&Return iterative based on object type.	iteritemsrE   __dict__)	r   r   rE   r$   rI   iterr   	enumerategetattr)rB   s    r   r?   r?   j   s    #w 	4yy{{	k	"	" 4}}	g		 4CIIKK   	C	"	" 4~~sJ++11333r   c                 z   t          | t                    rt          | ||          }nft          | t          t          f          r%t          | t
                    r#t          | d          rt          | ||          }nt          | ||          }|t          u r#t          dt          |            d| d          |S )a  
    Safely get an item by `key` from a sequence or mapping object when `default` provided.

    Args:
        obj (list|dict): Sequence or mapping to retrieve item from.
        key (mixed): Key or index identifying which item to retrieve.
        default (mixed, optional): Default value to return if `key` not found in `obj`.

    Returns:
        mixed: `obj[key]`, `obj.key`, or `default`.

    Raises:
        KeyError: If `obj` is missing key, index, or attribute and no default value provided.
    default_fieldszObject "z" does not have key "")r   dict_base_get_dictr   r   rA   r$   _base_get_object_base_get_itemUNSETKeyErrorreprrB   r   rP   r   s       r   base_getr[   x   s     #t 	:sC999gx011 :3:#*3	#:#::
 !c7;;;sC999~~H$s))HH#HHHIIILr   c                     |                      |t                    }|t          u rL|}t          |t                    s5	 |                      t          |          |          }n# t          $ r Y nw xY w|S r,   )getrW   r   int	ExceptionrZ   s       r   rT   rT      sz    GGCE~~#s## 	C'22   Ls   #A! !
A.-A.c                     	 | |         S # t           $ r Y nw xY wt          |t                    s&	 | t          |                   S # t           $ r Y nw xY w|S r,   )r_   r   r^   )rB   r   rP   s      r   rV   rV      s    3x    c3 	s3xx=  	 	 	D	 Ns   
 
A 
AAc                     t          | |t                    }|t          u r3t          |           |}	 t          | |          }n# t          $ r Y nw xY w|S )NrO   )rV   rW   _raise_if_restricted_keyrM   r_   rZ   s       r   rU   rU      sm    3U333E~~ %%%	C%%EE 	 	 	D	Ls   A 
AAc                 >    | t           v rt          d| d          d S )Nzaccess to restricted key z is not allowed)RESTRICTED_KEYSrX   )r   s    r   rb   rb      s/    
oI3IIIJJJ r   Tc                    t          | t                    r|s|| vr|| |<   nt          | t                    rit          |          }|t	          |           k     r|r|| |<   ns|t	          |           k    r| dg|z  z   d|         | dd<   |                     |           n4|st          | |          s"|  t          |           t          | ||           | S )a  
    Set an object's `key` to `value`. If `obj` is a ``list`` and the `key` is the next available
    index position, append to list; otherwise, pad the list of ``None`` and then append to the list.

    Args:
        obj (list|dict): Object to assign value to.
        key (mixed): Key or index to assign to.
        value (mixed): Value to assign.
        allow_override (bool): Whether to allow overriding a previously set key.
    N)	r   rS   listr^   r   appendr$   rb   setattr)rB   r   r   allow_overrides       r   base_setrj      s     #t ! 	S^^CH	C		 !#hhS>> ! CSXX~~ ,dsd3AAAJJu
 !S 1 1 !s %%%S%   Jr   c                 8    | |dS | dS |dS | |k    | |k     z
  S )z
    Replacement for built-in function ``cmp`` that was removed in Python 3.

    Note: Mainly used for comparison during sorting.
    Nr   r#   r   )abs     r   cmpro      s9     	yQYq	
r	
qEa!er   c                     |                     |           }|d         }|Gt          |          s,t          |t                    st          |t                    s||}|dd         }||fS )zvTry to find iteratee function passed in either as a keyword argument or as the last
    positional argument in `args`.rl   N)r]   callabler   strrS   )iteratee_keywordr   r   r   last_args        r   parse_iterateeru      s     zz*++HBxH h$$  h%%  CRCyT>r   c                   .    e Zd ZdZd Zd Zd Zd ZeZdS )iterator_with_defaultz<A wrapper around an iterator object that provides a default.c                 <    t          |          | _         || _        d S r,   )rK   rP   )self
collectionrP   s      r   __init__ziterator_with_default.__init__  s    $$	r   c                     | S r,   r   )ry   s    r   __iter__ziterator_with_default.__iter__  s    r   c                 ,    | j         }t          | _         |S r,   )rP   rW   ry   rets     r   next_defaultz"iterator_with_default.next_default  s    l
r   c                 t    t          | j        |                                           }|t          u rt          |S r,   )nextrK   r   rW   StopIterationr   s     r   __next__ziterator_with_default.__next__  s3    49d//1122%<<
r   N)	__name__
__module____qualname____doc__r{   r}   r   r   r   r   r   r   rw   rw   	  sW        FF      
   DDDr   rw   c                 <     t                      fd            }|S )z
    This is a decorator which can be used to mark functions as deprecated.

    It will result in a warning being emitted when the function is used.
    c                  ^    t          j        dj         dt          d            | i |S )NzCall to deprecated function .r=   )category
stacklevel)warningswarnr   DeprecationWarning)r   r   funcs     r   wrapperzdeprecated.<locals>.wrapper(  sI    ;4=;;;'	
 	
 	
 	

 tT$V$$$r   r   )r   r   s   ` r   
deprecatedr   !  s5     4[[% % % % [% Nr   )NF)T)(r   builtinscollections.abcr   r   r   r   decimalr   	functoolsr	   r.   r
   r   pydashr&   objectrW   r^   floatNUMBER_TYPESrJ   rE   BUILTINSrd   r    r   r(   rG   r?   r[   rT   rV   rU   rb   rj   ro   ru   rw   r   r   r   r   <module>r      s   3 3  A A A A A A A A A A A A              " " " " " "      	 UG$ cb):)@)@)B)Bbbb 2% % %  *  <M M M M$4 4 4  %    B &+ 
 
 
 
 &+     (- 	 	 	 	K K K   B    $    F   0    r   