
    O=dF                        d Z ddlmZ ddlmZ ddlmZmZ ddlZddlm	Z	m
Z
 ddlZddlZddlZddlmZmZmZmZmZmZ d	Z ej        d
          Z ej        d          Zda edddg          Zd Zd Zd Zd Zd Z d Z!d Z"d;dZ#d Z$d Z%d Z&d;dZ'd Z(d Z)d Z*d<dZ+d Z,d  Z-d! Z.d" Z/d# Z0d$ Z1d% Z2d=d'Zd( Z3d) Z4d;d*Z5d+d,d-d.de6fdfd/Z7d0 Z8d1 Z9d2 Z:d3 Z;d4 Z<d;d5Z=d6 Z>d;d7Z?d8 Z@d9 ZAd: ZBdS )>z-
Utility functions.

.. versionadded:: 1.0.0
    )
namedtuple)datetime)partialwrapsN)randintuniform   )NUMBER_TYPESUNSETbase_getcallitgetargcountiterator)$attemptcondconformsconforms_toconstant
default_todefault_to_anyidentityiterateematchesmatches_propertymemoizemethod	method_ofnoopnth_argnowover
over_every	over_some
properties	property_property_ofrandomrange_range_rightresultretry	stub_list	stub_dict
stub_falsestub_string	stub_truetimesto_path	unique_idz(?<!\\)(?:\\\\)*\.|(\[\d+\])z	^\[\d+\]$	PathTokenkeydefault_factoryc                 L    	  | |i |}n# t           $ r}|}Y d}~nd}~ww xY w|S )ax  
    Attempts to execute `func`, returning either the result or the caught error object.

    Args:
        func (callable): The function to attempt.

    Returns:
        mixed: Returns the `func` result or error object.

    Example:

        >>> results = attempt(lambda x: x/0, 1)
        >>> assert isinstance(results, ZeroDivisionError)

    .. versionadded:: 1.1.0
    N)	Exception)funcargskwargsretexs        :D:\Sites\api_v1\venv\Lib\site-packages\pydash/utilities.pyr   r   L   sR    "dD#F##    Js    
!!c                     |r gt          |          z     D ]k}d}	 t          |          dk    }n# t          $ r Y nw xY w|st          d          t	          t          t          |                    st          d          l fd}|S )a}  
    Creates a function that iterates over `pairs` and invokes the corresponding function of the
    first predicate to return truthy.

    Args:
        pairs (list): A list of predicate-function pairs.

    Returns:
        callable: Returns the new composite function.

    Example:

        >>> func = cond([[matches({'a': 1}), constant('matches A')],                         [matches({'b': 2}), constant('matches B')],                         [stub_true, lambda value: value]])
        >>> func({'a': 1, 'b': 2})
        'matches A'
        >>> func({'a': 0, 'b': 2})
        'matches B'
        >>> func({'a': 0, 'b': 0}) == {'a': 0, 'b': 0}
        True

    .. versionadded:: 4.0.0

    .. versionchanged:: 4.2.0
        Fixed missing argument passing to matched function and added support for passing in a single
        list of pairs instead of just pairs as separate arguments.
    F   z@Each predicate-function pair should contain exactly two elementsz/Both predicate-function pair should be callablec                  D    D ]}|\  }}t          |g| R  r ||  c S d S Nr   )r:   pair	predicater   pairss       r>   _condzcond.<locals>._cond   sU     	' 	'D"&Ixi'$''' 'x&&&'	' 	'    )listlenr8   
