
    g'                     j   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j0                        Z G d dej2                  e      Z G d dej6                        Z G d dej8                        ZdddefdZy)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      t/var/www/python.vincentserveurtest.ovh/public_html/venv/lib/python3.12/site-packages/django/core/servers/basehttp.pyget_internal_wsgi_applicationr      sb     %x!34H#%%X&& "&(01
 	s   
+ 	AAAc                  h    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   s1    \\^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                `    |rt         j                  | _        || _        t	        |   |i | y r   )socketAF_INET6address_familyr%   super__init__)selfr$   r%   argskwargs	__class__s        r   r+   zWSGIServer.__init__I   s,    "(//D#6 $)&)r!   c                 h    t               rt        j                  d|       y t        |   ||       y )Nz- Broken pipe from %s)r    loggerinfor*   handle_error)r,   requestclient_addressr/   s      r   r3   zWSGIServer.handle_errorO   s'    !KK/@G .9r!   )__name__
__module____qualname____doc__request_queue_sizer+   r3   __classcell__r/   s   @r   r
   r
   D   s     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                2    t        |   |i | || _        y r   )r*   r+   r?   )r,   r?   r-   r.   r/   s       r   r+   zThreadedWSGIServer.__init__[   s    $)&)$8!r!   c                     | j                   r+| j                   j                         D ]  \  }}|t        |<    t        |   ||       y r   )r?   itemsr   r*   process_request_thread)r,   r4   r5   aliasconnr/   s        r   rC   z)ThreadedWSGIServer.process_request_threada   sE    $$  $88>>@t%)E"  A&w?r!   c                 ,    t        j                          y r   )r   	close_allr,   s    r   _close_connectionsz%ThreadedWSGIServer._close_connectionsi   s    r!   c                 D    | j                          t        | 	  |       y r   )rI   r*   close_request)r,   r4   r/   s     r   rK   z ThreadedWSGIServer.close_requestm   s    !g&r!   )
r6   r7   r8   r9   daemon_threadsr+   rC   rI   rK   r;   r<   s   @r   r>   r>   V   s(    .N37 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        |j                  d            }t	        |   t        ||      |||fi | y# t        t        f$ r d}Y 1w xY w)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^    	 -=!>?N 	%0&&'	
MS	
 I& 	N	s   ; AAc                    t         |           | j                  d   dk(  r6d| j                  v r(t	        | j                  d         dk(  r| j                  d= | j                  d   dk7  rd| j                  vrd| j                  d<   n=t        | j                  j                  t        j                        sd| j                  d<   | j                  j                  d      dk(  rd| j                  _        y y )NREQUEST_METHODHEADzContent-Length0close
ConnectionT)r*   cleanup_headersrX   headersstr
isinstancerequest_handlerserversocketserverThreadingMixInrR   close_connectionr,   r/   s    r   r`   zServerHandler.cleanup_headers   s    !LL)*f4 DLL0DLL!123s:-.
 LL)*f4 4)0DLL&D00779T9TU)0DLL& <<L)W448D  1 5r!   c                 ^    | j                         j                          t        |           y r   )	get_stdinreadr*   r^   ri   s    r   r^   zServerHandler.close   s    r!   c                     | j                   d   dk(  rE	 t        | j                  d       | j                  s| j	                          | j                          y t        |           y # | j                          w xY w)Nr[   r\   r   )maxlen)rX   r   resultheaders_sentsend_headersr^   r*   finish_responseri   s    r   rr   zServerHandler.finish_response   s`    <<()V3
dkk!, ((%%'

G#% 

s   3A( (A:)	r6   r7   r8   http_versionr+   r`   r^   rr   r;   r<   s   @r   rN   rN   r   s!    L
90& &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                   | j                         d}|d   d   dk(  r1|d   j                  d      rd|d<   t        j	                  d|	       y |d   j                         rat        |d         d
k(  rPt        |d         }||d<   |dk\  rt        j                  }n7|dk\  rt        j                  }n!t        j                  }nt        j                  } ||g|d|i y )N)r4   server_time   r   4zi  status_codezNYou're accessing the development server over HTTPS, but it only supports HTTP.)extra   i  r|   )
r4   log_date_time_string
startswithr1   errorisdigitlenrQ   warningr2   )r,   formatr-   r|   r{   levels         r   log_messagezWSGIRequestHandler.log_message   s    ||446
 71:Aw!!*-'*m$-  
 7??T!W!2d1g,K#.E- c!#KKEf)t)5)r!   c                 f    | j                   D ]  }d|v s| j                   |=  t        | 	         S )Nr   )ra   r*   get_environ)r,   kr/   s     r   r   zWSGIRequestHandler.get_environ   s5    
 AaxLLO  w"$$r!   c                    d| _         | j                          | j                   s| j                          | j                   s	 | j                  j                  t        j
                         y # t        t        f$ r Y y w xY w)NT)rh   handle_one_request
connectionshutdownr'   SHUT_WRAttributeErrorOSErrorrH   s    r   handlezWSGIRequestHandler.handle   sh     $!''##% ''	OO$$V^^4( 		s   )A, ,A>=A>c                    | j                   j                  d      | _        t        | j                        dkD  r'd| _        d| _        d| _        | j                  d       y| j                         syt        | j                   | j                  | j                         | j                               }| |_        |j                  | j                  j!                                y)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   rd   runre   get_app)r,   handlers     r   r   z%WSGIRequestHandler.handle_one_request   s    #zz2259t##$u,!D#%D DLOOC !!#JJ

DOO$5t7G7G7I
 #'DKK'')*r!   )
r6   r7   r8   protocol_versionrv   r   r   r   r   r;   r<   s   @r   r   r      s"    !&*>	%+r!   r   Fc                     | |f}|rt        dt        j                  |fi       }n|} ||t        |      }	| |t	        |	d|             |rd|	_        |	j                  |       |	j                          y )Nr
   )r$   server_portT)typerf   rg   r   r   rL   set_appserve_forever)
addrportwsgi_handlerr$   	threadingon_bind
server_clsserver_address	httpd_clshttpds
             r   r   r      sz     D\N(C(CZ'PRTU		n&8tDE}d34  $	MM,	r!   )r9   loggingr'   rf   r   collectionsr   wsgirefr   django.core.exceptionsr   django.core.handlers.wsgir   django.core.wsgir   	django.dbr   django.utils.module_loadingr	   __all__	getLoggerr1   r   r    r
   rg   r>   rN   r   r    r!   r   <module>r      s       
  ! 7 3 1 ! 5
.			?	+8	:)) :$'44j '8<&M// <&~L+99 L+f 
r!   