o
    r¨Êh!#  ã                   @   sî   d Z 	 ddlmZ ddlmZ G dd„ dƒZG dd„ dƒZG dd	„ d	ƒZG d
d„ dƒZG dd„ dƒZ	G dd„ dƒZ
G dd„ dƒZG dd„ dƒZG dd„ dƒZG dd„ dƒZzddlZW n eyf   dZY nw G dd„ dƒZG dd„ dƒZdS )z;$Id: producers.py,v 1.9 2004/04/21 13:56:28 akuchling Exp $é    )Úfind_prefix_at_end)Úas_bytesc                   @   ó"   e Zd ZdZddd„Zdd„ ZdS )	Úsimple_producerzproducer for a stringé   c                 C   ó   || _ || _d S ©N)ÚdataÚbuffer_size©Úselfr	   r
   © r   úM/var/www/html/env/lib/python3.10/site-packages/supervisor/medusa/producers.pyÚ__init__   ó   
zsimple_producer.__init__c                 C   sF   t | jƒ| jkr| jd | j… }| j| jd … | _|S | j}d| _|S ©Nó    )Úlenr	   r
   ©r   Úresultr   r   r   Úmore   s   zsimple_producer.moreN©r   ©Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r   r   r      s    
r   c                   @   r   )	Úscanning_producerz:like simple_producer, but more efficient for large stringsr   c                 C   ó   || _ || _d| _d S ©Nr   )r	   r
   Úposr   r   r   r   r   #   ó   
zscanning_producer.__init__c                 C   sV   | j t| jƒk r)| j }tt| jƒ| j | j ƒ}| j||… }|  j t|ƒ7  _ |S dS r   )r    r   r	   Úminr
   )r   ÚlpÚrpr   r   r   r   r   (   s   
þzscanning_producer.moreNr   r   r   r   r   r   r   !   s    
r   c                   @   ó    e Zd ZdZdd„ Zdd„ ZdS )Úlines_producerzproducer for a list of linesc                 C   ó
   || _ d S r   )Úlines©r   r(   r   r   r   r   8   ó   
zlines_producer.__init__c                 C   s6   | j r| j d d… }| j dd … | _ d |¡d S dS )Né2   ú
Ú )r(   Újoin)r   Úchunkr   r   r   r   ;   s
   zlines_producer.moreNr   r   r   r   r   r&   5   s    r&   c                   @   r%   )Úbuffer_list_producerzproducer for a list of stringsc                 C   ó   d| _ || _d S r   )ÚindexÚbuffers)r   r3   r   r   r   r   H   r   zbuffer_list_producer.__init__c                 C   s2   | j t| jƒkr
