Ë
    "ïàjÇ9  ã                   ó6  — d Z dZddlZddlZddl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  ej(                  e«      Zd	Zd
Z G d„ dej2                  «      Z G d„ dej6                  ej8                  «      Zd„ Zedk(  r ed«      ‚y)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                   ó    — e Zd Zg d¢ZdZej                  › de› dej                  j                  › �Z
d„ Zd„ Zd„ Zd„ Zd	„ Zd
„ Zd„ Zdd„Zd„ Zy)Ú
ExtHandler)ÚHEADÚGETÚPUTÚPOSTÚOPTIONSÚTRACEÚDELETEÚPROPFINDÚ	PROPPATCHÚMKCOLÚCOPYÚMOVEÚLOCKÚUNLOCKzHTTP/1.1z ExtServer/ú c                  ó   — y ©N© ©ÚselfÚargss     úR/srv/dav/.venv/lib/python3.12/site-packages/wsgidav/server/ext_wsgiutils_server.pyÚlog_messagezExtHandler.log_messageq   ó   € Øó    c                  ó   — y r   r   r   s     r    Úlog_requestzExtHandler.log_requestv   r"   r#   c                 óJ  — t        d| j                  › �d¬«      \  }}}}}}| j                  j                  D ]i  \  }}|j	                  |«      sŒ|t        |«      d  }	t        |	«      dkD  r|	j	                  d«      sd|	z   }	|j                  d«      r|d d }
n|}
||
|	|fc S  y)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    ÚgetAppzExtHandler.getApp{   sº   € ä@HØ˜tŸy™y˜kÐ*¸EôA
Ñ=ˆ	�5˜$ ¨U°Ið !ŸK™K×8Ñ8ò 	:‰LˆG�SØ�‰˜wÕ'à ¤ W£ Ð0�	Ü�y“> AÒ%Ø$×/Ñ/°Ô4Ø$'¨)¡O˜	Ø×#Ñ# CÔ(Ø")¨#¨2 ,‘Kà")�Kà˜K¨°EÐ9Ò9ð	:ð &r#   c                 ó   ‡ — ˆ fd„}|S )Nc                  ó&   •— ‰j                  «        y r   )Ú	do_method)r   Úkwargsr   s     €r    ÚhandlerFunctionz:ExtHandler.handlerFunctionClosure.<locals>.handlerFunction‘   s   ø€ Ø�N‰NÕr#   r   )r   Únamer=   s   `  r    ÚhandlerFunctionClosurez!ExtHandler.handlerFunctionClosure�   s   ø€ ô	ð Ðr#   c                 ó€   — | j                  «       \  }}}}|s| j                  dd«       y | j                  ||||«       y )Ni”  zApplication not found.)r8   Ú
send_errorÚ
runWSGIApp)r   r5   r7   r6   r2   s        r    r;   zExtHandler.do_method–   s=   € Ø-1¯[©[«]Ñ*ˆˆ[˜) UÙØ�O‰O˜CÐ!9Ô:ØØ�‰˜˜[¨)°UÕ;r#   c                 ó®   — t        |«      dkD  r*|dd dk(  r"|dd  | j                  v r| j                  |«      S |dk(  rt        ‚| j	                  dd«       y )Né   r   Údo_Ú_headers_bufferiõ  zMethod Not Implemented.)r-   Ú_SUPPORTED_METHODSr?   ÚAttributeErrorrA   )r   r>   s     r    Ú__getattr__zExtHandler.__getattr__�   s_   € Üˆt‹9�qŠ=˜T ! A˜Y¨%Ò/°D¸¸°HÀ×@WÑ@WÑ4WØ×.Ñ.¨tÓ4Ð4ØÐ&Ò&ä Ð Ø�‰˜Ð6Ô7Ør#   c           	      óÌ  — | j                   dk(  r	 i dd“dd“d| j                  “dt        j                  “dd	“d
d“dd“d| j                   “d|“d|“d|“d| j                  j                  dd«      “d| j                  j                  dd«      “d| j                  d   “d| j                  j                  d   “dt        j                  | j                  j                  d	   «      “d| j                  “}| j                  j                  «       D ]J  \  }}|j                  «       dvsŒ||dj                  |j                  dd«      j!                  «       «      <   ŒL d| _        g | _        	 t&        j)                  d«        ||| j*                  «      }	 |D ]+  }	|	r| j-                  |	«       Œt&        j)                  d«       Œ- 	 t&        j)                  d «       t/        |d!«      r|j1                  «        	 | j"                  s| j-                  d&«       y # t&        j)                  d «       t/        |d!«      r|j1                  «        w w xY w# t2        $ r� t&        j)                  d"«       t5        «       }
t7        j8                  |
¬#«       t;        j<                  |
j?                  «       «       | j"                  s| j+                  d$d%g«       | j-                  t@        «       Y Œìw xY w)'Nr   zwsgi.version)é   r   zwsgi.url_schemeÚhttpz
wsgi.inputzwsgi.errorszwsgi.multithreadrK   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ÚhasattrrZ   Ú	Exceptionr   Ú	tracebackÚ	print_excÚloggingÚerrorÚgetvalueÚSERVER_ERROR)r   Úapplicationr7   r6   r2   ÚenvÚ
httpHeaderÚ	httpValueÚresultÚdataÚerrorMsgs              r    rB   zExtHandler.runWSGIApp¦   sñ  € ð �<‰<˜5Ò Øð
Ø˜Fð
à˜vð
ð ˜$Ÿ*™*ð
ð œ3Ÿ:™:ð	
ð
  ð
