U
    .eJ                     @  s   d Z ddlmZ ddlm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mZ ertdd	lmZ dd
lmZ dZedZedddZedddZddddddZdddddZG dd dZG dd deZdS )zObject utilities.    )annotations)copy)TYPE_CHECKINGAnyCallableTypeVar   )maybe_channel)NotBoundError)ChannelPromise)
Connection)Channel)ObjectMaybeChannelBound_T_ObjectTyper   )bound_MaybeChannelBoundTyper   ztype[_ObjectType]dict[str, Any])clskwargsreturnc                 C  s
   | f |S N )r   r   r   r   2/tmp/pip-unpacked-wheel-48hrr5dg/kombu/abstract.pyunpickle_dict   s    r   )vr   c                 C  s   | S r   r   )r   r   r   r   _any    s    r   c                   @  sb   e Zd ZU dZdZded< dddddd	ZddddddZdddddZdddddZ	dS )r   zYCommon base class.

    Supports automatic kwargs->attributes handling, and cloning.
    r   ztuple[tuple[str, Any], ...]attrsr   None)argsr   r   c              	   O  sl   | j D ]`\}}||}|d k	r6t| ||p,t| qzt| | W q tk
rd   t| |d  Y qX qd S r   )r   getsetattrr   getattrAttributeError)selfr    r   nametype_valuer   r   r   __init__,   s    
zObject.__init__Fboolr   )recurser   c                   s.   dddddfdd  fddj D S )	Nr   zCallable[[Any], Any] | None)objtyper   c                   s2    rt | tr| jddS |r.| d k	r.|| S | S )NTr+   )
isinstancer   as_dict)r,   r-   r.   r   r   f8   s    zObject.as_dict.<locals>.fc                   s"   i | ]\}}| t ||qS r   )r#   ).0attrr-   )r1   r%   r   r   
<dictcomp><   s     z"Object.as_dict.<locals>.<dictcomp>)N)r   )r%   r+   r   )r1   r+   r%   r   r0   7   s    zObject.as_dictr   zktuple[Callable[[type[_ObjectType], dict[str, Any]], _ObjectType], tuple[type[_ObjectType], dict[str, Any]]])r%   r   c                 C  s   t | j|  ffS r   )r   	__class__r0   r%   r   r   r   
__reduce__@   s    zObject.__reduce__c                 C  s   | j f |  S r   )r5   r0   r6   r   r   r   __copy__F   s    zObject.__copy__N)F)
__name__
__module____qualname____doc__r   __annotations__r)   r0   r7   r8   r   r   r   r   r   $   s   
	c                   @  s   e Zd ZU dZdZded< dZdZddddd	d
ZddddddZ	ddddddZ
dddddZddddZddddZd#dddddZedddd Zeddd!d"ZdS )$r   z7Mixin for classes that can be bound to an AMQP channel.NzChannel | None_channelFr   zChannel | Connection)r%   channelr   c                 C  s
   |  |S )z&`self(channel) -> self.bind(channel)`.)bindr%   r?   r   r   r   __call__S   s    zMaybeChannelBound.__call__c                 C  s   t | |S )z7Create copy of the instance that is bound to a channel.)r   
maybe_bindrA   r   r   r   r@   Y   s    zMaybeChannelBound.bindc                 C  s&   | j s"|r"t|| _|   d| _| S )z.Bind instance to channel if not already bound.T)is_boundr	   r>   
when_bound	_is_boundrA   r   r   r   rC   _   s
    

zMaybeChannelBound.maybe_bindr   r   )r?   r   c                 C  s   | j r|| _|   dS )zyRevive channel after the connection has been re-established.

        Used by :meth:`~kombu.Connection.ensure`.

        N)rD   r>   rE   rA   r   r   r   revivei   s    zMaybeChannelBound.revive)r   c                 C  s   dS )z(Callback called when the class is bound.Nr   r6   r   r   r   rE   s   s    zMaybeChannelBound.when_boundstrc                 C  s   |  t| jS r   )_repr_entityr-   r9   r6   r   r   r   __repr__v   s    zMaybeChannelBound.__repr__ )itemr   c                 C  s:   |pt | j}| jr.d|p$t | j| jjS d| dS )Nz<{} bound to chan:{}>z	<unbound >)r-   r9   rD   formatr?   Z
channel_id)r%   rL   r   r   r   rI   y   s     zMaybeChannelBound._repr_entityr*   c                 C  s   | j o| jdk	S )z!Flag set if the channel is bound.N)rF   r>   r6   r   r   r   rD      s    zMaybeChannelBound.is_boundc                 C  s<   | j }|dkr"tdt| jt|tr8|  }| _ |S )z'Current channel if the object is bound.Nz.Can't call method on {} not bound to a channel)r>   r
   rN   r-   r9   r/   r   rA   r   r   r   r?      s    
zMaybeChannelBound.channel)rK   )r9   r:   r;   r<   r>   r=   rF   Zcan_cache_declarationrB   r@   rC   rG   rE   rJ   rI   propertyrD   r?   r   r   r   r   r   J   s   


N)r<   
__future__r   r   typingr   r   r   r   
connectionr	   
exceptionsr
   Zutils.functionalr   Zkombu.connectionr   Zkombu.transport.virtualr   __all__r   r   r   r   r   r   r   r   r   r   r   <module>   s(    &