
    LȂi0&                     x   S r SSKrSSKrSSKrSSKrSSKJr  SSKJr  SSK	J
r
  SSKJr  SSKJr  SSKJr  SS	KJr  SS
KJr  Sr\R,                  " S5      rS rS r " S S\R4                  5      r " S S\R6                  \5      r " S S\R:                  5      r " S S\R<                  5      rSSS\4S jrg)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)log_message)import_string)
WSGIServerWSGIRequestHandlerzdjango.serverc                      SSK Jn   [        U S5      nUc
  [        5       $  [	        U5      $ ! [
         a  n[        SU-  5      UeSnAff = f)a'  
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      MD:\sksbv-state-backend\venv\Lib\site-packages\django/core/servers/basehttp.pyget_internal_wsgi_applicationr      sb     %x!34H#%%X&& "&(01
 	s   
, 
A
AA
c                  j    [         R                  " 5       u  n   n[        U [        [        [
        45      $ N)sysexc_info
issubclassBrokenPipeErrorConnectionAbortedErrorConnectionResetError)exc_type_s     r   is_broken_pipe_errorr!   9   s1    \\^NHa" 	
     c                   F   ^  \ rS rSrSrSrSSS.U 4S jjrU 4S jrS	rU =r	$ )
r   E   z7BaseHTTPServer that implements the Python WSGI protocol
   FT)ipv6allow_reuse_addressc                j   > U(       a  [         R                  U l        X l        [        TU ]  " U0 UD6  g r   )socketAF_INET6address_familyr'   super__init__)selfr&   r'   argskwargs	__class__s        r   r-   WSGIServer.__init__J   s*    "(//D#6 $)&)r"   c                 p   > [        5       (       a  [        R                  SU5        g [        TU ]  X5        g )Nz- Broken pipe from %s)r!   loggerinfor,   handle_error)r.   requestclient_addressr1   s      r   r6   WSGIServer.handle_errorP   s(    !!KK/@G 9r"   )r+   r'   )
__name__
__module____qualname____firstlineno____doc__request_queue_sizer-   r6   __static_attributes____classcell__r1   s   @r   r   r   E   s%    A#(d * *: :r"   r   c                   V   ^  \ rS rSrSrSrSS.U 4S jjrU 4S jrS rU 4S	 jr	Sr
U =r$ )
ThreadedWSGIServerW   z$A threaded version of the WSGIServerTN)connections_overridec                2   > [         TU ]  " U0 UD6  Xl        g r   )r,   r-   rF   )r.   rF   r/   r0   r1   s       r   r-   ThreadedWSGIServer.__init__\   s    $)&)$8!r"   c                    > U R                   (       a,  U R                   R                  5        H  u  p4U[        U'   M     [        TU ]  X5        g r   )rF   itemsr   r,   process_request_thread)r.   r7   r8   aliasconnr1   s        r   rK   )ThreadedWSGIServer.process_request_threadb   sA    $$  $88>>@%)E"  A&w?r"   c                 .    [         R                  " 5         g r   )r   	close_allr.   s    r   _close_connections%ThreadedWSGIServer._close_connectionsj   s    r"   c                 D   > U R                  5         [        TU ]	  U5        g r   )rR   r,   close_request)r.   r7   r1   s     r   rU    ThreadedWSGIServer.close_requestn   s    !g&r"   )r:   r;   r<   r=   r>   daemon_threadsr-   rK   rR   rU   r@   rA   rB   s   @r   rD   rD   W   s-    .N37 9 9@ ' 'r"   rD   c                   P   ^  \ rS rSrSrU 4S jrU 4S jrU 4S jrU 4S jrSr	U =r
$ )ServerHandlers   z1.1c                    >  [        UR                  S5      5      n[        TU ]  " [        X5      X#U40 UD6  g! [        [        4 a    Sn N1f = f)z
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environr0   content_lengthr1   s          r   r-   ServerHandler.__init__v   sZ    	 -=!>?N 	%0&'	
MS	
 I& 	N	s   : AAc                   > [         TU ]  5         U R                  S   S:X  a9  SU R                  ;   a)  [	        U R                  S   5      S:X  a  U R                  S	 U R                  S   S:w  a   SU R                  ;  a  SU R                  S'   OB[        U R                  R                  [        R                  5      (       d  SU R                  S'   U R                  R                  S5      S:X  a  SU R                  l        g g )NREQUEST_METHODHEADzContent-Length0close
ConnectionT)r,   cleanup_headersrd   headersstr
isinstancerequest_handlerserversocketserverThreadingMixInr^   close_connectionr.   r1   s    r   rm   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U)0DLL& <<L)W448D  1 5r"   c                 ^   > U R                  5       R                  5         [        TU ]  5         g r   )	get_stdinreadr,   rk   rv   s    r   rk   ServerHandler.close   s    r"   c                    > U R                   S   S:X  aG   [        U R                  SS9  U R                  (       d  U R	                  5         U R                  5         g [        TU ]  5         g ! U R                  5         f = f)Nrh   ri   r   )maxlen)rd   r   resultheaders_sentsend_headersrk   r,   finish_responserv   s    r   r   ServerHandler.finish_response   s`    <<()V3
dkk!, ((%%'

G#% 

s   5A+ +A= )r:   r;   r<   r=   http_versionr-   rm   rk   r   r@   rA   rB   s   @r   rY   rY   s   s!    L
90& &r"   rY   c                   D   ^  \ rS rSrSrS rS rU 4S jrS rS r	Sr
U =r$ )	r      zHTTP/1.1c                      U R                   S   $ )Nr   )r8   rQ   s    r   address_string!WSGIRequestHandler.address_string   s    ""1%%r"   c                 .   US   S   S:X  a   US   R                  S5      (       a  SnSnSnO;US   R                  5       (       a!  [        US   5      S:X  a  [        US   5      nOS n[	        [
        U/UQ7U R                  UU R                  5       S	.6  g )
N   r   4zzNYou're accessing the development server over HTTPS, but it only supports HTTP.i  r      )r7   status_codeserver_time)
startswithisdigitlenr]   r	   r4   r7   log_date_time_string)r.   formatr/   r   s       r   r	   WSGIRequestHandler.log_message   s    71:a!3!3J!?!?!  KD!W__3tAw<1#4d1g,KK	
 	
 LL#113	
r"   c                 p   > U R                    H  nSU;   d  M  U R                   U	 M     [        TU ]	  5       $ )Nr    )rn   r,   get_environ)r.   kr1   s     r   r   WSGIRequestHandler.get_environ   s5    
 AaxLLO  w"$$r"   c                    SU l         U R                  5         U R                   (       d#  U R                  5         U R                   (       d  M#   U R                  R                  [        R
                  5        g ! [        [        4 a     g f = f)NT)ru   handle_one_request
connectionshutdownr)   SHUT_WRAttributeErrorOSErrorrQ   s    r   handleWSGIRequestHandler.handle   sk     $!''##% '''	OO$$V^^4( 		s   )A7 7B
	B
c                    U R                   R                  S5      U l        [        U R                  5      S:  a'  SU l        SU l        SU l        U R                  S5        gU R                  5       (       d  g[        U R                   U R                  U R                  5       U R                  5       5      nXl        UR                  U R                  R!                  5       5        g)zF
Copy of WSGIRequestHandler.handle() but with different ServerHandler
i  i    i  N)rfilereadlineraw_requestliner   requestlinerequest_versioncommand
send_errorparse_requestrY   wfile
get_stderrr   rq   runrr   get_app)r.   handlers     r   r   %WSGIRequestHandler.handle_one_request   s      $zz2259t##$u,!D#%D DLOOC !!##JJ

DOO$5t7G7G7I
 #'DKK'')*r"   )ru   r   r   r   r   )r:   r;   r<   r=   protocol_versionr   r	   r   r   r   r@   rA   rB   s   @r   r   r      s'    !&
.	%+ +r"   r   Fc                     X4nU(       a  [        S[        R                  U40 5      nOUnU" U[        US9n	Ub  U" [	        U	SU5      5        U(       a  SU	l        U	R                  U5        U	R                  5         g )Nr   )r&   server_portT)typers   rt   r   r   rW   set_appserve_forever)
addrportwsgi_handlerr&   	threadingon_bind
server_clsserver_address	httpd_clshttpds
             r   r   r      sx     \N(C(CZ'PRTU		n&8tDE}d34  $	MM,	r"   ) r>   loggingr)   rs   r   collectionsr   wsgirefr   django.core.exceptionsr   django.core.handlers.wsgir   django.core.wsgir   	django.dbr   django.utils.logr	   django.utils.module_loadingr
   __all__	getLoggerr4   r   r!   r   rt   rD   rY   r   r   r   r"   r   <module>r      s       
  ! 7 3 1 ! ( 5
.			?	+8	:)) :$'44j '8<&M// <&~F+99 F+Z 
r"   