ð   ð
ð ˜Qð
ð ˜dŸl™lð
ð ˜;ð
ð ˜ð
ð ˜Eð
ð ˜DŸL™L×,Ñ,¨^¸RÓ@ð
ð ˜dŸl™l×.Ñ.Ð/?ÀÓDð
ð ˜4×.Ñ.¨qÑ1ð
ð ˜4Ÿ;™;×5Ñ5°aÑ8ð
ð  œ4Ÿ;™; t§{¡{×'AÑ'AÀ!Ñ'DÓEð!
ð" ˜t×3Ñ3ð#
ˆð& &*§\¡\×%7Ñ%7Ó%9ò 	XÑ!ˆJ˜	Ø×ÑÓ!Ð)KÒKØNW��I×$Ñ$ Z×%7Ñ%7¸¸SÓ%A×%GÑ%GÓ%IÓJÒKð	Xð
  !ˆÔØˆÔð	-ä�M‰MÐ7Ô8Ù   d×&<Ñ&<Ó=ˆFð	#Ø"ò ?�DÙØ×*Ñ*¨4Õ0äŸ™Ð&=Õ>ñ	?ô —‘Ð3Ô4Ü˜6 7Ô+Ø—L‘L•Nð ×#Ò#ð ×Ñ˜sÔ#Øøô' —‘Ð3Ô4Ü˜6 7Ô+Ø—L‘L•Nð ,ûäò 		-Ü�M‰MÐ:Ô;Ü“zˆHÜ×Ñ XÕ.Ü�M‰M˜(×+Ñ+Ó-Ô.Ø×'Ò'Ø×&Ñ&Ø&Ð)FÐ(Gôð ×Ñœ|Ö,ð		-ús+   Å*(I Æ0H Ç2I È4IÉI ÉBK#Ë"K#Nc           	      ó˜   — t         j                  d|› d|› d|› d�«       | j                  rt        d«      ‚||f| _        | j
                  S )NzwsgiStartResponse(z, ú)z5Headers already sent and start_response called again!)rn   ro   rl   rs   rm   rq   )r   Úresponse_statusÚresponse_headersÚexc_infos       r    rp   zExtHandler.wsgiStartResponseè   s[   € Ü�‰Ø  Ð 1°Ð4DÐ3EÀRÈÀzÐQRÐSô	
ð ×ÒÜÐSÓTÐTà+Ð-=Ð>ˆÔØ×!Ñ!Ð!r#   c           
      óX  — | j                   s£| j                  \  }}|d |j                  d«       }||j                  d«      dz   d  }t        j	                  d|›d|›�«       | j                  t        |«      |«       |D ]  \  }}| j                  ||«       Œ | j                  «        d| _         t        |«      t        u sJ ‚t        j	                  dt        |«      › dt        j                  |d d «      ›d�«       t        j                  |«      r-t        j                  d	|›�«       t        j                   |«      }	 | j"                  j%                  |«       y # t&        $ rC}|j(                  d
   dv r't        j                  d|t*        j,                  ¬«       n‚ Y d }~y d }~ww xY w)Nr   rK   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: %sr[   )rl   rm   Úfindrn   ro   Úsend_responseÚintÚsend_headerÚend_headersÚtypeÚbytesr-   r   re   Úis_strÚinfoÚto_bytesÚwfileÚwriteÚOSErrorr   r_   r`   )	r   r   Ústatusra   Ú
