
    qi9                     8   S r SrSSKrSSKrSSK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  \R(                  " \5      rS	rS
r " S S\R2                  5      r " S S\R6                  \R8                  5      rS r\S:X  a  \" S5      eg)ae  
ext_wsgiutils_server.py is an extension of the wsgiutils server in Paste.
It supports passing all of the HTTP and WebDAV (rfc 2518) methods.

It includes code from the following sources:
``wsgiServer.py`` from wsgiKit <http://www.owlfish.com/software/wsgiutils/> under PSF license,
``wsgiutils_server.py`` from Paste <http://pythonpaste.org> under PSF license,
flexible handler method <http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/307618>
under public domain.


Running as standalone server
----------------------------

To run as a standalone server using the bundled ext_wsgiutils_server.py::

        usage: python ext_wsgiutils_server.py [options] [config-file]

        config-file:
          The configuration file for WsgiDAV. if omitted, the application
          will look for a file named 'WsgiDAV.conf' in the current directory

        options:
          --port=PORT  Port to serve on (default: 8080)
          --host=HOST  Host to serve from (default: localhost, which is only
                            accessible from the local computer; use 0.0.0.0 to make your
                            application public)
          -h, --help   show this help message and exit


Running using other web servers
-------------------------------

To run it with other WSGI web servers, you can::

        from wsgidav.mainappwrapper import PyFileApp
        publish_app = PyFileApp('WsgiDAV.conf')
        # construct the application with configuration file
        # if configuration file is omitted, the application
        # will look for a file named 'WsgiDAV.conf'
        # in the current directory

where ``publish_app`` is the WSGI application to be run, it will be called with
``publish_app(environ, start_response)`` for each incoming request, as described in
`WSGI <http://www.python.org/peps/pep-3333.html>`_

Note: if you are using the paster development server (from Paste <http://pythonpaste.org>), you
can copy ``ext_wsgi_server.py`` to ``<Paste-installation>/paste/servers`` and use this server to
run the application by specifying ``server='ext_wsgiutils'`` in the ``server.conf`` or appropriate
paste configuration.
reStructuredText    N)client)server)StringIO)urlparse)utilg      ?z<html>
  <head>
     <title>Server Error</title>
  </head>
  <body>
     <h1>Server Error</h1>
     A server error has occurred.  Please contact the system administrator for
     more information.
  </body>
</html>
c                       \ rS rSr/ SQrSr\R                   S\ S\	R                  R                   3rS rS rS rS	 rS
 rS rS rSS jrS rSrg)