ValueErrorallmapcallable	TypeError)rF   extra_pairsrD   is_validrG   s   `    r>   r   r   e   s    :  ,${+++ O O	4yyA~HH 	 	 	D	  	dbccc3x&&'' 	OMNNN	O' ' ' ' ' Ls   2
??c                       fd}|S )a  
    Creates a function that invokes the predicate properties of `source` with the corresponding
    property values of a given object, returning ``True`` if all predicates return truthy, else
    ``False``.

    Args:
        source (dict|list): The object of property predicates to conform to.

    Returns:
        callable: Returns the new spec function.

    Example:

        >>> func = conforms({'b': lambda n: n > 1})
        >>> func({'b': 2})
        True
        >>> func({'b': 0})
        False
        >>> func = conforms([lambda n: n > 1, lambda n: n == 0])
        >>> func([2, 0])
        True
        >>> func([0, 0])
        False

    .. versionadded:: 4.0.0
    c                     t                    D ].\  }}t          j        | |          r || |                   s dS /dS )NFT)r   pydhas)objr5   rE   sources      r>   	_conformszconforms.<locals>._conforms   sX    &v.. 	 	NC73$$ IIc#h,?,? uutrH    )rW   rX   s   ` r>   r   r      s$    8     rH   c                 2     t          |          |           S )a|  
    Checks if `obj` conforms to `source` by invoking the predicate properties of `source` with the
    corresponding property values of `obj`.

    Args:
        obj (dict|list): The object to inspect.
        source (dict|list): The object of property predicates to conform to.

    Example:

        >>> conforms_to({'b': 2}, {'b': lambda n: n > 1})
        True
        >>> conforms_to({'b': 0}, {'b': lambda n: n > 1})
        False
        >>> conforms_to([2, 0], [lambda n: n > 1, lambda n: n == 0])
        True
        >>> conforms_to([0, 0], [lambda n: n > 1, lambda n: n == 0])
        False

    .. versionadded:: 4.0.0
    )r   rV   rW   s     r>   r   r      s    , 8FC   rH   c                 ,    t          t          |           S )a  
    Creates a function that returns `value`.

    Args:
        value (mixed): Constant value to return.

    Returns:
        callable: Function that always returns `value`.

    Example:

        >>> pi = constant(3.14)
        >>> pi() == 3.14
        True

    .. versionadded:: 1.0.0

    .. versionchanged:: 4.0.0
        Returned function ignores arguments instead of raising exception.
    )r   r   )values    r>   r   r      s    * 8U###rH   c                 "    t          | |          S )a  
    Checks `value` to determine whether a default value should be returned in its place. The
    `default_value` is returned if value is None.

    Args:
        value (mixed): Value passed in by the user.
        default_value (mixed): Default value passed in by the user.

    Returns:
        mixed: Returns `value` if :attr:`value` is given otherwise returns `default_value`.

    Example:

        >>> default_to(1, 10)
        1
        >>> default_to(None, 10)
        10

    .. versionadded:: 4.0.0
    )r   )r]   default_values     r>   r   r      s    * %///rH   c                 (    | f|z   }|D ]}||c S 	dS )a  
    Checks `value` to determine whether a default value should be returned in its place. The first
    item that is not None of the `default_values` is returned.

    Args:
        value (mixed): Value passed in by the user.
        *default_values (mixed): Default values passed in by the user.

    Returns:
        mixed: Returns `value` if :attr:`value` is given otherwise returns the first not None value
            of `default_values`.

    Example:

        >>> default_to_any(1, 10, 20)
        1
        >>> default_to_any(None, 10, 20)
        10
        >>> default_to_any(None, None, 20)
        20


    .. versionadded:: 4.9.0
    NrY   )r]   default_valuesvaluesvals       r>   r   r   
  s<    2 X&F  ?JJJ  rH   c                     | S )a;  
    Return the first argument provided to it.

    Args:
        *args (mixed): Arguments.

    Returns:
        mixed: First argument or ``None``.

    Example:

        >>> identity(1)
        1
        >>> identity(1, 2, 3)
        1
        >>> identity() is None
        True

    .. versionadded:: 1.0.0
    rY   )argr:   s     r>   r   r   )  s	    * JrH   c                 F   t          |           r| }nt          | t                    rt          |           } t          | t                    rt	          |           }nt          | t
                    r#t          |           dk    rt	          |           }nt          | t
                    r%t          |           dk    rt          | dd          }nKt          | t                    r
t          |  }n,t          | t                    rt          |           }nt          }d|_        |S )a  
    Return a pydash style iteratee. If `func` is a property name the created iteratee will return
    the property value for a given element. If `func` is an object the created iteratee will return
    ``True`` for elements that contain the equivalent object properties, otherwise it will return
    ``False``.

    Args:
        func (mixed): Object to create iteratee function from.

    Returns:
        callable: Iteratee function.

    Example:

        >>> get_data = iteratee('data')
        >>> get_data({'data': [1, 2, 3]})
        [1, 2, 3]
        >>> is_active = iteratee({'active': True})
        >>> is_active({'active': True})
        True
        >>> is_active({'active': 0})
        False
        >>> iteratee(['a', 5])({'a': 5})
        True
        >>> iteratee(['a.b'])({'a.b': 5})
        5
        >>> iteratee('a.b')({'a': {'b': 5}})
        5
        >>> iteratee(('a', ['c', 'd', 'e']))({'a': 1, 'c': {'d': {'e': 3}}})
        [1, 3]
        >>> iteratee(lambda a, b: a + b)(1, 2)
        3
        >>> ident = iteratee(None)
        >>> ident('a')
        'a'
        >>> ident(1, 2, 3)
        1

    .. versionadded:: 1.0.0

    .. versionchanged:: 2.0.0
        Renamed ``create_iteratee()`` to :func:`iteratee`.

    .. versionchanged:: 3.0.0
        Made pluck style iteratee support deep property access.

    .. versionchanged:: 3.1.0
        - Added support for shallow pluck style property access via single item list/tuple.
        - Added support for matches property style iteratee via two item list/tuple.

    .. versionchanged:: 4.0.0
        Removed alias ``callback``.

    .. versionchanged:: 4.1.0
        Return :func:`properties` callback when `func` is a ``tuple``.
    r	   Nr@   )rN   