statusCodeÚ	statusMsgÚheaderÚvalueÚes	            r    rq   zExtHandler.wsgiWriteDataò   s~  € Ø×#Ò#Ø"×.Ñ.‰OˆF�GàÐ 2 &§+¡+¨cÓ"2Ð3ˆJØ˜vŸ{™{¨3Ó/°!Ñ3Ð5Ð6ˆIÜ�M‰MÐ9¸&¸À3ÀwÀkÐRÔSØ×Ñœs :›°	Ô:Ø!(ò 0‘�˜Ø× Ñ  ¨Õ/ð0à×ÑÔØ#$ˆDÔ ä�D‹zœUÑ"Ð"Ð"Ü�‰Ø#¤C¨£I ;¨i¼¿¹ÀDÈÈ"ÀIÓ8NÐ7QÐQUÐVô	
ô �;‰;�tÔÜ�L‰LÐCÀDÀ8ÐLÔMä—=‘= Ó&ˆDð		Ø�J‰J×Ñ˜TÕ"øÜò 	ð �v‰v�a‰y˜NÑ*Ü—‘Ð:¸AÄCÇJÁJ�ÕOàô Pûð	ús   ÅE Å	F)Å&9F$Æ$F)r   )Ú__name__Ú
__module__Ú__qualname__rG   Úprotocol_versionr   Úpublic_wsgidav_infoÚ_versionÚBaseHTTPServerÚBaseHTTPRequestHandlerÚserver_versionr!   r%   r8   r?   r;   rI   rB   rp   rq   r   r#   r    r
   r
   Z   sk   „ òÐð$ "Ðà×0Ñ0Ð1°¸X¸JÀaÈ×HmÑHm×H|ÑH|ÐG}Ð~€Nòò
ò
&ò*ò<òò@óD"ór#   r
   c                   ó&   — e Zd Zd„ Zd„ Zd„ Zdd„Zy)Ú	ExtServerc                 óH  — t        j                  «       }|d   }|j                  d   dv rt        j	                  d|› �«       yt        j	                  dt         j
                  ¬«       t        j	                  dt        j                  «       j                  › d	|› �«       t        j	                  |t         j
                  ¬«       t        j                  «        t        j	                  dt         j
                  ¬«       t        j	                  |t         j
                  ¬«       y)
