Ϫf5/dZddlZddlZddlZ ddlZddlmZddlm Z ddl m Z m Z ddl mZddlmZddlmZdd lmZdd lmZmZmZmZmZdd lmZGd d ej:ZGddej>ej@Z ejBej@e GddZ"GddejFZ$GddejJejLZ'GddejFZ(y#e$rdZYwxYw)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)addressreactor)Logger)styles)pb) SIZE_LIMIT)httpresourceserverstaticutil)Headersc$eZdZdZdZdZdZy)_ReferenceableProducerWrapperc||_yN)producer)selfrs 5/usr/lib/python3/dist-packages/twisted/web/distrib.py__init__z&_ReferenceableProducerWrapper.__init__!s   c8|jjyr)rresumeProducingrs rremote_resumeProducingz4_ReferenceableProducerWrapper.remote_resumeProducing$s %%'rc8|jjyr)rpauseProducingrs rremote_pauseProducingz3_ReferenceableProducerWrapper.remote_pauseProducing's $$&rc8|jjyr)r stopProducingrs rremote_stopProducingz2_ReferenceableProducerWrapper.remote_stopProducing*s ##%rN)__name__ __module__ __qualname__rrr r#rrrr s!('&rrc.eZdZdZdZdZdZdZdZy)Requestzn A request which was received by a L{ResourceSubscription} and sent via PB to a distributed node. cdD]+}||ddddfdfdd}|||<-tt|d |d <tjj ||t |j |_|jjd |_ |jjd |_ |jjd |_ |jjd |_ |jjd|_|jjd|_|jjd|_y)z Initialize this L{twisted.web.distrib.Request} based on the copied state so that it closely resembles a L{twisted.web.server.Request}. )hostclientTCPUNIX)INETr.rc>tjddS)N)r IPv4Address)addrdesctupsrz*Request.setCopyableState..=sw228SVSVLrc4tjdS)Nr1)r UNIXAddress)r5srr6z*Request.setCopyableState..>s 3 3CF ;r)r-r.requestHeadersfinish setHeader addCookiesetETagsetResponseCodesetLastModifiedwriteN)rdictr RemoteCopysetCopyableStater content_datacontentremote remoteMethodr:r;r<r=r>r?_write)rstatekaddrr4r5s @@rrCzRequest.setCopyableState4s? " A(C %v6s1v>HL;DE!H #*$u5E/F*G"H &&tU3t001 kk..x8 11+>11+>{{// : #{{778IJ#{{778IJkk..w7 rcd}t} |j||||tz }|tz }|t|k\ry6)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. rN)r rHlen)rbytesstartends rr@z Request.writePsL KKeC( ) Z E : CE " rc|jjdt||j|jy)NregisterProducer)rF callRemoter addErrbackfail)rr streamings rrRzRequest.registerProducer`s/   =h G *TYY rcl|jjdj|jy)NunregisterProducer)rFrSrTrUrs rrXzRequest.unregisterProduceres$ 34?? Jrc>|jjd|y)N)failure)_logr[rr[s rrUz Request.failhs "g.rN) r$r%r&__doc__rCr@rRrXrUr'rrr)r).s! 88  K/rr)c,eZdZeZdZdZdZy)Issuec||_yr)request)rrbs rrzIssue.__init__rs  rc|tjurMt|tsJd|jj ||jj yy)Nzreturn value not a string)r NOT_DONE_YET isinstancestrrbr@r:)rresults rfinishedzIssue.finishedusM ,, ,fc* G,G G* LL  v & LL   ! -rc ^t|}|jjtjt j ddtj|zj|j|jj|jj|y)NzServer Connection Lostz&Connection to distributed server lost:) rfrbr@r _UnsafeErrorPager INTERNAL_SERVER_ERRORr_PRErenderr:r\infor]s rfailedz Issue.failed{szg,   % %**(8499W;MM   fT\\"    wrN)r$r%r&rr\rrhror'rrr`r`os 8D"  rr`cFeZdZdZdZeZdZdZdZ dZ dZ dZ y ) ResourceSubscriptionr1rcztjj|||_||_g|_d|_yr)r Resourcerr+portpending publisher)rr+rts rrzResourceSubscription.__init__s2""4(   rcbtj|j}d|d<d|d<g|d<|S)z3Get persistent state for this ResourceSubscription.Nrvrwaitingru)copy__dict__)rrIs r __getstate__z!ResourceSubscription.__getstate__s9 $--(!kii rc|jjd|jj|j||_d|_|jD]}|j|g|_y)z=I've connected to a publisher; I'll now send all my requests.zconnected to publisherrN) r\rnbrokernotifyOnDisconnectbootedrvrxrurm)rrvrbs r connectedzResourceSubscription.connecteds_ /0++DKK8" || !G KK  ! rc|jjd|d|_d|_|jD]#}|j d|j %g|_y)zXI can't connect to a publisher; I'll now reply to all pending requests. z3could not connect to distributed web service: {msg})msgrNz(Unable to connect to distributed server.)r\rnrxrvrur@r:)rrrbs r notConnectedz!ResourceSubscription.notConnecteds[ LRUV || G MMD E NN   rc&|jdy)Nzconnection dropped)rrs rrzResourceSubscription.booteds ./rc|js|jj||jsd|_t j }d}|j dk(r"tj|j||n,tj|j |j|||j}|j|j|jt&j(St|}|jj!d|j|j"|j$t&j(S)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. r1 unixrb)rvruappendrxr PBClientFactoryr+r connectUNIXrt connectTCP getRootObject addCallbacksrrr`rSrhror rd)rrbbftimeoutdis rrmzResourceSubscription.renders~~ LL   (<<  '')99&'' 2w?&&tyy$))RI$$&t~~t/@/@A""" gA NN % %i 9 F F AHH """rN) r$r%r&isLeafrxrr\rr{rrrrmr'rrrqrqs1 FG 8D  0#rrqc:eZdZdZeZdZdZdZdZ dZ y)ResourcePublisherz 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||_yr)site)rrs rrzResourcePublisher.__init__s  rr2c|jjjd|jj|j=|`|`|`y)Nweb) application authorizerremoveIdentityservices serviceNameperspectiveNamers rupgradeToVersion2z#ResourcePublisher.upgradeToVersion2sH ##2259    % %d&6&6 7      rc|Srr')rnames rgetPerspectiveNamedz%ResourcePublisher.getPerspectiveNameds rc|jj|}|jj||j |}|t j ur!|j||jt j S)zK Look up the resource for the given request and render it. ) rgetResourceForr\rnrmr rdr@r:)rrbresrgs rremote_requestz ResourcePublisher.remote_requestsfii&&w/ wG$ ,, , MM& ! NN """rN) r$r%r&r^rr\rpersistenceVersionrrrr'rrrrs, 8D! #rrc6eZdZdZdZdZdZd dZdZdZ d Z y) UserDirectoryz 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 twisted.web.distrib.UserDirectory

twisted.web.distrib.UserDirectory

%(users)s Nc`tjj||t}||_yr)r rsrpwd_pwd)r userDatabases rrzUserDirectory.__init__5s(""4(  L  rcg}|jjD]}|\}}}}}}} |jdd} | s|} tjj tjj ||jr|j|| dzftjj ||j} tjj | s|dz} |j| | dzf|S)z| Return a list of two-tuples giving links to user resources and text to associate with those links. ,rz (file)z.twistdz (twistd)) rgetpwallsplitospathexistsjoin userDirNameruserSocketName) rusersuserrpasswduidgidgecosdirshellrealname twistdsocklinkNames r_userszUserDirectory._users;s II&&( AD8< 5D&#sE3{{3'*Hww~~bggll30@0@AB dHy$89:c4+>+>?Jww~~j))+ h;(>?@ A rct}|jddd}|j}|jD]\}}|j d}|j d|dz|j |}|j||j d} | j||j| |jd|jiz} | jdS) zm Render as HTML a listing of all known users with links to their personal resources. Nulahref/lirzutf-8) rcreateDocumentdocumentElementr createElement setAttributecreateTextNode appendChildtemplatetoxmlencode) rrbdomImplnewDoclistinglinktext linkElementtextNodeitemhtmlDocs r render_GETzUserDirectory.render_GETNs '(''dD9((++- &JD$ ..s3K  $ $VTCZ 8,,T2H  # #H -''-D   [ )    % &--GW]]_#=>~~g&&rc|dk(r|Sd}|j|r|dt| }d}n|}d} |jj|j t j \}}}} } } } |rJtjj| |j} td| }|j|||Stjj| |j }tjj#|stjSt%j&|S#t$rtjcYSwxYw)Nrs.twistdr1rr)endswithrMrgetpwnamdecodesysgetfilesystemencodingKeyErrorr _UnsafeNoResourcerrrrrqputChildrrrFile)rrrbtdusernamesubpw_name pw_passwdpw_uidpw_gidpw_gecospw_dirpw_shellrrsrs rgetChildzUserDirectory.getChildcs+ 3;K  == Js2wh'HCHC 0 ""8??33L3L3N#OP  fd.A.ABJ%fj9B MM$ #I77<<(8(89D77>>$'1133;;t$ $ 0--/ / 0sAD44EEr) r$r%r&r^rrrrrrrr'rrrrs/ K%N(HT! &'*#%rr))r^ryrrr ImportErroriorxml.dom.minidomrtwisted.internetrrtwisted.loggerrtwisted.persistedrtwisted.spreadr twisted.spread.bananar twisted.webr r r rrtwisted.web.http_headersr ReferenceablerrBr)setUnjellyableForClassr`rsrqRoot Versionedrrr'rrrs  0-!$,<<, &B$4$4 &;/bmmV^^;/|&..'2  6K#8,,K#\$#!1!1$#NG%H%%G%[ CsC;;DD