isinstanceintstrr%   rI   rJ   r   tupler$   dictr   r   	_argcount)r9   cbks     r>   r   r   A  s   r ~~ dC   	t99DdC   	D//CCd## 		D		QD//CCd## 	D		A"D!H-CCe$$ 	d#CCd## 	$--CCC JrH   c                       fdS )a  
    Creates a matches-style predicate function which performs a deep comparison between a given
    object and the `source` object, returning ``True`` if the given object has equivalent property
    values, else ``False``.

    Args:
        source (dict): Source object used for comparision.

    Returns:
        callable: Function that compares an object to `source` and returns whether the two objects
            contain the same items.

    Example:

        >>> matches({'a': {'b': 2}})({'a': {'b': 2, 'c':3}})
        True
        >>> matches({'a': 1})({'b': 2, 'a': 1})
        True
        >>> matches({'a': 1})({'b': 2, 'a': 2})
        False

    .. versionadded:: 1.0.0

    .. versionchanged:: 3.0.0
        Use :func:`pydash.predicates.is_match` as matching function.
    c                 .    t          j        |           S rB   )rT   is_matchr[   s    r>   <lambda>zmatches.<locals>.<lambda>  s    s|C00 rH   rY   )rW   s   `r>   r   r     s    6 10000rH   c                 0    t          |           fdS )a?  
    Creates a function that compares the property value of `key` on a given object to `value`.

    Args:
        key (str): Object key to match against.
        value (mixed): Value to compare to.

    Returns:
        callable: Function that compares `value` to an object's `key` and returns whether they are
            equal.

    Example:

        >>> matches_property('a', 1)({'a': 1, 'b': 2})
        True
        >>> matches_property(0, 1)([1, 2, 3])
        True
        >>> matches_property('a', 2)({'a': 1, 'b': 2})
        False

    .. versionadded:: 3.1.0
    c                 F     t                     |                     S rB   )r   )rV   prop_accessorr]   s    r>   rq   z"matches_property.<locals>.<lambda>  s!    ~wu~~mmC&8&899 rH   )r%   )r5   r]   rt   s    `@r>   r   r     s#    . cNNM999999rH   c                 (      fdi _         S )aG  
    Creates a function that memoizes the result of `func`. If `resolver` is provided it will be used
    to determine the cache key for storing the result based on the arguments provided to the
    memoized function. By default, all arguments provided to the memoized function are used as the
    cache key. The result cache is exposed as the cache property on the memoized function.

    Args:
        func (callable): Function to memoize.
        resolver (callable, optional): Function that returns the cache key to use.

    Returns:
        callable: Memoized function.

    Example:

        >>> ident = memoize(identity)
        >>> ident(1)
        1
        >>> ident.cache['(1,){}'] == 1
        True
        >>> ident(1, 2, 3)
        1
        >>> ident.cache['(1, 2, 3){}'] == 1
        True

    .. versionadded:: 1.0.0
    c                  r    r	 | i |}n|  | }|j         vr | i |j         |<   j         |         S rB   cache)r:   r;   r5   r9   memoizedresolvers      r>   ry   zmemoize.<locals>.memoized  sf     	$(D+F++CC#6##Chn$$"&$"7"7"7HN3~c""rH   rw   )r9   rz   ry   s   ``@r>   r   r     s6    :	# 	# 	# 	# 	# 	# 	# HNOrH   c                       fd}|S )a  
    Creates a function that invokes the method at `path` on a given object. Any additional arguments
    are provided to the invoked method.

    Args:
        path (str): Object path of method to invoke.
        *args (mixed): Global arguments to apply to method when invoked.
        **kwargs (mixed): Global keyword argument to apply to method when invoked.

    Returns:
        callable: Function that invokes method located at path for object.

    Example:

        >>> obj = {'a': {'b': [None, lambda x: x]}}
        >>> echo = method('a.b.1')
        >>> echo(obj, 1) == 1
        True
        >>> echo(obj, 'one') == 'one'
        True

    .. versionadded:: 3.3.0
    c                 d    t          j        t          j        |           gR i } ||i |S rB   rT   r   get)rV   _args_kwargsr9   r:   r;   paths       r>   _methodzmethod.<locals>._method  C    {373--??????tU&g&&&rH   rY   )r   r:   r;   r   s   ``` r>   r   r     s/    2' ' ' ' ' ' ' NrH   c                       fd}|S )a  
    The opposite of :func:`method`. This method creates a function that invokes the method at a
    given path on object. Any additional arguments are provided to the invoked method.

    Args:
        obj (mixed): The object to query.
        *args (mixed): Global arguments to apply to method when invoked.
        **kwargs (mixed): Global keyword argument to apply to method when invoked.

    Returns:
        callable: Function that invokes method located at path for object.

    Example:

        >>> obj = {'a': {'b': [None, lambda x: x]}}
        >>> dispatch = method_of(obj)
        >>> dispatch('a.b.1', 1) == 1
        True
        >>> dispatch('a.b.1', 'one') == 'one'
        True

    .. versionadded:: 3.3.0
    c                 d    t          j        t          j        |           gR i } ||i |S rB   r}   )r   r   r   r9   r:   r;   rV   s       r>   
_method_ofzmethod_of.<locals>._method_of3  r   rH   rY   )rV   r:   r;   r   s   ``` r>   r   r     s0    2' ' ' ' ' ' ' rH   c                      dS )z?
    A no-operation function.

    .. versionadded:: 1.0.0
    NrY   )r:   r;   s     r>   r   r   :  s	     	DrH   c                       fd}|S )a  
    Creates a function that gets the argument at index n. If n is negative, the nth argument from
    the end is returned.

    Args:
        pos (int): The index of the argument to return.

    Returns:
        callable: Returns the new pass-thru function.

    Example:

        >>> func = nth_arg(1)
        >>> func(11, 22, 33, 44)
        22
        >>> func = nth_arg(-1)
        >>> func(11, 22, 33, 44)
        44

    .. versionadded:: 4.0.0
    c                      	 t          j        t                              }n# t          $ r d}Y nw xY wt	          j        | |          S )Nr   )mathceilfloatrK   rT   r~   )r:   positionposs     r>   _nth_argznth_arg.<locals>._nth_argZ  sW    	ys,,HH 	 	 	HHH	 wtX&&&s   !% 44rY   )r   r   s   ` r>   r   r   C  s#    .' ' ' ' ' OrH   c                  
   t          j        d          } t          j                    | z
  }t          |d          r|                                }n#|j        |j        |j        dz  dz  z   dz  z   dz  }t          |dz            S )a)  
    Return the number of milliseconds that have elapsed since the Unix epoch (1 January 1970
    00:00:00 UTC).

    Returns:
        int: Milliseconds since Unix epoch.

    .. versionadded:: 1.0.0

    .. versionchanged:: 3.0.0
        Use ``datetime`` module for calculating elapsed time.
    r   total_seconds   i  i@B i  )	r   utcfromtimestamputcnowhasattrr   microsecondssecondsdaysrh   )epochdeltar   s      r>   r    r    e  s     %a((EO%Euo&& %%'' %-%*r/D2H"HE!QQ w~rH   c                       fd}|S )a  
    Creates a function that invokes all functions in `funcs` with the arguments it receives and
    returns their results.

    Args:
        funcs (list): List of functions to be invoked.

    Returns:
        callable: Returns the new pass-thru function.

    Example:

        >>> func = over([max, min])
        >>> func(1, 2, 3, 4)
        [4, 1]

    .. versionadded:: 4.0.0
    c                  "      fdD             S )Nc                     g | ]} | S rY   rY   .0r9   r:   s     r>   
<listcomp>z'over.<locals>._over.<locals>.<listcomp>  s    ...d...rH   rY   r:   funcss   `r>   _overzover.<locals>._over  s    ........rH   rY   )r   r   s   ` r>   r!   r!     s#    (/ / / / / LrH   c                       fd}|S )a  
    Creates a function that checks if all of the functions in `funcs` return truthy when invoked
    with the arguments it receives.

    Args:
        funcs (list): List of functions to be invoked.

    Returns:
        callable: Returns the new pass-thru function.

    Example:

        >>> func = over_every([bool, lambda x: x is not None])
        >>> func(1)
        True

    .. versionadded:: 4.0.0
    c                  <     t           fdD                       S )Nc              3   "   K   | ]	} | V  
d S rB   rY   r   s     r>   	<genexpr>z2over_every.<locals>._over_every.<locals>.<genexpr>  )      11444;111111rH   )rL   r   s   `r>   _over_everyzover_every.<locals>._over_every  '    11115111111rH   rY   )r   r   s   ` r>   r"   r"     s$    (2 2 2 2 2 rH   c                       fd}|S )a  
    Creates a function that checks if any of the functions in `funcs` return truthy when invoked
    with the arguments it receives.

    Args:
        funcs (list): List of functions to be invoked.

    Returns:
        callable: Returns the new pass-thru function.

    Example:

        >>> func = over_some([bool, lambda x: x is None])
        >>> func(1)
        True

    .. versionadded:: 4.0.0
    c                  <     t           fdD                       S )Nc              3   "   K   | ]	} | V  
