U
    d                     @   sj   d Z ddlmZ ddlmZ ddlmZ ddlmZ dZdd	 Z	d
d Z
G dd dZG dd deZdS )zObject utilities.    )copy   )maybe_channel)NotBoundError)ChannelPromise)ObjectMaybeChannelBoundc                 C   s
   | f |S N )clskwargsr
   r
   2/tmp/pip-unpacked-wheel-hqfrjlvz/kombu/abstract.pyunpickle_dict   s    r   c                 C   s   | S r	   r
   )vr
   r
   r   _any   s    r   c                   @   s6   e Zd ZdZdZdd ZdddZdd	 Zd
d ZdS )r   zYCommon base class.

    Supports automatic kwargs->attributes handling, and cloning.
    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	   )attrsgetsetattrr   getattrAttributeError)selfargsr   nametype_valuer
   r
   r   __init__   s    
zObject.__init__Fc                    s"   fdd  fddj D S )Nc                    s2    rt | tr| jddS |r.| d k	r.|| S | S )NTrecurse)
isinstancer   as_dict)objtyper   r
   r   f(   s    zObject.as_dict.<locals>.fc                    s"   i | ]\}}| t ||qS r
   )r   ).0attrr!   )r"   r   r
   r   
<dictcomp>,   s     z"Object.as_dict.<locals>.<dictcomp>)r   )r   r   r
   )r"   r   r   r   r   '   s    zObject.as_dictc                 C   s   t | j|  ffS r	   )r   	__class__r   r   r
   r
   r   
__reduce__0   s    zObject.__reduce__c                 C   s   | j f |  S r	   )r&   r   r'   r
   r
   r   __copy__3   s    zObject.__copy__N)F)	__name__
__module____qualname____doc__r   r   r   r(   r)   r
   r
   r
   r   r      s   
	r   c                   @   sn   e Zd ZdZdZdZdZdd Zdd Zdd	 Z	d
d Z
dd Zdd ZdddZedd Zedd ZdS )r   z7Mixin for classes that can be bound to an AMQP channel.NFc                 C   s
   |  |S )z&`self(channel) -> self.bind(channel)`.)bindr   channelr
   r
   r   __call__@   s    zMaybeChannelBound.__call__c                 C   s   t | |S )z7Create copy of the instance that is bound to a channel.)r   
maybe_bindr/   r
   r
   r   r.   D   s    zMaybeChannelBound.bindc                 C   s&   | j s"|r"t|| _|   d| _| S )z.Bind instance to channel if not already bound.T)is_boundr   _channel
when_bound	_is_boundr/   r
   r
   r   r2   H   s
    

zMaybeChannelBound.maybe_bindc                 C   s   | j r|| _|   dS )zyRevive channel after the connection has been re-established.

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

        N)r3   r4   r5   r/   r
   r
   r   reviveP   s    zMaybeChannelBound.revivec                 C   s   dS )z(Callback called when the class is bound.Nr
   r'   r
   r
   r   r5   Z   s    zMaybeChannelBound.when_boundc                 C   s   |  t| jS r	   )_repr_entityr!   r*   r'   r
   r
   r   __repr__]   s    zMaybeChannelBound.__repr__ 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!   r*   r3   formatr0   Z
channel_id)r   itemr
   r
   r   r8   `   s     zMaybeChannelBound._repr_entityc                 C   s   | j o| jdk	S )z!Flag set if the channel is bound.N)r6   r4   r'   r
   r
   r   r3   g   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)r4   r   r<   r!   r*   r   r   r/   r
   r
   r   r0   l   s    
zMaybeChannelBound.channel)r:   )r*   r+   r,   r-   r4   r6   Zcan_cache_declarationr1   r.   r2   r7   r5   r9   r8   propertyr3   r0   r
   r
   r
   r   r   7   s   


r   N)r-   r   
connectionr   
exceptionsr   Zutils.functionalr   __all__r   r   r   r   r
   r
   r
   r   <module>   s   #