o 5Ä@g—ã@s˜dZzddlmZWneyddlmZYnwddlmZddlm Z Gdd„dej ƒZ Gdd„de j ƒZ Gd d „d e j ƒZGd d „d e j ƒZd S)z& I am a virtual hosts implementation. é)Úescape)Úroots)Úresourcec@s>eZdZdZejZdd„Zdd„Zdd„Z dd „Z d d „Z d S) ÚVirtualHostCollectionzWWrapper for virtual hosts collection. This exists for configuration purposes. cCs ||_dS©N)Únvh)Úselfr©r ú3/usr/lib/python3/dist-packages/twisted/web/vhost.pyÚ__init__s zVirtualHostCollection.__init__cCs |jj ¡Sr)rÚhostsÚitems©rr r r ÚlistStaticEntitiess z(VirtualHostCollection.listStaticEntitiescCs|jj |¡Sr)rr Úget©rÚnamer r r ÚgetStaticEntity"sz%VirtualHostCollection.getStaticEntitycCs|j ||¡dSr)rÚaddHost)rrÚentityr r r ÚreallyPutEntity%sz%VirtualHostCollection.reallyPutEntitycCs|j |¡dSr)rÚ removeHostrr r r Ú delEntity(szVirtualHostCollection.delEntityN) Ú__name__Ú __module__Ú __qualname__Ú__doc__rÚResourceÚ entityTyper rrrrr r r r rs rc@sTeZdZdZdZdd„Zdd„Zdd„Zd d „Zd d „Z d d„Z dd„Z dd„Z dS)ÚNameVirtualHostz5I am a resource which represents named virtual hosts.NcCstj |¡i|_dS)z Initialize.N)rrr r rr r r r 1s  zNameVirtualHost.__init__cCstj |¡dt|ƒfgS©Nz Virtual Hosts)rrrrrr r r r6s  ÿz"NameVirtualHost.listStaticEntitiescCs|dkrt|ƒStj ||¡Sr )rrrrrr r r r;szNameVirtualHost.getStaticEntitycCs||j|<dS)a¼Add a host to this virtual host. This will take a host named `name', and map it to a resource `resrc'. For example, a setup for our virtual hosts would be:: nvh.addHost('divunal.com', divunalDirectory) nvh.addHost('www.divunal.com', divunalDirectory) nvh.addHost('twistedmatrix.com', twistedMatrixDirectory) nvh.addHost('www.twistedmatrix.com', twistedMatrixDirectory) N©r )rrÚresrcr r r rAs zNameVirtualHost.addHostcCs |j|=dS)zRemove a host.Nr!rr r r rNs zNameVirtualHost.removeHostcCsZ| d¡}|dkr|jpt ¡S| ¡ dd¡d}|j ||j¡p,t dtt |ƒƒ¡S)z;(Internal) Get the appropriate resource for the given host.shostNó:érzhost %s not in vhost map) Ú getHeaderÚdefaultrÚ NoResourceÚlowerÚsplitr rÚ html_escapeÚrepr)rÚrequestÚ hostHeaderÚhostr r r Ú_getResourceForRequestRs ÿz&NameVirtualHost._getResourceForRequestcCs| |¡}| |¡S)z4Implementation of resource.Resource's render method.)r/Úrender)rr,r"r r r r0]s  zNameVirtualHost.rendercCs6| |¡}|jr|j d|j d¡¡|S| ||¡S)z6Implementation of resource.Resource's getChild method.réÿÿÿÿ)r/ÚisLeafÚpostpathÚinsertÚprepathÚpopÚgetChildWithDefault)rÚpathr,r"r r r ÚgetChildbs  zNameVirtualHost.getChild) rrrrr&r rrrrr/r0r9r r r r r,s  rc@seZdZdd„ZdS)Ú _HostResourcecCs˜d|vr| dd¡\}}t|ƒ}n|d}}| ||¡d| ¡dt|ƒt|jdƒ}dd |j¡|_|j |d…|_ |jdd…=|j   |¡S)Nr#r$éPéééýÿÿÿó/) r)ÚintÚsetHostÚisSecureÚlenr5Újoinr3r8ÚuriÚsiteÚgetResourceFor)rr8r,r.ÚportÚ prefixLenr r r r9ms   &  z_HostResource.getChildN)rrrr9r r r r r:ls r:c@seZdZdZdd„ZdS)ÚVHostMonsterResourcea. Use this to be able to record the hostname and method (http vs. https) in the URL without disturbing your web site. If you put this resource in a URL http://foo.com/bar then requests to http://foo.com/bar/http/baz.com/something will be equivalent to http://foo.com/something, except that the hostname the request will appear to be accessing will be "baz.com". So if "baz.com" is redirecting all requests for to foo.com, while foo.com is inaccessible from the outside, then redirect and url generation will work correctly cCs0|dkr dd„|_tƒS|dkrdd„|_tƒS)NshttpcSódS)Nrr r r r r ÚŠóz/VHostMonsterResource.getChild..shttpscSrK)Nr$r r r r r rLŒrM)rBr:)rr8r,r r r r9ˆs  þ zVHostMonsterResource.getChildN)rrrrr9r r r r rJ{s rJN)rÚhtmlrr*Ú ImportErrorÚcgiÚtwisted.pythonrÚ twisted.webrÚ Homogenousrrrr:rJr r r r Ús ÿ  @