
    vg!#                        d Z 	 ddlmZ ddlmZ  G d d          Z G d d          Z G d d	          Z G d
 d          Z G d d          Z	 G d d          Z
 G d d          Z G d d          Z G d d          Z G d d          Z	 ddlZn# e$ r dZY nw xY w G d d          Z G 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Zd ZdS )simple_producerzproducer for a string   c                 "    || _         || _        d S N)databuffer_sizeselfr
   r   s      X/var/www/pixelcanvas.ch/venv/lib/python3.11/site-packages/supervisor/medusa/producers.py__init__zsimple_producer.__init__   s    	&    c                     t          | j                  | j        k    r/| j        d | j                 }| j        | j        d          | _        |S | j        }d| _        |S Nr   )lenr
   r   r   results     r   morezsimple_producer.more   s\    	??T---Y0 001F	$"2"3"34DIMYFDIMr   Nr   __name__
__module____qualname____doc__r   r    r   r   r   r      s=        ' ' ' '    r   r   c                        e Zd ZdZddZd ZdS )scanning_producerz:like simple_producer, but more efficient for large stringsr   c                 0    || _         || _        d| _        d S Nr   )r
   r   posr   s      r   r   zscanning_producer.__init__#   s    	&r   c                    | j         t          | j                  k     rd| j         }t          t          | j                  | j         | j        z             }| j        ||         }| xj         t          |          z  c_         |S dS r   )r"   r   r
   minr   )r   lprpr   s       r   r   zscanning_producer.more(   sw    8c$)nn$$B	NNHt// B Yr"u%FHHF#HHM3r   Nr   r   r   r   r   r   r   !   s=        DD   
    r   r   c                       e Zd ZdZd Zd ZdS )lines_producerzproducer for a list of linesc                     || _         d S r	   )linesr   r*   s     r   r   zlines_producer.__init__8   s    


r   c                     | j         r;| j         d d         }| j         dd          | _         d                    |          dz   S dS )N2   
 )r*   join)r   chunks     r   r   zlines_producer.more;   sH    : 	JssOEBCCDJ;;u%%..2r   Nr   r   r   r   r(   r(   5   s8        &&      r   r(   c                       e Zd ZdZd Zd ZdS )buffer_list_producerzproducer for a list of stringsc                 "    d| _         || _        d S r!   )indexbuffers)r   r6   s     r   r   zbuffer_list_producer.__init__H   s    
r   c                     | j         t          | j                  k    rdS | j        | j                  }| xj         dz  c_         |S Nr      )r5   r   r6   r   r
   s     r   r   zbuffer_list_producer.moreL   s@    :T\****3<