d S rB   rY   r   s     r>   r   z0over_some.<locals>._over_some.<locals>.<genexpr>  r   rH   )anyr   s   `r>   
_over_somezover_some.<locals>._over_some  r   rH   rY   )r   r   s   ` r>   r#   r#     s$    (2 2 2 2 2 rH   c                       fdS )a8  
    Creates a function that returns the value at path of a given object.

    Args:
        path (str|list): Path value to fetch from object.

    Returns:
        callable: Function that returns object's path value.

    Example:

        >>> get_data = property_('data')
        >>> get_data({'data': 1})
        1
        >>> get_data({}) is None
        True
        >>> get_first = property_(0)
        >>> get_first([1, 2, 3])
        1

    .. versionadded:: 1.0.0

    .. versionchanged:: 4.0.1
        Made property accessor work with deep path strings.
    c                 .    t          j        |           S rB   rT   r~   )rV   r   s    r>   rq   zproperty_.<locals>.<lambda>  s    swsD)) rH   rY   )r   s   `r>   r%   r%     s    4 *))))rH   c                        fdS )a  
    Like :func:`property_` except that it returns a list of values at each path in `paths`.

    Args:
        *path (str|list): Path values to fetch from object.

    Returns:
        callable: Function that returns object's path value.

    Example:

        >>> getter = properties('a', 'b', ['c', 'd', 'e'])
        >>> getter({'a': 1, 'b': 2, 'c': {'d': {'e': 3}}})
        [1, 2, 3]

    .. versionadded:: 4.1.0
    c                 6      fdd D             D             S )Nc                 &    g | ]} |          S rY   rY   )r   getterrV   s     r>   r   z0properties.<locals>.<lambda>.<locals>.<listcomp>  s!    ZZZsZZZrH   c              3   >   K   | ]}t          j        |          V  d S rB   )rT   r%   )r   r   s     r>   r   z/properties.<locals>.<lambda>.<locals>.<genexpr>  s,      2Y2Y43=3F3F2Y2Y2Y2Y2Y2YrH   rY   )rV   pathss   `r>   rq   zproperties.<locals>.<lambda>  s-    ZZZZ2Y2YSX2Y2Y2YZZZ rH   rY   )r   s   `r>   r$   r$     s    $ [ZZZZrH   c                       fdS )a'  
    The inverse of :func:`property_`. This method creates a function that returns the key value of a
    given key on `obj`.

    Args:
        obj (dict|list): Object to fetch values from.

    Returns:
        callable: Function that returns object's key value.

    Example:

        >>> getter = property_of({'a': 1, 'b': 2, 'c': 3})
        >>> getter('a')
        1
        >>> getter('b')
        2
        >>> getter('x') is None
        True

    .. versionadded:: 3.0.0

    .. versionchanged:: 4.0.0
        Removed alias ``prop_of``.
    c                 .    t          j        |           S rB   r   )r5   rV   s    r>   rq   zproperty_of.<locals>.<lambda>  s    swsC(( rH   rY   )rV   s   `r>   r&   r&      s    4 )((((rH   Fc                     t          | t                    pt          |t                    p|du }|| k     r| |} }|rt          | |          }nt          | |          }|S )a  
    Produces a random number between `start` and `stop` (inclusive). If only one argument is
    provided a number between 0 and the given number will be returned. If floating is truthy or
    either `start` or `stop` are floats a floating-point number will be returned instead of an
    integer.

    Args:
        start (int): Minimum value.
        stop (int): Maximum value.
        floating (bool, optional): Whether to force random value to ``float``. Defaults to
            ``False``.

    Returns:
        int|float: Random value.

    Example:

        >>> 0 <= random() <= 1
        True
        >>> 5 <= random(5, 10) <= 10
        True
        >>> isinstance(random(floating=True), float)
        True

    .. versionadded:: 1.0.0
    T)rg   r   r   r   )startstopfloatingrnds       r>   r'   r'     sl    6 %''V:dE+B+BVhRVFVHe||Te #eT""eT""JrH   c                      t          |  S )a  
    Creates a list of numbers (positive and/or negative) progressing from start up to but not
    including end. If `start` is less than `stop`, a zero-length range is created unless a negative
    `step` is specified.

    Args:
        start (int, optional): Integer to start with. Defaults to ``0``.
        stop (int): Integer to stop at.
        step (int, optional): The value to increment or decrement by. Defaults to ``1``.

    Yields:
        int: Next integer in range.

    Example:

        >>> list(range_(5))
        [0, 1, 2, 3, 4]
        >>> list(range_(1, 4))
        [1, 2, 3]
        >>> list(range_(0, 6, 2))
        [0, 2, 4]
        >>> list(range_(4, 1))
        [4, 3, 2]

    .. versionadded:: 1.0.0

    .. versionchanged:: 1.1.0
        Moved to :mod:`pydash.uilities`.

    .. versionchanged:: 3.0.0
        Return generator instead of list.

    .. versionchanged:: 4.0.0
        Support decrementing when start argument is greater than stop argument.
    