dS | j| j  }|  j d7  _ |S ©Nr   é   )r2   r   r3   ©r   r	   r   r   r   r   L   s
   zbuffer_list_producer.moreNr   r   r   r   r   r0   C   s    r0   c                   @   s$   e Zd ZdZdZdd„ Zdd„ ZdS )Úfile_producerz(producer wrapper for file[-like] objectsé   c                 C   r1   r   )ÚdoneÚfile)r   r:   r   r   r   r   Z   r   zfile_producer.__init__c                 C   s8   | j rdS | j | j¡}|s| j ¡  | `d| _ dS |S r4   )r9   r:   ÚreadÚout_buffer_sizeÚcloser6   r   r   r   r   ^   s   
zfile_producer.moreN)r   r   r   r   r<   r   r   r   r   r   r   r7   T   s
    r7   c                   @   sH   e 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„ Z
dS )Úoutput_producerz;Acts like an output file; suitable for capturing sys.stdoutc                 C   s
   d| _ d S r   ©r	   ©r   r   r   r   r   t   r*   zoutput_producer.__init__c                 C   s&   |  d¡}d |¡}|  j|7  _d S )NÚ
r,   )Úsplitr.   r	   )r   r	   r(   r   r   r   Úwritew   s   

zoutput_producer.writec                 C   s   | j | d | _ d S ©Nr,   r?   )r   Úliner   r   r   Ú	writeline|   s   zoutput_producer.writelinec                 C   s   | j d |¡ d | _ d S rD   )r	   r.   r)   r   r   r   Ú
writelines   s   zoutput_producer.writelinesc                 C   ó   d S r   r   r@   r   r   r   Úflush‚   ó   zoutput_producer.flushc                 G   rH   r   r   )r   Úargsr   r   r   Ú	softspace…   rJ   zoutput_producer.softspacec                 C   s,   | j r| j d d… }| j dd … | _ |S dS )Ni   r-   r?   r   r   r   r   r   ˆ   s
   zoutput_producer.moreN)r   r   r   r   r   rC   rF   rG   rI   rL   r   r   r   r   r   r>   r   s    r>   c                   @   r%   )Úcomposite_producerz$combine a fifo of producers into onec                 C   r'   r   )Ú	producers)r   rN   r   r   r   r   ’   r*   zcomposite_producer.__init__c                 C   s>   t | jƒr| jd }| ¡ }|r|S | j d¡ t | jƒsdS )Nr   r   )r   rN   r   Úpop)r   ÚpÚdr   r   r   r   •   s   


úzcomposite_producer.moreNr   r   r   r   r   rM   �   s    rM   c                   @   r   )	Úglobbing_producerzÌ
    'glob' the output from a producer into a particular buffer size.
    helps reduce the number of calls to send().  [this appears to
    gain about 30% performance on requests to a single channel]
    r8   c                 C   s   || _ d| _|| _d S r   )ÚproducerÚbufferr
   )r   rS   r
   r   r   r   r   ¨   r!   zglobbing_producer.__init__c                 C   sN   t | jƒ| jk r| j ¡ }|r| j| | _nnt | jƒ| jk s| j}d| _|S r   )r   rT   r
   rS   r   )r   r	   Úrr   r   r   r   ­   s   
ûzglobbing_producer.moreN)r8   r   r   r   r   r   rR   ¡   s    
rR   c                   @   r%   )Úhooked_producerz¨
    A producer that will call <function> when it empties,.
    with an argument of the number of bytes produced.  Useful
    for logging/instrumentation purposes.
    c                 C   r   r   )rS   ÚfunctionÚbytes)r   rS   rW   r   r   r   r   À   r!   zhooked_producer.__init__c                 C   sD   | j r | j  ¡ }|sd | _ |  | j¡ |S |  jt|ƒ7  _|S dS )Nr-   )rS   r   rW   rX   r   r   r   r   r   r   Å   s   
ÿzhooked_producer.moreNr   r   r   r   r   rV   ¹   s    rV   c                   @   s"   e Zd ZdZddd„Zdd„ ZdS )Úchunked_producera'  A producer that implements the 'chunked' transfer coding for HTTP/1.1.
    Here is a sample usage:
            request['Transfer-Encoding'] = 'chunked'
            request.push (
                    producers.chunked_producer (your_producer)
                    )
            request.done()
    Nc                 C   r   r   )rS   Úfooters)r   rS   rZ   r   r   r   r   ã   r   zchunked_producer.__init__c                 C   s^   | j r-| j  ¡ }|rdt|ƒ }t|ƒd | d S d | _ | jr+d dg| j ¡d S dS dS )Nz%xs   
ó   0s   

s   0

r   )rS   r   r   r   rZ   r.   )r   r	   Úsr   r   r   r   ç   s   
zchunked_producer.morer   r   r   r   r   r   rY   Ù   s    
	rY   Nc                   @   r   )	Úcompressed_producerz:
    Compress another producer on-the-fly, using ZLIB
    é   c                 C   s   || _ t |¡| _d S r   )rS   ÚzlibÚcompressobjÚ
compressor)r   rS   Úlevelr   r   r   r     s   zcompressed_producer.__init__c                 C   sD   | j r d}|s| j  ¡ }|sd | _ | j ¡ S | j |¡}|r|S dS r   )rS   r   ra   rI   Úcompress)r   Úcdatar	   r   r   r   r     s   

úzcompressed_producer.moreN)r^   r   r   r   r   r   r]   û   s    
r]   c                   @   s"   e Zd ZdZd	dd„Zdd„ ZdS )
Úescaping_producerz0A producer that escapes a sequence of charactersú
.ú
..c                 C   s"   || _ || _|| _d| _t| _d S r   )rS   Úesc_fromÚesc_torT   r   )r   rS   rh   ri   r   r   r   r      s
   
zescaping_producer.__init__c                 C   sh   | j }| j}| j| j ¡  }|r2| ||¡}|  ||¡}|r-|| d … | _|d | … S d| _|S |S r   )rh   ri   rT   rS   r   Úreplacer   )r   rh   ri   rT   Úir   r   r   r   '  s   zescaping_producer.moreN)rf   rg   r   r   r   r   r   re     s    
re   )ÚRCS_IDÚsupervisor.medusa.asynchat_25r   Úsupervisor.compatr   r   r   r&   r0   r7   r>   rM   rR   rV   rY   r_   ÚImportErrorr]   re   r   r   r   r   Ú<module>   s*   	 ÿ 