
    Ac!#                     6   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 G d d      Z G d d      Zy# e$ r dZY w xY w)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y)simple_producerzproducer for a stringc                      || _         || _        y N)databuffer_sizeselfr	   r
   s      =/usr/lib/python3/dist-packages/supervisor/medusa/producers.py__init__zsimple_producer.__init__   s    	&    c                     t        | j                        | j                  kD  r9| j                  d | j                   }| j                  | j                  d  | _        |S | j                  }d| _        |S Nr   )lenr	   r
   r   results     r   morezsimple_producer.more   sb    		?T---YY0 0 01F		$"2"2"34DIMYYFDIMr   Ni   __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y)scanning_producerz:like simple_producer, but more efficient for large stringsc                 .    || _         || _        d| _        y Nr   )r	   r
   posr   s      r   r   zscanning_producer.__init__#   s    	&r   c                 *   | j                   t        | j                        k  rq| j                   }t        t        | j                        | j                   | j                  z         }| j                  || }| xj                   t        |      z  c_         |S yr   )r!   r   r	   minr
   )r   lprpr   s       r   r   zscanning_producer.more(   sr    88c$))n$B		NHHt///B YYr"%FHHF#HMr   Nr   r   r   r   r   r   r   !   s    D
r   r   c                       e Zd ZdZd Zd Zy)lines_producerzproducer for a list of linesc                     || _         y r   )linesr   r)   s     r   r   zlines_producer.__init__8   s	    
r   c                     | j                   r7| j                   d d }| j                   dd  | _         dj                  |      dz   S y)N2   
 )r)   join)r   chunks     r   r   zlines_producer.more;   s@    ::JJsOEBCDJ;;u%..r   Nr   r   r   r   r'   r'   5   s    &r   r'   c                       e Zd ZdZd Zd Zy)buffer_list_producerzproducer for a list of stringsc                      d| _         || _        y r    )indexbuffers)r   r5   s     r   r   zbuffer_list_producer.__init__H   s    
r   c                     | j                   t        | j                        k\  ry| j                  | j                      }| xj                   dz  c_         |S Nr      )r4   r   r5   r   r	   s     r   r   zbuffer_list_producer.moreL   s>    ::T\\**<<

+DJJ!OJKr   Nr   r   r   r   r2   r2   C   s    (r   r2   c                        e Zd ZdZdZd Zd Zy)file_producerz(producer wrapper for file[-like] objects   c                      d| _         || _        y r    )donefile)r   r?   s     r   r   zfile_producer.__init__Z   s    		r   c                     | j                   ry| j                  j                  | j                        }|s$| j                  j	                          | `d| _         y|S r7   )r>   r?   readout_buffer_sizecloser9   s     r   r   zfile_producer.more^   sI    9999>>4#7#78D		!I	r   N)r   r   r   r   rB   r   r   r   r   r   r;   r;   T   s    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
y	)
output_producerz;Acts like an output file; suitable for capturing sys.stdoutc                     d| _         y r   r	   r   s    r   r   zoutput_producer.__init__t   s	    	r   c                 r    |j                  d      }dj                  |      }| xj                  |z  c_        y )N
r-   )splitr/   r	   )r   r	   r)   s      r   writezoutput_producer.writew   s,    

4 {{5!		T	r   c                 2    | j                   |z   dz   | _         y Nr-   rG   )r   lines     r   	writelinezoutput_producer.writeline|   s    II$v-	r   c                 P    | j                   dj                  |      z   dz   | _         y rN   )r	   r/   r*   s     r   
writelineszoutput_producer.writelines   s     IIE 22V;	r   c                      y r   r   rH   s    r   flushzoutput_producer.flush       r   c                      y r   r   )r   argss     r   	softspacezoutput_producer.softspace   rU   r   c                 f    | j                   r%| j                   d d }| j                   dd  | _         |S y)Ni   r.   rG   r   s     r   r   zoutput_producer.more   s1    99YYt_F		#$DIMr   N)r   r   r   r   r   rL   rP   rR   rT   rX   r   r   r   r   rE   rE   r   s(    E
.<r   rE   c                       e Zd ZdZd Zd Zy)composite_producerz$combine a fifo of producers into onec                     || _         y r   )	producers)r   r]   s     r   r   zcomposite_producer.__init__   s	    "r   c                     t        | j                        rT| j                  d   }|j                         }|r|S | j                  j                  d       t        | j                        rTy)Nr   r   )r   r]   r   pop)r   pds      r   r   zcomposite_producer.more   sT    $..!q!AA""1% $..! r   Nr   r   r   r   r[   r[      s    .#	r   r[   c                       e Zd ZdZddZd Zy)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]
    c                 .    || _         d| _        || _        y r   )producerbufferr
   )r   re   r
   s      r   r   zglobbing_producer.__init__   s     &r   c                    t        | j                        | j                  k  rU| j                  j	                         }|r| j                  |z   | _        nn#t        | j                        | j                  k  rU| j                  }d| _        |S r   )r   rf   r
   re   r   )r   r	   rs      r   r   zglobbing_producer.more   sq    $++!1!11==%%'D"kkD0 $++!1!11 KKr   N)r<   r   r   r   r   rc   rc      s    '
	r   rc   c                       e Zd ZdZd Zd Zy)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                 .    || _         || _        d| _        y r    )re   functionbytes)r   re   rl   s      r   r   zhooked_producer.__init__   s      
r   c                     | j                   r`| j                   j                         }|s$d | _         | j                  | j                         |S | xj                  t	        |      z  c_        |S y)Nr.   )re   r   rl   rm   r   r   s     r   r   zhooked_producer.more   sX    ==]]'')F $tzz* M 