base_ranger:   s    r>   r(   r(   E  s    H trH   c                      t          | ddiS )ac  
    Similar to :func:`range_`, except that it populates the values in descending order.

    Args:
        start (int, optional): Integer to start with. Defaults to ``0``.
        stop (int): Integer to stop at.
        step (int, optional): The value to increment or decrement by. Defaults to ``1`` if `start`
            < `stop` else ``-1``.

    Yields:
        int: Next integer in range.

    Example:

        >>> list(range_right(5))
        [4, 3, 2, 1, 0]
        >>> list(range_right(1, 4))
        [3, 2, 1]
        >>> list(range_right(0, 6, 2))
        [4, 2, 0]

    .. versionadded:: 4.0.0
    
from_rightTr   r   s    r>   r)   r)   l  s    0 t----rH   c                 d    | s|S t          | ||          }t          |          r
 |            }|S )ax  
    Return the value of property `key` on `obj`. If `key` value is a function it will be invoked and
    its result returned, else the property value is returned. If `obj` is falsey then `default` is
    returned.

    Args:
        obj (list|dict): Object to retrieve result from.
        key (mixed): Key or index to get result from.
        default (mixed, optional): Default value to return if `obj` is falsey. Defaults to ``None``.

    Returns:
        mixed: Result of ``obj[key]`` or ``None``.

    Example:

        >>> result({'a': 1, 'b': lambda: 2}, 'a')
        1
        >>> result({'a': 1, 'b': lambda: 2}, 'b')
        2
        >>> result({'a': 1, 'b': lambda: 2}, 'c') is None
        True
        >>> result({'a': 1, 'b': lambda: 2}, 'c', default=False)
        False

    .. versionadded:: 1.0.0

    .. versionchanged:: 2.0.0
        Added ``default`` argument.
    )default)r   rN   )rV   r5   r   r<   s       r>   r*   r*     sC    <  
