U
    lufk                     @   sX   d Z ddlmZmZ ddlmZmZmZ ddlm	Z	 ddlm
Z G dd dZdgZd	S )
zzmq Context class    )EINVAL
IO_THREADS)InterruptedSystemCallZMQError	_check_rc   )ffi)libc                   @   sV   e Zd ZdZdZdZdZdddZedd Z	ed	d
 Z
dd Zdd Zdd ZdS )ContextNTFr   c                 C   sp   |rt d|| _d| _n d| _|dks0ttt | _| jt jkrRtt	 |sft
| jt| d| _d S )Nzvoid *TFr   )r   cast_zmq_ctx_shadowr   r   CZzmq_ctx_newZNULLZ	zmq_errnozmq_ctx_setr   _closed)selfZ
io_threadsZshadow r   </tmp/pip-unpacked-wheel-h6ekxre8/zmq/backend/cffi/context.py__init__   s    
zContext.__init__c                 C   s   t td| jS )z,The address of the underlying libzmq contextZsize_t)intr   r   r   r   r   r   r   
underlying#   s    zContext.underlyingc                 C   s   | j S )N)r   r   r   r   r   closed(   s    zContext.closedc                 C   s   t | j||}t| dS )z6set a context option

        see zmq_ctx_set
        N)r   r   r   r   )r   optionvaluercr   r   r   set,   s    zContext.setc                 C   s   t | j|}t|dd |S )z4get context option

        see zmq_ctx_get
        F)Zerror_without_errno)r   Zzmq_ctx_getr   r   )r   r   r   r   r   r   get4   s    zContext.getc                 C   sH   | j r
d S t| j}zt| W n tk
r6   Y nX d | _d| _d S )NT)r   r   Zzmq_ctx_destroyr   r   r   r   )r   r   r   r   r   term=   s    zContext.term)r   N)__name__
__module____qualname__r   Z
_iothreadsr   r   r   propertyr   r   r   r   r   r   r   r   r   r
      s   


	r
   N)__doc__Zzmq.constantsr   r   Z	zmq.errorr   r   r   Z_cffir   r	   r   r
   __all__r   r   r   r   <module>   s   @