
    h5/                        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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JrJrJrJr  SSKJr   " S S\R:                  5      r " S S\R>                  \R@                  5      r \RB                  " \R@                  \ 5         " S S5      r" " S S\RF                  5      r$ " S S\RJ                  \RL                  5      r' " S S\RF                  5      r(g! \ a    Sr Nf = f)z
Distributed web servers.

This is going to have to be refactored so that argument parsing is done
by each subprocess and not by the main web server (i.e. GET, POST etc.).
    N)BytesIO)getDOMImplementation)addressreactor)Logger)styles)pb)
SIZE_LIMIT)httpresourceserverstaticutil)Headersc                   ,    \ rS rSrS rS rS rS rSrg)_ReferenceableProducerWrapper    c                     Xl         g Nproducer)selfr   s     Z/root/1688_scrapy/alibaba-scraper/venv/lib/python3.13/site-packages/twisted/web/distrib.py__init__&_ReferenceableProducerWrapper.__init__!   s         c                 8    U R                   R                  5         g r   )r   resumeProducingr   s    r   remote_resumeProducing4_ReferenceableProducerWrapper.remote_resumeProducing$   s    %%'r   c                 8    U R                   R                  5         g r   )r   pauseProducingr   s    r   remote_pauseProducing3_ReferenceableProducerWrapper.remote_pauseProducing'   s    $$&r   c                 8    U R                   R                  5         g r   )r   stopProducingr   s    r   remote_stopProducing2_ReferenceableProducerWrapper.remote_stopProducing*   s    ##%r   r   N)	__name__
__module____qualname____firstlineno__r   r    r$   r(   __static_attributes__ r   r   r   r       s    !('&r   r   c                   6    \ rS rSrSrS rS rS rS rS r	Sr
g	)
Request.   zb
A request which was received by a L{ResourceSubscription} and sent via
PB to a distributed node.
c                   ^^ S H,  nX   mSSS.TS      mUU4S jU4S jS.T   " 5       nX1U'   M.     [        [        US	   5      5      US	'   [        R                  R	                  X5        [        U R                  5      U l        U R                  R                  S
5      U l
        U R                  R                  S5      U l        U R                  R                  S5      U l        U R                  R                  S5      U l        U R                  R                  S5      U l        U R                  R                  S5      U l        U R                  R                  S5      U l        g)z
Initialize this L{twisted.web.distrib.Request} based on the copied
state so that it closely resembles a L{twisted.web.server.Request}.
)hostclientTCPUNIX)INETr7   r   c                  @   > [         R                  " T TS   TS   5      $ )N      )r   IPv4Address)addrdesctups   r   <lambda>*Request.setCopyableState.<locals>.<lambda>=   s    w228SVSVLr   c                  6   > [         R                  " T S   5      $ )Nr:   )r   UNIXAddress)r>   s   r   r?   r@   >   s     3 3CF ;r   )r6   r7   requestHeadersfinish	setHeader	addCookiesetETagsetResponseCodesetLastModifiedwriteN)r   dictr	   
RemoteCopysetCopyableStater   content_datacontentremoteremoteMethodrD   rE   rF   rG   rH   rI   _write)r   statekaddrr=   r>   s       @@r   rM   Request.setCopyableState4   s/   
 "A(C %v6s1v>HL;  D !H " #*$u5E/F*G"H
&&t3t001kk..x811+>11+>{{//	:#{{778IJ#{{778IJ kk..w7r   c                     Sn[         n U R                  XU 5        U[         -  nU[         -  nU[        U5      :  a  gM7  )z
Write the given bytes to the response body.

@param bytes: The bytes to write.  If this is longer than 640k, it
    will be split up into smaller pieces.
r   N)r
   rR   len)r   bytesstartends       r   rJ   Request.writeP   sJ     KKC()ZE:CE