3W
-
-
-C}} ceeJrH      g      ?g     b@g       @c                     t           t                    r dk    rt          d          t          t                    rdk     rt          d          t          t                    rdk     rt          d          t          t                    rdk    rt          d          t          t          t          fz             r\t          t                    rdk     sAt          t                    r;t                    dk    st          d D                       st          d          t          t                    rt          d	 D                       st          d
          rt                    st          d          rt          t                    sdfrt          d          nd fd}|S )a?	  
    Decorator that retries a function multiple times if it raises an exception with an optional
    delay between each attempt.

    When a `delay` is supplied, there will be a sleep period in between retry
    attempts. The first delay time will always be equal to `delay`. After
    subsequent retries, the delay time will be scaled by `scale` up to
    `max_delay`. If `max_delay` is ``0``, then `delay` can increase unbounded.

    Args:
        attempts (int, optional): Number of retry attempts. Defaults to ``3``.
        delay (int|float, optional): Base amount of seconds to sleep between retry attempts.
            Defaults to ``0.5``.
        max_delay (int|float, optional): Maximum number of seconds to sleep between retries. Is
            ignored when equal to ``0``. Defaults to ``150.0`` (2.5 minutes).
        scale (int|float, optional): Scale factor to increase `delay` after first retry fails.
            Defaults to ``2.0``.
        jitter (int|float|tuple, optional): Random jitter to add to `delay` time. Can be a positive
            number or 2-item tuple of numbers representing the random range to choose from. When a
            number is given, the random range will be from ``[0, jitter]``. When jitter is a float
            or contains a float, then a random float will be chosen; otherwise, a random integer
            will be selected. Defaults to ``0`` which disables jitter.
        exceptions (tuple, optional): Tuple of exceptions that trigger a retry attempt. Exceptions
            not in the tuple will be ignored. Defaults to ``(Exception,)`` (all exceptions).
        on_exception (callable, optional): Function that is called when a retryable exception is
            caught. It is invoked with ``on_exception(exc, attempt)`` where ``exc`` is the caught
            exception and ``attempt`` is the attempt count. All arguments are optional. Defaults to
            ``None``.

    Example:

        >>> @retry(attempts=3, delay=0)
        ... def do_something():
        ...     print('something')
        ...     raise Exception('something went wrong')
        >>> try: do_something()
        ... except Exception: print('caught something')
        something
        something
        something
        caught something

    ..versionadded:: 4.4.0

    ..versionchanged:: 4.5.0
        Added ``jitter`` argument.
    r   z*attempts must be an integer greater than 0z1delay must be a number greater than or equal to 0z1scale must be a number greater than or equal to 0z%scale must be a number greater than 0r@   c              3   @   K   | ]}t          |t                    V  d S rB   )rg   r
   )r   jits     r>   r   zretry.<locals>.<genexpr>  s,      ,],]sZ\-J-J,],],],],],]rH   zCjitter must be a number greater than 0 or a 2-item tuple of numbersc              3   @   K   | ]}t          |t                    V  d S rB   )