+DJJ!OJJKr   Nr   r   r   r   r3   r3   C   s8        ((      r   r3   c                   "    e Zd ZdZdZd Zd ZdS )file_producerz(producer wrapper for file[-like] objects   c                 "    d| _         || _        d S r!   )donefile)r   r@   s     r   r   zfile_producer.__init__Z   s    				r   c                     | j         rdS | j                            | j                  }|s$| j                                         | `d| _         dS |S r8   )r?   r@   readout_buffer_sizecloser:   s     r   r   zfile_producer.more^   sW    9 
	39>>4#788D 	!!!I	sr   N)r   r   r   r   rC   r   r   r   r   r   r<   r<   T   s?        22 O      r   r<   c                   <    e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
d	S )
output_producerz;Acts like an output file; suitable for capturing sys.stdoutc                     d| _         d S r   r
   r   s    r   r   zoutput_producer.__init__t   s    			r   c                 z    |                     d          }d                    |          }| xj        |z  c_        d S )N
r.   )splitr0   r
   )r   r
   r*   s      r   writezoutput_producer.writew   s8    

4  {{5!!		T				r   c                 *    | j         |z   dz   | _         d S Nr.   rH   )r   lines     r   	writelinezoutput_producer.writeline|   s    I$v-			r   c                 P    | j         d                    |          z   dz   | _         d S rO   )r
   r0   r+   s     r   
writelineszoutput_producer.writelines   s%    IE 2 22V;			r   c                     d S r	   r   rI   s    r   flushzoutput_producer.flush       r   c                     d S r	   r   )r   argss     r   	softspacezoutput_producer.softspace   rV   r   c                 ^    | j         r%| j         d d         }| j         dd          | _         |S dS )Ni   r/   rH   r   s     r   r   zoutput_producer.more   s6    9 	Ytt_F	#$$DIM2r   N)r   r   r   r   r   rM   rQ   rS   rU   rY   r   r   r   r   rF   rF   r   s        EE    
. . .< < <        r   rF   c                       e Zd ZdZd Zd ZdS )composite_producerz$combine a fifo of producers into onec                     || _         d S r	   )	producers)r   r^   s     r   r   zcomposite_producer.__init__   s    "r   c                     t          | j                  rS| j        d         }|                                }|r|S | j                            d           t          | j                  SdS )Nr   r   )r   r^   r   pop)r   pds      r   r   zcomposite_producer.more   sk    $.!! 	q!AA &""1%%% $.!! 	 3r   Nr   r   r   r   r\   r\      s8        ..# # #	 	 	 	 	r   r\   c                        e Zd ZdZddZd ZdS )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]
    r=   c                 0    || _         d| _        || _        d S r   )producerbufferr   )r   rf   r   s      r   r   zglobbing_producer.__init__   s     &r   c                     t          | j                  | j        k     rI| j                                        }|r| j        |z   | _        nnt          | j                  | j        k     I| j        }d| _        |S r   )r   rg   r   rf   r   )r   r
   rs      r   r   zglobbing_producer.more   sw    $+!111=%%''D "kD0 $+!111 Kr   N)r=   r   r   r   r   rd   rd      sA         ' ' ' '
	 	 	 	 	r   rd   c                       e Zd ZdZd Zd ZdS )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                 0    || _         || _        d| _        d S r!   )rf   functionbytes)r   rf   rm   s      r   r   zhooked_producer.__init__   s      


r   c                     | j         r\| j                                         }|s"d | _         |                     | j                   n| xj        t	          |          z  c_        |S dS )Nr/   )rf   r   rm   rn   r   r   s     r   r   zhooked_producer.more   se    = 		]''))F * $tz****

c&kk)

M2r   Nr   r   r   r   rk   rk      s<           

 
 
 
 
r   rk   c                        e Zd ZdZddZ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                 "    || _         || _        d S r	   )rf   footers)r   rf   rs   s      r   r   zchunked_producer.__init__   s     r   c                     | j         rv| j                                         }|r*dt          |          z  }t          |          dz   |z   dz   S d | _         | j        r!d                    dg| j        z             dz   S dS dS )Nz%xs   
   0s   

s   0

r   )rf   r   r   r   rs   r0   )r   r
   ss      r   r   zchunked_producer.more   s    = 	=%%''D (3t99${{W,t3g== $< ("<<(=>>LL'<3r   r	   r   r   r   r   rq   rq      sA                r   rq   Nc                        e Zd ZdZddZd ZdS )compressed_producerz:
    Compress another producer on-the-fly, using ZLIB
       c                 F    || _         t          j        |          | _        d S r	   )rf   zlibcompressobj
compressor)r   rf   levels      r   r   zcompressed_producer.__init__  s     *E22r   c                     | j         r]d}|sW| j                                         }|s d | _         | j                                        S | j                            |          }|W|S dS r   )rf   r   r}   rU   compress)r   cdatar
   s      r   r   zcompressed_producer.more  sz    = 	E <}))++ <$(DM?00222 O44d;;E  < L3r   N)ry   r   r   r   r   rx   rx      sA         3 3 3 3    r   rx   c                        e Zd ZdZddZd ZdS )escaping_producerz0A producer that escapes a sequence of characters
.
..c                 V    || _         || _        || _        d| _        t          | _        d S r   )rf   esc_fromesc_torg   r   )r   rf   r   r   s       r   r   zescaping_producer.__init__   s,      "4r   c                    | j         }| j        }| j        | j                                        z   }|rR|                    ||          }|                     ||          }|r|| d          | _        |d |          S d| _        |S |S r   )r   r   rg   rf   r   replacer   )r   r   r   rg   is        r   r   zescaping_producer.more'  s    =;t}11333 	^^Hf55F''::A $aRSSkcrc{" "Mr   N)r   r   r   r   r   r   r   r     s=        ::5 5 5 5    r   r   )RCS_IDsupervisor.medusa.asynchat_25r   supervisor.compatr   r   r   r(   r3   r<   rF   r\   rd   rk   rq   r{   ImportErrorrx   r   r   r   r   <module>r      sX   
G = < < < < < & & & & & &               (              "       <       <       "       0       @       :KKKK   DDD       @         s   B B"!B"