" r   c                     U R                   R                  S[        U5      U5      R                  U R                  5        g )NregisterProducer)rP   
callRemoter   
addErrbackfail)r   r   	streamings      r   r^   Request.registerProducer`   s/     =h G	

*TYY
r   c                 l    U R                   R                  S5      R                  U R                  5        g )NunregisterProducer)rP   r_   r`   ra   r   s    r   re   Request.unregisterProducere   s$    34??		Jr   c                 8    U R                   R                  SUS9  g )N )failure)_logri   r   ri   s     r   ra   Request.failh   s    		"g.r   )rR   rF   rO   rD   rG   rE   rI   rH   N)r*   r+   r,   r-   __doc__rM   rJ   r^   re   ra   r.   r/   r   r   r1   r1   .   s!    
88  
K/r   r1   c                   4    \ rS rSr\" 5       rS rS rS rSr	g)Issueo   c                     Xl         g r   request)r   rs   s     r   r   Issue.__init__r   s    r   c                     U[         R                  LaR  [        U[        5      (       d   S5       eU R                  R                  U5        U R                  R                  5         g g )Nzreturn value not a string)r   NOT_DONE_YET
isinstancestrrs   rJ   rD   )r   results     r   finishedIssue.finishedu   sP    ,,,fc**G,GG*LLv&LL! -r   c           
      b   [        U5      nU R                  R                  [        R                  " [
        R                  SS[        R                  " U5      -   5      R                  U R                  5      5        U R                  R                  5         U R                  R                  U5        g )NzServer Connection Lostz&Connection to distributed server lost:)rx   rs   rJ   r   _UnsafeErrorPager   INTERNAL_SERVER_ERRORr   _PRErenderrD   rj   infork   s     r   failedIssue.failed{   sz    g,%%**(8499W;MM	
 fT\\"	
 			wr   rr   N)
r*   r+   r,   r-   r   rj   r   rz   r   r.   r/   r   r   ro   ro   o   s    8D" r   ro   c                   N    \ rS rSrSrSr\" 5       rS rS r	S r
S rS rS	 rS
rg)ResourceSubscription   r:   r   c                 v    [         R                  R                  U 5        Xl        X l        / U l        S U l        g r   )r   Resourcer   r4   portpending	publisher)r   r4   r   s      r   r   ResourceSubscription.__init__   s.    ""4(		r   c                 d    [         R                   " U R                  5      nSUS'   SUS'   / US'   U$ )z3Get persistent state for this ResourceSubscription.Nr   r   waitingr   )copy__dict__)r   rS   s     r   __getstate__!ResourceSubscription.__getstate__   s9     		$--(!kiir   c                     U R                   R                  S5        UR                  R                  U R                  5        Xl        SU l        U R                   H  nU R                  U5        M     / U l        g)z=I've connected to a publisher; I'll now send all my requests.zconnected to publisherr   N)	rj   r   brokernotifyOnDisconnectbootedr   r   r   r   )r   r   rs   s      r   	connectedResourceSubscription.connected   sX    		/0++DKK8"||GKK  $r   c                     U R                   R                  SUS9  SU l        SU l        U R                   H$  nUR                  S5        UR                  5         M&     / U l        g)zHI can't connect to a publisher; I'll now reply to all pending
requests.
z3could not connect to distributed web service: {msg})msgr   Nz(Unable to connect to distributed server.)rj   r   r   r   r   rJ   rD   )r   r   rs   s      r   notConnected!ResourceSubscription.notConnected   sV     			LRUV||GMMDENN $ r   c                 &    U R                  S5        g )Nzconnection dropped)r   r   s    r   r   ResourceSubscription.booted   s    ./r   c                    U R                   (       d  U R                  R                  U5        U R                  (       d  SU l        [        R
                  " 5       nSnU R                  S:X  a"  [        R                  " U R                  X#5        O,[        R                  " U R                  U R                  X#5        UR                  5       nUR                  U R                  U R                  5        [&        R(                  $ [        U5      nU R                   R!                  SU5      R                  UR"                  UR$                  5        [&        R(                  $ )a  Render this request, from my server.

This will always be asynchronous, and therefore return NOT_DONE_YET.
It spins off a request to the pb client, and either adds it to the list
of pending issues or requests it immediately, depending on if the
client is already connected.
r:   
   unixrs   )r   r   appendr   r	   PBClientFactoryr4   r   connectUNIXr   
connectTCPgetRootObjectaddCallbacksr   r   ro   r_   rz   r   r   rv   )r   rs   bftimeoutdis         r   r   ResourceSubscription.render   s     ~~LL(<< '')99&''		2?&&tyy$))RI$$&t~~t/@/@A """	 gANN%%i9FF

AHH """r   )r4   r   r   r   r   N)r*   r+   r,   r-   isLeafr   r   rj   r   r   r   r   r   r   r.   r/   r   r   r   r      s1    FG8D

0#r   r   c                   B    \ rS rSrSr\" 5       rS rSrS r	S r
S rSrg	)
ResourcePublisher   z
L{ResourcePublisher} exposes a remote API which can be used to respond
to request.

@ivar site: The site which will be used for resource lookup.
@type site: L{twisted.web.server.Site}
c                     Xl         g r   site)r   r   s     r   r   ResourcePublisher.__init__   s    	r   r;   c                     U R                   R                  R                  S5        U R                   R                  U R                  	 U ?U ? U ?g )Nweb)application
authorizerremoveIdentityservicesserviceNameperspectiveNamer   s    r   upgradeToVersion2#ResourcePublisher.upgradeToVersion2   sH    ##2259%%d&6&67 r   c                     U $ r   r/   )r   names     r   getPerspectiveNamed%ResourcePublisher.getPerspectiveNamed   s    r   c                    U R                   R                  U5      nU R                  R                  U5        UR	                  U5      nU[
        R                  La!  UR                  U5        UR                  5         [
        R                  $ )z;