z{Handle an error gracefully.  May be overridden.

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

        rK   r   rˆ   z*** Caught socket.error: Nz(----------------------------------------r[   ú<z7> Exception happened during processing of request from )r_   r…   r   rn   rw   r`   Ú	threadingÚcurrent_threadÚidentrt   ru   )r   Úrequestrc   Úeir›   s        r    Úhandle_errorzExtServer.handle_error  sÐ   € ô �\‰\‹^ˆØˆq‰Eˆð �6‰6�!‰9˜Ñ&Ü�M‰MÐ5°a°SÐ9Ô:Øô 	�‰�h¤S§Z¡ZˆÔ0Ü�‰Ø”	×(Ñ(Ó*×0Ñ0Ð1Ð1hÐiwÐhxÐyô	
ô 	�‰�n¬3¯:©:ˆÔ6Ü×ÑÔÜ�‰�h¤S§Z¡ZˆÔ0Ü�‰�g¤C§J¡JˆÕ/r#   c                 ó�  — t        | d«      sJ d«       ‚| j                  rJ d«       ‚d| _        t        j                  d«       | j                  ryd„ }t        t
        d«      s|t
        _        | j                  \  }}t        j                  |› d	|› �«      }|j                  d
d«       |j                  «        | j                  sJ ‚y)zStop serve_forever_stoppable().Ústop_requestz/serve_forever_stoppable() must be called beforez-stop_serve_forever() must only be called onceTgš™™™™™¹?Nc                 óh   — | j                  d«       | j                  «        d| j                  _        y)z€Send 200 OK response, and set server.stop_request to True.

            http://code.activestate.com/recipes/336012/
            éÈ   TN)rŠ   r�   r   r°   ©r   s    r    Ú_shutdownHandlerz6ExtServer.stop_serve_forever.<locals>._shutdownHandler?  s*   € ð ×Ñ˜sÔ#Ø×ÑÔØ'+ˆD�K‰KÕ$r#   Údo_SHUTDOWNú:ÚSHUTDOWNr(   )rr   r°   ÚtimeÚsleepÚstoppedr
   rµ   rd   Úhttp_clientÚHTTPConnectionr¬   Úgetresponse)r   r´   ÚhostÚportÚconns        r    Ústop_serve_foreverzExtServer.stop_serve_forever0  sÀ   € ä�t˜^Ô,ð 	
Ø=ó	
Ð,ð ×$Ò$ÐUÐ&UÓUÐ$ð !ˆÔÜ�
‰
�3ŒØ�<Š<àò	,ô ”z =Ô1Ø%5ŒJÔ"ð ×*Ñ*‰ˆˆtä×)Ñ)¨T¨F°!°D°6Ð*:Ó;ˆØ�‰�Z Ô%à×ÑÔà× Ò Ð Ñ r#   c                 ó€   — d| _         d| _        | j                   s| j                  «        | j                   sŒd| _        y)zvHandle one request at a time until stop_serve_forever().

        http://code.activestate.com/recipes/336012/
        FTN)r°   rº   Úhandle_requestr³   s    r    Úserve_forever_stoppablez!ExtServer.serve_forever_stoppableV  s<   € ð
 "ˆÔØˆŒà×#Ò#Ø×ÑÔ!ð ×#Ó#ð ˆ�r#   c                 óÒ   — t         j                  j                  | |t        «       g }|j	                  «       D ]  \  }}|j                  ||f«       Œ || _        || _        d| _        y )Nr   )	r¢   Ú
HTTPServerÚ__init__r
   rg   Úappendr+   Ú
serveFilesÚserverShuttingDown)r   ÚserverAddressr+   rÉ   ÚappListÚurlPathÚwsgiApps          r    rÇ   zExtServer.__init__d  sd   € Ü×!Ñ!×*Ñ*¨4°Ä
ÔKØˆØ 0× 6Ñ 6Ó 8ò 	/ÑˆG�WØ�N‰N˜G WÐ-Õ.ð	/à 'ˆÔØ$ˆŒØ"#ˆÕr#   N)rK   )rœ   r�   rž   r®   rÁ   rÄ   rÇ   r   r#   r    r¦   r¦     s   „ ò0ò6$!òLô$r#   r¦   c                 óò  — | j                  dd«      }t        | j                  dd«      «      }t        ||fd|i«      }t        j                  }| j                  d«      dk\  r†t
        j                  d|› �«       |d	v rNt        j                  t        j                  «       «      \  }}}t
        j                  d
|› d|› d|›d|› d�	«       nt
        j                  d
|› d|› d�«       |j                  «        y )Nr¾   Ú	localhostr¿   i�  rR   ÚverboserK   zRunning )rR   z0.0.0.0zServing at z, port z (host=r   z)...z...)rb   r‹   r¦   r
   r¤   rn   r‘   ÚsocketÚgethostbyname_exÚgethostnameÚserve_forever)	Úconfr5   r¾   r¿   r   r¤   ÚhostnameÚ
_aliaslistÚ
ipaddrlists	            r    ÚserverÚ   n  sì   € Ø�8‰8�F˜KÓ(€DÜˆt�x‰x˜ Ó%Ó&€DÜ˜˜d�| b¨# YÓ/€FÜ×.Ñ.€NØ‡x�x�	Ó˜aÒÜ�‰�x Ð/Ð0Ô1Ø�?Ñ"Ü17×1HÑ1HÜ×"Ñ"Ó$ó2Ñ.ˆX�z :ô �L‰LØ˜d˜V 7¨4¨&°¸°|À1ÀZÀLÐPTÐUõô �L‰L˜; t f¨G°D°6¸Ð=Ô>Ø
×ÑÕr#   Ú__main__zUse run_server.py) Ú__doc__Ú__docformat__rv   rÒ   Úsocketserverr_   r©   r¸   rt   rL   r   r»   r   r¢   Úior   Úurllib.parser   Úwsgidavr   Úget_module_loggerrœ   rn   r¡   ry   r£   r
   ÚThreadingMixInrÆ   r¦   rÚ   ÚRuntimeErrorr   r#   r    ú<module>rå      s¦   ðñ2ðh #€ã Û Û Û 
Û Û Û Ý &Ý )Ý Ý !å à
 ˆ$×
 Ñ
  Ó
*€à€ð€ôw�×6Ñ6ô wôtW$�×+Ñ+¨^×-FÑ-Fô W$òtð( ˆzÒÙ
Ð*Ó
+Ð+ð r#   