
    af&                     X   d Z ddlZddlZddlZddlZddlmZ ddlmZ ddl	m
Z
 ddlmZ ddlmZ ddlmZ dd	lmZ d
Z ej        d          Zd Zd Z G d dej                  Z G d dej        e          Z G d dej                  Z G d dej                  ZdddefdZdS )a0  
HTTP server that implements the Python WSGI protocol (PEP 333, rev 1.21).

Based on wsgiref.simple_server which is part of the standard library since 2.5.

This is a simple server for use in testing or debugging Django apps. It hasn't
been reviewed for security issues. DON'T USE IT FOR PRODUCTION USE!
    N)deque)simple_server)ImproperlyConfigured)LimitedStream)get_wsgi_application)connections)import_string)
WSGIServerWSGIRequestHandlerzdjango.serverc                      ddl m}  t          | d          }|t                      S 	 t	          |          S # t
          $ r}t          d|z            |d}~ww xY w)aK  
    Load and return the WSGI application as configured by the user in
    ``settings.WSGI_APPLICATION``. With the default ``startproject`` layout,
    this will be the ``application`` object in ``projectname/wsgi.py``.

    This function, and the ``WSGI_APPLICATION`` setting itself, are only useful
    for Django's internal server (runserver); external WSGI servers should just
    be configured to point to the correct application object directly.

    If settings.WSGI_APPLICATION is not set (is ``None``), return
    whatever ``django.core.wsgi.get_wsgi_application`` returns.
    r   )settingsWSGI_APPLICATIONNzBWSGI application '%s' could not be loaded; Error importing module.)django.confr   getattrr   r	   ImportErrorr   )r   app_patherrs      N/var/www/html/env/lib/python3.11/site-packages/django/core/servers/basehttp.pyget_internal_wsgi_applicationr      s     %$$$$$x!344H#%%%X&&&   "&(01
 
 	s   7 
AAAc                  t    t          j                    \  } }}t          | t          t          t
          f          S N)sysexc_info
issubclassBrokenPipeErrorConnectionAbortedErrorConnectionResetError)exc_type_s     r   is_broken_pipe_errorr    8   s6    \^^NHa" 	
      c                   8     e Zd ZdZdZddd fd
Z fdZ xZS )r
   z7BaseHTTPServer that implements the Python WSGI protocol
   FT)ipv6allow_reuse_addressc                n    |rt           j        | _        || _         t	                      j        |i | d S r   )socketAF_INET6address_familyr%   super__init__)selfr$   r%   argskwargs	__class__s        r   r+   zWSGIServer.__init__I   s?     	2"(/D#6 $)&)))))r!   c                     t                      rt                              d|           d S t                                          ||           d S )Nz- Broken pipe from %s)r    loggerinfor*   handle_error)r,   requestclient_addressr/   s      r   r3   zWSGIServer.handle_errorO   sL    !! 	:KK/@@@@@GG  .99999r!   )__name__
__module____qualname____doc__request_queue_sizer+   r3   __classcell__r/   s   @r   r
   r
   D   sl        AA#(d * * * * * * *: : : : : : : : :r!   r
   c                   F     e Zd ZdZdZdd fd
Z fdZd Z fdZ xZ	S )	ThreadedWSGIServerz$A threaded version of the WSGIServerTN)connections_overridec                H     t                      j        |i | || _        d S r   )r*   r+   r?   )r,   r?   r-   r.   r/   s       r   r+   zThreadedWSGIServer.__init__[   s-    $)&)))$8!!!r!   c                     | j         r)| j                                         D ]\  }}|t          |<   t                                          ||           d S r   )r?   itemsr   r*   process_request_thread)r,   r4   r5   aliasconnr/   s        r   rC   z)ThreadedWSGIServer.process_request_threada   s_    $ 	*  $8>>@@ * *t%)E""&&w?????r!   c                 ,    t          j                     d S r   )r   	close_allr,   s    r   _close_connectionsz%ThreadedWSGIServer._close_connectionsi   s    r!   c                 r    |                                   t                                          |           d S r   )rI   r*   close_request)r,   r4   r/   s     r   rK   z ThreadedWSGIServer.close_requestm   s3    !!!g&&&&&r!   )
r6   r7   r8   r9   daemon_threadsr+   rC   rI   rK   r;   r<   s   @r   r>   r>   V   s        ..N37 9 9 9 9 9 9 9@ @ @ @ @     ' ' ' ' ' ' ' ' 'r!   r>   c                   @     e Zd ZdZ fdZ fdZ fdZ fdZ xZS )ServerHandlerz1.1c                     	 t          |                    d                    }n# t          t          f$ r d}Y nw xY w t	                      j        t          ||          |||fi | dS )a#  
        Use a LimitedStream so that unread request data will be ignored at
        the end of the request. WSGIRequest uses a LimitedStream but it
        shouldn't discard the data since the upstream servers usually do this.
        This fix applies only for testserver/runserver.
        CONTENT_LENGTHr   N)intget
ValueError	TypeErrorr*   r+   r   )r,   stdinstdoutstderrenvironr.   content_lengthr/   s          r   r+   zServerHandler.__init__u   s    	 -=!>!>??NNI& 	 	 	NNN	%00&&'	
 	
