HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux spn-python 5.15.0-89-generic #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64
User: arjun (1000)
PHP: 8.1.2-1ubuntu2.20
Disabled: NONE
Upload Files
File: //usr/lib/python3/dist-packages/twisted/web/__pycache__/vhost.cpython-310.pyc
o

�b�@shdZddlmZddlmZGdd�dej�ZGdd�dej�ZGdd	�d	ej�Z	Gd
d�dej�Z
dS)
z&
I am a virtual hosts implementation.
�)�roots)�resourcec@s>eZdZdZejZdd�Zdd�Zdd�Z	dd	�Z
d
d�Zd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�rrrr	�listStaticEntitiessz(VirtualHostCollection.listStaticEntitiescCs|jj�|�Sr)rr�get�r�namerrr	�getStaticEntitysz%VirtualHostCollection.getStaticEntitycCs|j�||�dSr)r�addHost)rr�entityrrr	�reallyPutEntity sz%VirtualHostCollection.reallyPutEntitycCs|j�|�dSr)r�
removeHostrrrr	�	delEntity#szVirtualHostCollection.delEntityN)�__name__�
__module__�__qualname__�__doc__r�Resource�
entityTyper
rrrrrrrr	rsrc@sTeZdZdZdZdd�Zdd�Zdd�Zd	d
�Zdd�Z	d
d�Z
dd�Zdd�ZdS)�NameVirtualHostz5I am a resource which represents named virtual hosts.NcCstj�|�i|_dS)zInitialize.N)rrr
rr
rrr	r
,s
zNameVirtualHost.__init__cCstj�|�dt|�fgS�Nz
Virtual Hosts)rrrrr
rrr	r1s

�z"NameVirtualHost.listStaticEntitiescCs|dkrt|�Stj�||�Sr)rrrrrrrr	r6szNameVirtualHost.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�resrcrrr	r<szNameVirtualHost.addHostcCs|j|=dS)zRemove a host.Nr rrrr	rIszNameVirtualHost.removeHostcCsV|�d�}|dkr|jpt��S|���dd�d}|j�||j�p*t�dt|��S)z;(Internal) Get the appropriate resource for the given host.shostN�:�rzhost %s not in vhost map)	�	getHeader�defaultr�
NoResource�lower�splitrr�repr)r�request�
hostHeader�hostrrr	�_getResourceForRequestMs

�z&NameVirtualHost._getResourceForRequestcCs|�|�}|�|�S)z4Implementation of resource.Resource's render method.)r-�render)rr*r!rrr	r.Xs

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!rrr	�getChild]s

zNameVirtualHost.getChild)
rrrrr%r
rrrrr-r.r7rrrr	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�lenr3�joinr1r6�uri�site�getResourceFor)rr6r*r,�port�	prefixLenrrr	r7hs

&z_HostResource.getChildN)rrrr7rrrr	r8gsr8c@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)Nrrrrrr	�<lambda>��z/VHostMonsterResource.getChild.<locals>.<lambda>shttpscSrI)Nr#rrrrr	rJ�rK)r@r8)rr6r*rrr	r7�s
�
zVHostMonsterResource.getChildN)rrrrr7rrrr	rHvsrHN)r�twisted.pythonr�twisted.webr�
Homogenousrrrr8rHrrrr	�<module>s@