ExtHandlerY   )HEADGETPUTPOSTOPTIONSTRACEDELETEPROPFIND	PROPPATCHMKCOLCOPYMOVELOCKUNLOCKzHTTP/1.1z ExtServer/ c                     g N selfargss     X/home/kali/flask_env/lib/python3.13/site-packages/wsgidav/server/ext_wsgiutils_server.pylog_messageExtHandler.log_messagep           c                     g r   r   r   s     r!   log_requestExtHandler.log_requestu   r$   r%   c                 \   [        SU R                   3SS9u  pp4pVU R                  R                   Hw  u  pxUR	                  U5      (       d  M  U[        U5      S  n	[        U	5      S:  a  U	R	                  S5      (       d  SU	-   n	UR                  S5      (       a  US S n
OUn
XX4s  $    g)Nzhttp://dummyhostF)allow_fragmentsr   /)NNNN)r   pathr   wsgiApplications
startswithlenendswith)r   	_protocol_hostr-   _parametersquery	_fragmentappPathapp	path_infoscript_names              r!   getAppExtHandler.getAppz   s    @Htyyk*EA
=	$U !KK88LGw'' W0	y>A%$//44$')O	##C((")#2,K")K99 9 &r%   c                    ^  U 4S jnU$ )Nc                  &   > TR                  5         g r   )	do_method)r    kwargsr   s     r!   handlerFunction:ExtHandler.handlerFunctionClosure.<locals>.handlerFunction   s    NNr%   r   )r   namerA   s   `  r!   handlerFunctionClosure!ExtHandler.handlerFunctionClosure   s    	 r%   c                     U R                  5       u  pp4U(       d  U R                  SS5        g U R                  XX45        g )Ni  zApplication not found.)r;   
send_error
runWSGIApp)r   r8   r:   r9   r5   s        r!   r?   ExtHandler.do_method   s5    -1[[]*)OOC!9:);r%   c                     [        U5      S:  a-  USS S:X  a$  USS  U R                  ;   a  U R                  U5      $ US:X  a  [        eU R	                  SS5        g )N   r   do__headers_bufferi  zMethod Not Implemented.)r0   _SUPPORTED_METHODSrD   AttributeErrorrG   )r   rC   s     r!   __getattr__ExtHandler.__getattr__   s_    t9q=T!AY%/DH@W@W4W..t44&&  67r%   c           	         U R                   S:X  a   0 SS_SS_SU R                  _S[        R                  _SS	_S
S_SS_SU R                   _SU_SU_SU_SU R                  R                  SS5      _SU R                  R                  SS5      _SU R                  S   _SU R                  R                  S   _S[        R                  " U R                  R                  S	   5      _SU R                  _nU R                  R                  5        HL  u  pgUR                  5       S;  d  M  XuSR                  UR                  SS5      R!                  5       5      '   MN     SU l        / U l         [&        R)                  S5        U" XPR*                  5      n U H2  n	U	(       a  U R-                  U	5        M  [&        R)                  S5        M4     [&        R)                  S 5        [/        US!5      (       a  UR1                  5         U R"                  (       d  U R-                  S&5        g ! [&        R)                  S 5        [/        US!5      (       a  UR1                  5         f f = f! [2         a    [&        R)                  S"5        [5        5       n
[6        R8                  " U
S#9  [:        R<                  " U
R?                  5       5        U R"                  (       d  U R+                  S$S%/5        U R-                  [@        5         Nf = f)'Nr   zwsgi.version)   r   zwsgi.url_schemehttpz
wsgi.inputzwsgi.errorszwsgi.multithreadrS   zwsgi.multiprocessr   zwsgi.run_onceREQUEST_METHODSCRIPT_NAME	PATH_INFOQUERY_STRINGCONTENT_TYPEzContent-Type CONTENT_LENGTHzContent-LengthREMOTE_ADDRSERVER_NAMESERVER_PORTSERVER_PROTOCOL)zcontent-typezcontent-lengthzHTTP_{}-_zrunWSGIApp application()...zrunWSGIApp empty datazrunWSGIApp finally.closezrunWSGIApp caught exception...filez500 Server Error)zContent-typez	text/htmlr%   )!commandrfilesysstderrheadersgetclient_addressr   server_addressr   to_strrequest_versionitemslowerformatreplaceupperwsgiSentHeaderswsgiHeaders_loggerdebugwsgiStartResponsewsgiWriteDatahasattrrb   	Exceptionr   	traceback	print_excloggingerrorgetvalueSERVER_ERROR)r   applicationr:   r9   r5   env
httpHeader	httpValueresultdataerrorMsgs              r!   rH   ExtHandler.runWSGIApp   s    <<5 
F
v
 $**
 3::	

 
  
 Q
 dll
 ;
 
 E
 DLL,,^R@
 dll../?D
 4..q1
 4;;55a8
  4;;t{{'A'A!'DE!
" t33#
& &*\\%7%7%9!J!)KKNWI$$Z%7%7S%A%G%G%IJK &:
  !	-MM78 &<&<=F	#"D**40&=>	 # 3467++LLN ## s#' 3467++LLN , 		-MM:;zHX.MM(++-.''&&&)F(G |,		-s+   /'I$ 8H( 6I$ (9I!!I$ $BL LNc           	          [         R                  SU SU SU S35        U R                  (       a  [        S5      eX4U l        U R
                  $ )NzwsgiStartResponse(z, )z5Headers already sent and start_response called again!)rv   rw   rt   r{   ru   ry   )r   response_statusresponse_headersexc_infos       r!   rx   ExtHandler.wsgiStartResponse   sX      14D3ERzQRS	
 STT+>!!!r%   c           
      v   U R                   (       d  U R                  u  p#US UR                  S5       nX"R                  S5      S-   S  n[        R	                  SU< SU< 35        U R                  [        U5      U5        U H  u  pgU R                  Xg5        M     U R                  5         SU l         [        U5      [        L d   e[        R	                  S[        U5       S[        R                  " US S 5      < S35        [        R                  " U5      (       a/  [        R                  S	U< 35        [        R                   " U5      n U R"                  R%                  U5        g ! [&         aA  nUR(                  S
   S;   a(  [        R                  SU[*        R,                  S9   S nAg e S nAff = f)Nr   rS   zwsgiWriteData: send headers 'z', zwsgiWriteData: write z	 bytes: '2   z'...z(ext_wsgiutils_server: Got unicode data: r   iE'  iF'  z*** Caught socket.error: %src   )rt   ru   findrv   rw   send_responseintsend_headerend_headerstypebytesr0   r   rm   is_strinfoto_byteswfilewriteOSErrorr    rg   rh   )	r   r   statusri   
statusCode	statusMsgheadervaluees	            r!   ry   ExtHandler.wsgiWriteData   sn   ##"..OF 2&++c"23J{{3/!356IMM9&3wkRSs:	:!(  / ")#$D DzU"""#CI;iD"I8N7QQUV	
 ;;tLLCD8LM==&D		JJT" 	 vvayN*:ACJJO	s   E- -
F876F32F33F8)ru   rt   r   )__name__
__module____qualname____firstlineno__rN   protocol_versionr   public_wsgidav_info_versionBaseHTTPServerBaseHTTPRequestHandlerserver_versionr"   r'   r;   rD   r?   rP   rH   rx   ry   __static_attributes__r   r%   r!   r
   r
   Y   sk    $ "001XJaHmHmH|H|G}~N

&*<@D"r%   r
   c                   0    \ rS rSrS rS rS rSS jrSrg)		ExtServeri  c                 :   [         R                  " 5       nUS   nUR                  S   S;   a  [        R	                  SU 35        g[        R	                  S[         R
                  S9  [        R	                  S[        R                  " 5       R                   S	U 35        [        R	                  U[         R
                  S9  [        R                  " 5         [        R	                  S[         R
                  S9  [        R	                  U[         R
                  S9  g)
zkHandle an error gracefully.  May be overridden.

The default is to _logger.info a traceback and continue.

rS   r   r   z*** Caught socket.error: Nz(----------------------------------------rc   <z7> Exception happened during processing of request from )rg   r   r    rv   r   rh   	threadingcurrent_threadidentr|   r}   )r   requestrk   eir   s        r!   handle_errorExtServer.handle_error  s     \\^qE 66!9&MM5aS9: 	hSZZ0	((*0011hiwhxy	
 	n3::6hSZZ0gCJJ/r%   c                    [        U S5      (       d   S5       eU R                  (       a   S5       eSU l        [        R                  " S5        U R                  (       a  gS n[        [
        S5      (       d  U[
        l        U R                  u  p#[        R                  " U S	U 35      nUR                  S
S5        UR                  5         U R                  (       d   eg)zStop serve_forever_stoppable().stop_requestz/serve_forever_stoppable() must be called beforez-stop_serve_forever() must only be called onceTg?Nc                 h    U R                  S5        U R                  5         SU R                  l        g)zhSend 200 OK response, and set server.stop_request to True.

http://code.activestate.com/recipes/336012/
   TN)r   r   r   r   r   s    r!   _shutdownHandler6ExtServer.stop_serve_forever.<locals>._shutdownHandler>  s*     s#'+DKK$r%   do_SHUTDOWN:SHUTDOWNr+   )rz   r   timesleepstoppedr
   r   rl   http_clientHTTPConnectionr   getresponse)r   r   hostportconns        r!   stop_serve_foreverExtServer.stop_serve_forever/  s    .
 
 	=<	= 
 $$U&UU$ !

3<<	, z=11%5J" **))TF!D6*:;Z%    r%   c                     SU l         SU l        U R                   (       d#  U R                  5         U R                   (       d  M#  SU l        g)zfHandle one request at a time until stop_serve_forever().

http://code.activestate.com/recipes/336012/
FTN)r   r   handle_requestr   s    r!   serve_forever_stoppable!ExtServer.serve_forever_stoppableU  s?    
 "##! ### r%   c                     [         R                  R                  X[        5        / nUR	                  5        H  u  pVUR                  XV45        M     X@l        X0l        SU l        g )Nr   )	r   
HTTPServer__init__r
   ro   appendr.   
serveFilesserverShuttingDown)r   serverAddressr.   r   appListurlPathwsgiApps          r!   r   ExtServer.__init__c  sU    !!**4
K 0 6 6 8GNNG-. !9 '$"#r%   )r   r   r   r   r.   N)rS   )	r   r   r   r   r   r   r   r   r   r   r%   r!   r   r     s    06$!L$r%   r   c                    U R                  SS5      n[        U R                  SS5      5      n[        X#4SU05      n[        R                  nU R                  S5      S:  a  [
        R                  SU 35        US	;   aP  [        R                  " [        R                  " 5       5      u  pgn[
        R                  S
U SU SU< SU S3	5        O[
        R                  S
U SU S35        UR                  5         g )Nr   	localhostr   i  rZ   verboserS   zRunning )rZ   z0.0.0.0zServing at z, port z (host=r   z)...z...)rj   r   r   r
   r   rv   r   socketgethostbyname_exgethostnameserve_forever)	confr8   r   r   r   r   hostname
_aliaslist
ipaddrlists	            r!   server   m  s    88FK(Dtxx%&D|b#Y/F..Nxx	ax/01?"171H1H""$2.X: LLdV74&|1ZLPTU LL;tfGD6=>
r%   __main__zUse run_server.py) __doc____docformat__r~   r   socketserverrg   r   r   r|   rT   r   r   r   r   ior   urllib.parser   wsgidavr   get_module_loggerr   rv   r   r   r   r
   ThreadingMixInr   r   r   RuntimeErrorr   r%   r!   <module>r      s   2f #    
    & )  ! 

 
 
*w66 wtW$++^-F-F W$t( z
*
++ r%   