MS	
 	
 	
 	
 	
s   "& <<c                    t                                                       | j        d         dk    rd| j        v r| j        d= | j        d         dk    rd| j        vrd| j        d<   n.t	          | j        j        t          j                  s
d| j        d<   | j        	                    d          dk    rd| j        _
        d S d S )NREQUEST_METHODHEADzContent-Lengthclose
ConnectionT)r*   cleanup_headersrX   headers
isinstancerequest_handlerserversocketserverThreadingMixInrR   close_connectionr,   r/   s    r   r_   zServerHandler.cleanup_headers   s    !!!L)*f44 DL00-.
 L)*f44 44)0DL&&D079TUU 	1)0DL& <L))W4448D 111 54r!   c                     |                                                                   t                                                       d S r   )	get_stdinreadr*   r]   rg   s    r   r]   zServerHandler.close   s4    r!   c                 ,   | j         d         dk    ra	 t          | j        d           | j        s|                                  |                                  d S # |                                  w xY wt                                                       d S )Nr[   r\   r   )maxlen)rX   r   resultheaders_sentsend_headersr]   r*   finish_responserg   s    r   rp   zServerHandler.finish_response   s    <()V33
dk!,,,, ( (%%'''



GG##%%%%%s   1A A1)	r6   r7   r8   http_versionr+   r_   r]   rp   r;   r<   s   @r   rN   rN   r   s        L
 
 
 
 
9 9 9 9 9.    & & & & & & & & &r!   rN   c                   :     e Zd ZdZd Zd Z fdZd Zd Z xZ	S )r   zHTTP/1.1c                     | j         d         S )Nr   )r5   rH   s    r   address_stringz!WSGIRequestHandler.address_string   s    "1%%r!   c                    | j         |                                 d}|d         d         dk    r>|d                             d          r#d|d<   t                              d|	           d S |d                                         rft          |d                   d
k    rMt          |d                   }||d<   |dk    rt          j        }n,|dk    rt          j        }nt          j	        }nt          j	        } ||g|R d|i d S )N)r4   server_time   r   4zi  status_codezNYou're accessing the development server over HTTPS, but it only supports HTTP.)extra   i  rz   )
r4   log_date_time_string
startswithr1   errorisdigitlenrQ   warningr2   )r,   formatr-   rz   ry   levels         r   log_messagezWSGIRequestHandler.log_message   s&   |4466
 
 71:Aw!!*-- '*m$-    
 7?? 	 T!W!2!2d1g,,K#.E- c!!##KEf)t)))5)))))r!   c                 p    | j         D ]}d|v r| j         |= t                                                      S )Nr   )r`   r*   get_environ)r,   kr/   s     r   r   zWSGIRequestHandler.get_environ   s?    
  	$ 	$AaxxLOww""$$$r!   c                     d| _         |                                  | j         s|                                  | j         	 | j                            t          j                   d S # t          t          f$ r Y d S w xY w)NT)rf   handle_one_request
connectionshutdownr'   SHUT_WRAttributeErrorOSErrorrH   s    r   handlezWSGIRequestHandler.handle   s     $!!!' 	&##%%% ' 	&	O$$V^44444( 	 	 	DD	s   $A% %A:9A:c                    | j                             d          | _        t          | j                  dk    r,d| _        d| _        d| _        |                     d           dS |                                 sdS t          | j         | j
        |                                 |                                           }| |_        |                    | j                                                   dS )zDCopy of WSGIRequestHandler.handle() but with different ServerHandleri  i    i  N)rfilereadlineraw_requestliner   requestlinerequest_versioncommand
send_errorparse_requestrN   wfile
get_stderrr   rb   runrc   get_app)r,   handlers     r   r   z%WSGIRequestHandler.handle_one_request   s    #z22599t#$$u,,!D#%D DLOOC   F!!## 	FJ
DOO$5$5t7G7G7I7I
 
 #'DK''))*****r!   )
r6   r7   r8   protocol_versionrt   r   r   r   r   r;   r<   s   @r   r   r      sz        !& & &* * *>	% 	% 	% 	% 	%  + + + + + + +r!   r   Fc                    | |f}|rt          dt          j        |fi           }n|} ||t          |          }	| |t	          |	d|                     |rd|	_        |	                    |           |	                                 d S )Nr
   )r$   server_portT)typerd   re   r   r   rL   set_appserve_forever)
addrportwsgi_handlerr$   	threadingon_bind
server_clsserver_address	httpd_clshttpds
             r   r   r      s     D\N (CZ'PRTUU			In&8tDDDE}d33444 $  $	MM,	r!   )r9   loggingr'   rd   r   collectionsr   wsgirefr   django.core.exceptionsr   django.core.handlers.wsgir   django.core.wsgir   	django.dbr   django.utils.module_loadingr	   __all__	getLoggerr1   r   r    r
   re   r>   rN   r   r    r!   r   <module>r      s          



       ! ! ! ! ! ! 7 7 7 7 7 7 3 3 3 3 3 3 1 1 1 1 1 1 ! ! ! ! ! ! 5 5 5 5 5 5
.		?	+	+  8	 	 	: : : : :) : : :$' ' ' ' '4j ' ' '8;& ;& ;& ;& ;&M/ ;& ;& ;&|L+ L+ L+ L+ L+9 L+ L+ L+f 
     r!   