HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux spn-python 5.15.0-89-generic #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64
User: arjun (1000)
PHP: 8.1.2-1ubuntu2.20
Disabled: NONE
Upload Files
File: //home/arjun/projects/env/lib/python3.10/site-packages/vine/__pycache__/funtools.cpython-310.pyc
o

we.�@srdZddlmZddlmZgd�Zdd�Zdd�Zd	d
�Zdd�Z	ddd�Z
dd�Zdd�Zdd�Z
dd�Zd
S)zFunctional utilities.�)�Thenable��promise)�
maybe_promise�ensure_promise�ppartial�preplace�
ready_promise�starpromise�	transform�wrapcCs|rt|t�st|�S|S)zBReturn None if p is undefined, otherwise make sure it's a promise.)�
isinstancerr��p�r�F/home/arjun/projects/env/lib/python3.10/site-packages/vine/funtools.pyrs
rcCs|durt�St|�S)zeEnsure p is a promise.

    If p is not a promise, a new promise is created with p' as callback.
    N)rrrrrrrsrcOs,t|�}|r||j|_|r|j�|�|S)z-Create/modify promise with partial arguments.)r�args�kwargs�update)rrrrrrrsrcs���fdd�}t|�S)z�Replace promise arguments.

    This will force the promise to disregard any arguments
    the promise is fulfilled with, and to be called with the
    provided arguments instead.
    cs��i���S�Nr)�_�__�rrrrr�	_replacer/szpreplace.<locals>._replacerr)rrrrrrrr(srNcGst|�}||�|S)z)Create promise that is already fulfilled.)r)�callbackrrrrrr	4sr	cOst|||�S)z%Create promise, using star arguments.r)�funrrrrrr
;sr
cOs.t|�}tt||||f�}|�t�|j�|S)a?Filter final argument to a promise.

    E.g. to coerce callback argument to :class:`int`::

        transform(int, callback)

    or a more complex example extracting something from a dict
    and coercing the value to :class:`float`:

    .. code-block:: python

        def filter_key_value(key, filter_, mapping):
            return filter_(mapping[key])

        def get_page_expires(self, url, callback=None):
            return self.request(
                'GET', url,
                callback=transform(get_key, callback, 'PageExpireValue', int),
            )

    )rr�
_transback�then�throw)�filter_r�filter_args�
filter_kwargs�Prrrr@srcCs<z|||fi|��}W||�Sty|��YdSwr)�	Exceptionr)rrrr�retrrrr\s��rcs�fdd�}|S)z�Wrap promise.

    This wraps the promise such that if the promise is called with a promise as
    argument, we attach ourselves to that promise instead.
    cs6t|�dkrt|dt�r|d���S�|i|��S)Nr�)�lenr
rr)rrrrr�on_callkszwrap.<locals>.on_callr)rr'rrrresrr)�__doc__�abstractr�promisesr�__all__rrrrr	r
rrrrrrr�<module>s