c&k)
Mr   Nr   r   r   r   rj   rj      s    

r   rj   c                       e Zd ZdZddZd Zy)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                      || _         || _        y r   )re   footers)r   re   rr   s      r   r   zchunked_producer.__init__   s     r   c                    | j                   rt| j                   j                         }|r"dt        |      z  }t        |      dz   |z   dz   S d | _         | j                  r"dj                  dg| j                  z         dz   S yy)Nz%xs   
   0s   

s   0

r   )re   r   r   r   rr   r/   )r   r	   ss      r   r   zchunked_producer.more   sx    ====%%'D3t9${W,t3g== $<<"<<(=>LL'r   r   r   r   r   r   rp   rp      s    r   rp   Nc                       e Zd ZdZddZd Zy)compressed_producerz:
    Compress another producer on-the-fly, using ZLIB
    c                 F    || _         t        j                  |      | _        y r   )re   zlibcompressobj
compressor)r   re   levels      r   r   zcompressed_producer.__init__  s     **E2r   c                     | j                   rad}|s[| j                   j                         }|s!d | _         | j                  j                         S | j                  j	                  |      }|s[|S yr   )re   r   r{   rT   compress)r   cdatar	   s      r   r   zcompressed_producer.more  sc    ==E}}))+$(DM??0022 OO44d;E  Lr   N)   r   r   r   r   rw   rw      s    3r   rw   c                       e Zd ZdZddZd Zy)escaping_producerz0A producer that escapes a sequence of charactersc                 R    || _         || _        || _        d| _        t        | _        y r   )re   esc_fromesc_torf   r   )r   re   r   r   s       r   r   zescaping_producer.__init__   s&      "4r   c                    | j                   }| j                  }| j                  | j                  j	                         z   }|r@|j                  ||      }| j                  ||      }|r|| d  | _        |d |  S d| _        |S |S r   )r   r   rf   re   r   replacer   )r   r   r   rf   is        r   r   zescaping_producer.more'  s    ==;;t}}1133^^Hf5F'':A$aRSkcr{" "Mr   N)z
.z
..r   r   r   r   r   r     s    :5r   r   )RCS_IDsupervisor.medusa.asynchat_25r   supervisor.compatr   r   r   r'   r2   r;   rE   r[   rc   rj   rp   ry   ImportErrorrw   r   r   r   r   <module>r      s    
G = &   (  " < < " 0 @ : @ G  Ds   5B BB