Mini Shell
3
@��e�
� @ s, d dl Z d dlmZmZ G dd� de�ZdS )� N)�
lowerASCII�
upperASCIIc @ s( e Zd ZdZdd� Zdd� Zdd� ZdS ) �QueueFactorya� Constructs a new object wrapping a Queue.Queue, complete with constants
and sending functions for each type of message that can be put into the
queue.
Creating a new object using this class is done like so:
q = QueueFactory("progress")
And then adding messages to it is done like so:
q.addMessage("init", 0)
q.addMessage("step", 1)
The first call will create a new constant named PROGRESS_CODE_INIT and a
method named send_init that takes zero arguments. The second call will
create a new constant named PROGRESS_CODE_STEP and a method named send_step
that takes one argument.
Reusing names within the same class is not allowed.
c C s || _ d| _g | _tj� | _d S )Nr )�name�_QueueFactory__counter�_QueueFactory__names�queueZQueue�q)�selfr � r �$/usr/lib64/python3.6/queuefactory.py�__init__, s zQueueFactory.__init__c s � ���fdd�}�|_ |S )Nc s6 t | �� kr"td�� t | �f ���jj�| f� d S )Nz*%s() takes exactly %d arguments (%d given))�len� TypeErrorr Zput)�args)�argc�constant�
methodNamer
r r Z__method5 s z*QueueFactory._makeMethod.<locals>.__method)�__name__)r
r r r Z_QueueFactory__methodr )r r r r
r �_makeMethod4 s zQueueFactory._makeMethodc C s� || j krtd| j|f ��t| j�d t|� }t| || j� | jd7 _dt|� }| jt| |�||�}t| ||� | j j |� d S )Nz'%s queue already has a message named %sZ_CODE_� Zsend_)
r �AttributeErrorr r �setattrr r r �getattr�append)r
r r Z
const_nameZmethod_name�methodr r r �
addMessage? s
zQueueFactory.addMessageN)r �
__module__�__qualname__�__doc__r
r r r r r r r s r )r Zpyanaconda.core.utilr r �objectr r r r r �<module> s