o
    j                     @   sZ   d dl Z d dlZd dlZd dlmZ d dlmZmZ dZG dd dZ	G dd de	Z
dS )	    N)Request)SocketUnreaderIterUnreaderi   c                   @   s6   e Zd ZdZdd Zdd Zd
ddZdd	 ZeZdS )ParserNc                 C   s<   || _ t|drt|| _nt|| _d | _|| _d| _d S )Nrecvr   )cfghasattrr   unreaderr   mesgsource_addr	req_count)selfr   sourcer    r   I/var/www/ai-app/venv/lib/python3.10/site-packages/gunicorn/http/parser.py__init__   s   


zParser.__init__c                 C   s   | S )Nr   r   r   r   r   __iter__#   s   zParser.__iter__c           	      C   s$  | j sdS |du r|durt}t| jdd}|dur+t|dr+t|dr+|}| }nd}d}d}z	 |durd|durd|t  }|dkr_W |dur]z|| W dS  t	y\   Y dS w dS || z	| j j
d}W nG tjtfy   Y W |durz|| W dS  t	y   Y dS w dS  tjy   Y W |durz|| W dS  t	y   Y dS w dS w |sW |durz|| W dS  t	y   Y dS w dS |t|7 }|dur||krW |durz|| W dS  t	y   Y dS w dS q3|durz|| W w  t	y   Y w w w )	a<  Discard any unread body of the current message.

        Called before returning a keepalive connection to the poller so the
        socket does not appear readable due to leftover body bytes.

        ``deadline`` is an absolute ``time.monotonic()`` value; when set the
        socket read timeout is bounded by the remaining time before each read.
        ``max_bytes`` caps the total drained bytes; when a deadline is given
        and ``max_bytes`` is left at the default, ``_DRAIN_MAX_BYTES`` applies
        to defend against a slow client that keeps trickling under it.  When
        called without a deadline (the default invocation from ``__next__``),
        no byte cap is applied so the prior unbounded drain semantics are
        preserved for callers that don't know how to react to a partial drain.

        Returns ``True`` when the body was fully drained, ``False`` when the
        drain was abandoned (deadline, byte cap, or socket timeout).  Callers
        that observe ``False`` MUST close the connection rather than serve
        another request on it.
        TNsock
gettimeout
settimeoutr   Fi   )r
   _DRAIN_MAX_BYTESgetattrr	   r   r   time	monotonicr   OSErrorbodyreadsockettimeoutTimeoutErrorsslSSLWantReadErrorlen)	r   deadline	max_bytesr   timeoutable_sockprior_timeoutdrained	remainingdatar   r   r   finish_body&   s   



zParser.finish_bodyc                 C   sX   | j r| j  rt |   |  jd7  _| | j| j| j| j| _ | j s)t | j S )N   )	r
   should_closeStopIterationr+   r   
mesg_classr   r	   r   r   r   r   r   __next__e   s   zParser.__next__)NN)	__name__
__module____qualname__r/   r   r   r+   r0   nextr   r   r   r   r      s    
?r   c                   @   s   e Zd ZeZdS )RequestParserN)r1   r2   r3   r   r/   r   r   r   r   r5   w   s    r5   )r   r!   r   gunicorn.http.messager   gunicorn.http.unreaderr   r   r   r   r5   r   r   r   r   <module>   s   d