issubclassr8   )r   excs     r>   r   zretry.<locals>.<genexpr>  s=       4 4'*
3	""4 4 4 4 4 4rH   z-exceptions must be a tuple of Exception typeszon_exception must be a callablemaxargsNc           
      N     t                      	f	d            }|S )Nc            	      L  	 }t          ddz             D ]}	  | i |c S # $ rx}rt          ||           |k    r 	r|t          dt          	           z  }|dk     rY d }~U
rt	          |
          }t          j        |           |z  }Y d }~d }~ww xY wd S )Nr	   argcountr   )ranger   maxr'   mintimesleep)r:   r;   
delay_timer   r   attemptsdelay
exceptionsr9   jitter	max_delayon_exc_argcounton_exceptionscales        r>   	decoratedz+retry.<locals>.decorator.<locals>.decorated  s   J HqL11 ( ((4000000! ( ( (# U|S'OTTTT(** >"c!VV_&=&==
!A~~   @%(Y%?%?
Jz*** %'JJJJJJ'(	( (s   $B!>B,+BB!)r   )
r9   r   r   r   r   r   r   r   r   r   s
   ` r>   	decoratorzretry.<locals>.decorator  s]    	t	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 
	(8 rH   )
rg   rh   rK   r
   rj   rJ   rL   rO   rN   r   )	r   r   r   r   r   r   r   r   r   s	   ``````` @r>   r+   r+     s<   p h$$ GAEFFFe\** NeaiiLMMMi.. N)a--LMMMe\** Beqjj@AAA v|uh677cv|,,c17!vu%% 2< V!!,],]V\,],],])])]! abbbj%(( I 4 4.84 4 4 1 1 I GHHH ;H\22 ;9::: j// V>JTk,::::PTO           @ rH   c                      g S )z
    Returns empty "list".

    Returns:
        list: Empty list.

    Example:

        >>> stub_list()
        []

    .. versionadded:: 4.0.0
    rY   rY   rH   r>   r,   r,   .  	     IrH   c                      i S )z
    Returns empty "dict".

    Returns:
        dict: Empty dict.

    Example:

        >>> stub_dict()
        {}

    .. versionadded:: 4.0.0
    rY   rY   rH   r>   r-   r-   ?  r   rH   c                      dS )z
    Returns ``False``.

    Returns:
        bool: False

    Example:

        >>> stub_false()
        False

    .. versionadded:: 4.0.0
    FrY   rY   rH   r>   r.   r.   P  s	     5rH   c                      dS )z
    Returns an empty string.

    Returns:
        str: Empty string

    Example:

        >>> stub_string()
        ''

    .. versionadded:: 4.0.0
     rY   rY   rH   r>   r/   r/   a  s	     2rH   c                      dS )z
    Returns ``True``.

    Returns:
        bool: True

    Example:

        >>> stub_true()
        True

    .. versionadded:: 4.0.0
    TrY   rY   rH   r>   r0   r0   r  s	     4rH   c                 x    
