o
    DfJ                     @  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r:d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Z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   clstype[_ObjectType]kwargsdict[str, Any]returnc                 C  s   | di |S N r   )r   r   r   r   G/home/ubuntu/webapp/venv/lib/python3.10/site-packages/kombu/abstract.pyunpickle_dict   s   r   vc                 C  s   | S Nr   )r   r   r   r   _any    s   r   c                   @  sH   e Zd ZU dZdZded< dd
dZddddZdddZdddZ	dS )r   zYCommon base class.

    Supports automatic kwargs->attributes handling, and cloning.
    r   ztuple[tuple[str, Any], ...]attrsargsr   r   r   Nonec              	   O  sh   | j D ].\}}||}|d urt| ||pt| qzt| | W q ty1   t| |d  Y qw d S r   )r    getsetattrr   getattrAttributeError)selfr!   r   nametype_valuer   r   r   __init__,   s   
zObject.__init__Frecurseboolr   c                   s&   d
dfdd  fdd	j D S )Nobjr   typeCallable[[Any], Any] | Noner   c                   s2    rt | tr| jddS |r| d ur|| S | S )NTr,   )
isinstancer   as_dict)r.   r/   r1   r   r   f8   s   zObject.as_dict.<locals>.fc                   s"   i | ]\}}| t ||qS r   )r%   ).0attrr/   )r4   r'   r   r   
<dictcomp><   s    z"Object.as_dict.<locals>.<dictcomp>r   )r.   r   r/   r0   r   r   )r    )r'   r,   r   )r4   r,   r'   r   r3   7   s   zObject.as_dictr'   r   ktuple[Callable[[type[_ObjectType], dict[str, Any]], _ObjectType], tuple[type[_ObjectType], dict[str, Any]]]c                 C  s   t | j|  ffS r   )r   	__class__r3   r'   r   r   r   
__reduce__@   s   zObject.__reduce__c                 C  s   | j di |  S r   )r9   r3   r:   r   r   r   __copy__F   s   zObject.__copy__N)r!   r   r   r   r   r"   )F)r,   r-   r   r   )r'   r   r   r8   )r'   r   r   r   )
__name__
__module____qualname____doc__r    __annotations__r+   r3   r;   r<   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Zd#ddZ	d#ddZ
d$ddZd%ddZd&ddZd'd(ddZed)dd Zed*d!d"ZdS )+r   z7Mixin for classes that can be bound to an AMQP channel.NzChannel | None_channelFr'   r   channelChannel | Connectionr   c                 C  s
   |  |S )z&`self(channel) -> self.bind(channel)`.)bindr'   rC   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_bindrF   r   r   r   rE   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	   rB   
when_bound	_is_boundrF   r   r   r   rH   _   s
   

zMaybeChannelBound.maybe_bindr   r"   c                 C  s   | j r|| _|   dS dS )zyRevive channel after the connection has been re-established.

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

        N)rI   rB   rJ   rF   r   r   r   revivei   s   zMaybeChannelBound.revivec                 C  s   dS )z(Callback called when the class is bound.Nr   r:   r   r   r   rJ   s   s    zMaybeChannelBound.when_boundstrc                 C  s   |  t| jS r   )_repr_entityr/   r=   r:   r   r   r   __repr__v   s   zMaybeChannelBound.__repr__ itemc                 C  s:   |pt | j}| jrd|pt | j| jjS d| dS )Nz<{} bound to chan:{}>z	<unbound >)r/   r=   rI   formatrC   
channel_id)r'   rQ   r   r   r   rN   y   s   zMaybeChannelBound._repr_entityr-   c                 C  s   | j o| jduS )z!Flag set if the channel is bound.N)rK   rB   r:   r   r   r   rI      s   zMaybeChannelBound.is_boundc                 C  s<   | j }|du rtdt| jt|tr|  }| _ |S )z'Current channel if the object is bound.Nz.Can't call method on {} not bound to a channel)rB   r
   rS   r/   r=   r2   r   rF   r   r   r   rC      s   
zMaybeChannelBound.channel)r'   r   rC   rD   r   r   )rC   r   r   r"   )r   r"   )r   rM   )rP   )rQ   rM   r   rM   )r   r-   )r   r   )r=   r>   r?   r@   rB   rA   rK   can_cache_declarationrG   rE   rH   rL   rJ   rO   rN   propertyrI   rC   r   r   r   r   r   J   s    
 







N)r   r   r   r   r   r   )r   r   r   r   )r@   
__future__r   r   typingr   r   r   r   
connectionr	   
exceptionsr
   utils.functionalr   kombu.connectionr   kombu.transport.virtualr   __all__r   r   r   r   r   r   r   r   r   r   r   <module>   s(    

&