Look up the resource for the given request and render it.
)	r   getResourceForrj   r   r   r   rv   rJ   rD   )r   rs   resry   s       r   remote_request ResourcePublisher.remote_request   sf     ii&&w/		wG$,,,MM&!NN"""r   r   N)r*   r+   r,   r-   rm   r   rj   r   persistenceVersionr   r   r   r.   r/   r   r   r   r      s,     8D !
#r   r   c                   @    \ rS rSrSrSrSrSrSS jrS r	S	 r
S
 rSrg)UserDirectory   z
A resource which lists available user resources and serves them as
children.

@ivar _pwd: An object like L{pwd} which is used to enumerate users and
    their home directories.
public_htmlz.twistd-web-pba  
<html>
    <head>
    <title>twisted.web.distrib.UserDirectory</title>
    <style>

    a
    {
        font-family: Lucida, Verdana, Helvetica, Arial, sans-serif;
        color: #369;
        text-decoration: none;
    }

    th
    {
        font-family: Lucida, Verdana, Helvetica, Arial, sans-serif;
        font-weight: bold;
        text-decoration: none;
        text-align: left;
    }

    pre, code
    {
        font-family: "Courier New", Courier, monospace;
    }

    p, body, td, ol, ul, menu, blockquote, div
    {
        font-family: Lucida, Verdana, Helvetica, Arial, sans-serif;
        color: #000;
    }
    </style>
    </head>

    <body>
    <h1>twisted.web.distrib.UserDirectory</h1>

    %(users)s
</body>
</html>
Nc                 `    [         R                  R                  U 5        Uc  [        nXl        g r   )r   r   r   pwd_pwd)r   userDatabases     r   r   UserDirectory.__init__5  s&    ""4(L 	r   c                 &   / nU R                   R                  5        H  nUu  p4pVpxn	UR                  S5      S   n
U
(       d  Un
[        R                  R                  [        R                  R                  XR                  5      5      (       a  UR                  X:S-   45        [        R                  R                  XR                  5      n[        R                  R                  U5      (       d  M  US-   nUR                  XS-   45        M     U$ )zd
Return a list of two-tuples giving links to user resources and text to
associate with those links.
,r   z (file)z.twistdz	 (twistd))
r   getpwallsplitospathexistsjoinuserDirNamer   userSocketName)r   usersuserr   passwduidgidgecosdirshellrealname
twistdsocklinkNames                r   _usersUserDirectory._users;  s    
 II&&(D8<5D#E{{3'*Hww~~bggll30@0@ABBdy$89:c+>+>?Jww~~j)))+h;(>?@ ) r   c                    [        5       nUR                  SSS5      nUR                  nU R                  5        H  u  pVUR	                  S5      nUR                  SUS-   5        UR                  U5      nUR                  U5        UR	                  S5      n	U	R                  U5        UR                  U	5        M     U R                  SUR                  5       0-  n
U
R                  S5      $ )	zU
Render as HTML a listing of all known users with links to their
personal resources.
Nulahref/lir   zutf-8)r   createDocumentdocumentElementr   createElementsetAttributecreateTextNodeappendChildtemplatetoxmlencode)r   rs   domImplnewDoclistinglinktextlinkElementtextNodeitemhtmlDocs              r   
render_GETUserDirectory.render_GETN  s     '(''dD9((++-JD ..s3K$$VTCZ8,,T2H##H-''-D[)% ( --GW]]_#=>~~g&&r   c                    US:X  a  U $ SnUR                  U5      (       a  US [        U5      *  nSnOUnSn U R                  R                  UR	                  [
        R                  " 5       5      5      u  nnnn	n
nnU(       aH  [        R                  R                  XR                  5      n[        SU5      nU R                  X5        U$ [        R                  R                  XR                   5      n[        R                  R#                  U5      (       d  [        R                  " 5       $ [$        R&                  " U5      $ ! [         a    [        R                  " 5       s $ f = f)Nr   s   .twistdr:   r   r   )endswithrX   r   getpwnamdecodesysgetfilesystemencodingKeyErrorr   _UnsafeNoResourcer   r   r   r   r   putChildr   r   r   File)r   r   rs   tdusernamesubpw_name	pw_passwdpw_uidpw_gidpw_gecospw_dirpw_shellr   rsr   s                   r   getChildUserDirectory.getChildc  s+   3;K==Js2wh'HCHC	0 		""8??33L3L3N#OP f.A.ABJ%fj9BMM$#I77<<(8(89D77>>$''1133;;t$$  	0--//	0s   AE E&%E&)r   r   )r*   r+   r,   r-   rm   r   r   r   r   r   r  r  r.   r/   r   r   r   r      s/      K%N(HT!&'*#%r   r   ))rm   r   r   r  r   ImportErrorior   xml.dom.minidomr   twisted.internetr   r   twisted.loggerr   twisted.persistedr   twisted.spreadr	   twisted.spread.bananar
   twisted.webr   r   r   r   r   twisted.web.http_headersr   Referenceabler   rL   r1   setUnjellyableForClassro   r   r   Root	Versionedr   r   r/   r   r   <module>r(     s   
  	 
  0 - ! $  , < < ,&B$4$4 &;/bmmV^^ ;/|   &..' 2   6K#8,, K#\$#!1!1 $#NG%H%% G%[  
Cs   C; ;DD