t           dnt          d          fdt          |           D             S )a  
    Executes the iteratee `n` times, returning a list of the results of each iteratee execution. The
    iteratee is invoked with one argument: ``(index)``.

    Args:
        n (int): Number of times to execute `iteratee`.
        iteratee (callable): Function to execute.

    Returns:
        list: A list of results from calling `iteratee`.

    Example:

        >>> times(5, lambda i: i)
        [0, 1, 2, 3, 4]

    .. versionadded:: 1.0.0

    .. versionchanged:: 3.0.0
        Reordered arguments to make `iteratee` first.

    .. versionchanged:: 4.0.0

        - Re-reordered arguments to make `iteratee` last argument.
        - Added functionality for handling `iteratee` with zero positional arguments.
    Nr	   r   c                 4    g | ]}t          |           S )r   rC   )r   indexr   r   s     r>   r   ztimes.<locals>.<listcomp>  s(    MMM5F8UX666MMMrH   )r   r   r   )nr   r   s    `@r>   r1   r1     sM    6 x333MMMMME!HHMMMMrH   c                     t          |           }t          |t                    rd t          |           D             }n|g}|S )a  
    Converts values to a property path array.

    Args:
        value (mixed): Value to convert.

    Returns:
        list: Returns the new property path array.

    Example:

        >>> to_path('a.b.c')
        ['a', 'b', 'c']
        >>> to_path('a[0].b.c')
        ['a', 0, 'b', 'c']
        >>> to_path('a[0][1][2].b.c')
        ['a', 0, 1, 2, 'b', 'c']

    .. versionadded:: 4.0.0

    .. versionchanged:: 4.2.1
        Ensure returned path is always a list.
    c                 J    g | ] }t          |t                    r|j        n|!S rY   )rg   r4   r5   )r   tokens     r>   r   zto_path.<locals>.<listcomp>  s:     
 
 
EJE955@EII5
 
 
rH   )to_path_tokensrg   rI   )r]   tokensr   s      r>   r2   r2     sZ    0 E""F&$ 
 
N\]bNcNc
 
 
 xKrH   c                 ^    t           dz  a | d} nt          j        |           } |  t            S )an  
    Generates a unique ID. If `prefix` is provided the ID will be appended to  it.

    Args:
        prefix (str, optional): String prefix to prepend to ID value.

    Returns:
        str: ID value.

    Example:

        >>> unique_id()
        '1'
        >>> unique_id('id_')
        'id_2'
        >>> unique_id()
        '3'

    .. versionadded:: 1.0.0
    r	   Nr   )
ID_COUNTERrT   	to_string)prefixs    r>   r3   r3     s9    . !OJ~v&&"j"""rH   c                 @   t          j        |           r;d| v sd| v r3d t          dt                              |                     D             }nNt          j        |           st          j        |           rt          | t                    g}n| t          u rg }n| }|S )z.Parse `value` into :class:`PathToken` objects..[c           	          g | ]j}t                               |          r+t          t          |d d                   t                    n"t          t          |          t                    kS )r	   r6   )RE_PATH_LIST_INDEXmatchr4   rh   rI   unescape_path_keyrk   )r   r5   s     r>   r   z"to_path_tokens.<locals>.<listcomp>  sw     
 
 
  "'',,IIc#ad)nnd;;;;,S114HHH
 
 
rH   Nr   )	rT   	is_stringfilterRE_PATH_KEY_DELIMsplit	is_numberr4   rk   r   )r]   keyss     r>   r   r     s    
}U 
 
 d$5$;$;E$B$BCC	
 
 
 
u		 u!5!5 %6667	%KrH   c                 ^    |                      dd          } |                      dd          } | S )zUnescape path key.z\\\z\.r   )replace)r5   s    r>   r  r    s-    
++eT
"
"C
++eT
"
"CJrH   c                      |                     dd          t                     dk    r dd          nCt                     dk    r d          d         df nt                     dk    rd d         df  r d          dd         }n }|D ]<}t          |t                    s%t	          dt          |          j        d	          = fd
} |            S )zYield range values.r   Fr   Nr@   r   r	   zrange cannot interpret z object as an integerc               3      K   sd S \  } }}|
| |k     rdnd}t          t          t          j        || z
  |pdz            dg                    }r| ||z  |z
  z  } |dz  }|r| V  | |z  } |dz  }|d S d S )Nr	   r   r   )rh   r   r   r   )r   r   steplengthr:   r   s       r>   genzbase_range.<locals>.gen  s       	F tT<11"DS$)TE\dia$@AA1EFFGG 	dVmt++EBJD 	KKKTMEaKF	  	 	 	 	 	rH   )r~   rJ   rg   rh   rO   type__name__)r:   r;   
check_argsre   r  r   s   `    @r>   r   r     s   L%00J
4yyA~~BQBx	TaQa$'	Ta47D! Q"1"X


 c c#s## 	cad3ii6Haaabbb	c     * 355LrH   rB   )r   )r   r	   F)C__doc__collectionsr   r   	functoolsr   r   r   r'   r   r   rer   pydashrT   helpersr
   r   r   r   r   r   __all__compiler  r   r   r4   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r    r!   r"   r#   r%   r$   r&   r(   r)   r*   r8   r+   r,   r-   r.   r/   r0   r1   r2   r3   r   r  r   rY   rH   r>   <module>r     s    # " " " " "       $ $ $ $ $ $ $ $  # # # # # # # # 				      Q Q Q Q Q Q Q Q Q Q Q Q Q Q Q Q%X BJ>??   RZ--  
J{U,=$>??	  24 4 4n" " "J! ! !2$ $ $00 0 00  >   0P P Pf1 1 1<: : :6* * * *Z  @  @	 	 	   D  6  4  4  4* * *:[ [ [*) ) ):% % % %P$ $ $N. . .6& & & &T 

|{ { { {|  "  "  "  "  "!N !N !N !NH  D# # # #J  ,  ) ) ) ) )rH   