
    \dG                         d Z ddlmZ ddlmZmZ  G d dej                  Z G d dej                  Z	 G d d	ej                  Z
 G d
 dej                  ZdS )z&
I am a virtual hosts implementation.
    )roots)pagesresourcec                   >    e Zd ZdZej        Zd Zd Zd Z	d Z
d ZdS )VirtualHostCollectionzWWrapper for virtual hosts collection.

    This exists for configuration purposes.
    c                     || _         d S N)nvh)selfr
   s     1lib/python3.11/site-packages/twisted/web/vhost.py__init__zVirtualHostCollection.__init__   s        c                 >    | j         j                                        S r	   )r
   hostsitemsr   s    r   listStaticEntitiesz(VirtualHostCollection.listStaticEntities   s    x~##%%%r   c                 @    | j         j                            |           S r	   )r
   r   getr   names     r   getStaticEntityz%VirtualHostCollection.getStaticEntity   s    x~!!$'''r   c                 <    | j                             ||           d S r	   )r
   addHost)r   r   entitys      r   reallyPutEntityz%VirtualHostCollection.reallyPutEntity    s     v&&&&&r   c                 :    | j                             |           d S r	   )r
   
removeHostr   s     r   	delEntityzVirtualHostCollection.delEntity#   s    D!!!!!r   N)__name__
__module____qualname____doc__r   Resource
entityTyper   r   r   r   r    r   r   r   r      ss         
 "J  & & &( ( (' ' '" " " " "r   r   c                   F    e Zd ZdZdZd Zd Zd Zd Zd Z	d Z
d	 Zd
 ZdS )NameVirtualHostz5I am a resource which represents named virtual hosts.Nc                 R    t           j                            |            i | _        dS )zInitialize.N)r   r$   r   r   r   s    r   r   zNameVirtualHost.__init__,   s$    ""4(((


r   c                 f    t           j                            |           dt          |           fgz   S NzVirtual Hosts)r   r$   r   r   r   s    r   r   z"NameVirtualHost.listStaticEntities1   s6     33D993D99:=
 
 	
r   c                 l    |dk    rt          |           S t          j                            | |          S r+   )r   r   r$   r   r   s     r   r   zNameVirtualHost.getStaticEntity6   s4    ?""(...$44T4@@@r   c                     || j         |<   dS )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   )r   r   resrcs      r   r   zNameVirtualHost.addHost<   s     !
4r   c                     | j         |= dS )zRemove a host.Nr.   r   s     r   r   zNameVirtualHost.removeHostI   s    Jtr   c                 Z   |                     d          }|| j        pt          j                    S |                                                    dd          d         }| j                            || j                  p,t          j        dd|                    dd	          d
          S )z;(Internal) Get the appropriate resource for the given host.s   hostN   :   r   z	Not Foundzhost asciireplacez not in vhost map)		getHeaderdefaultr   notFoundlowersplitr   r   decode)r   request
hostHeaderhosts       r   _getResourceForRequestz&NameVirtualHost._getResourceForRequestM   s    &&w//
<35>#3#33##%%++D!44Q7Dz~~dDL11 
U^HDKK33HHH6
 6
 	
r   c                 V    |                      |          }|                    |          S )z4Implementation of resource.Resource's render method.)r?   render)r   r<   r/   s      r   rA   zNameVirtualHost.renderY   s'    ++G44||G$$$r   c                     |                      |          }|j        r5|j                            d|j                            d                     |S |                    ||          S )z6Implementation of resource.Resource's getChild method.r   )r?   isLeafpostpathinsertprepathpopgetChildWithDefault)r   pathr<   r/   s       r   getChildzNameVirtualHost.getChild^   sc    ++G44< 	<##Aw':':2'>'>???L,,T7;;;r   )r    r!   r"   r#   r7   r   r   r   r   r   r?   rA   rK   r&   r   r   r(   r(   '   s        ??G  

 
 

A A A! ! !  

 

 

% % %
< < < < <r   r(   c                       e Zd Zd ZdS )_HostResourcec                    d|v r)|                     dd          \  }}t          |          }n|d}}|                    ||           d|                                z   dz   t	          |          z   t	          |j        d                   z   }dd                    |j                  z   |_        |j	        |d          |_	        |j        d d= |j
                            |          S )Nr2   r3   P            /)r:   intsetHostisSecurelenrG   joinrE   rJ   urisitegetResourceFor)r   rJ   r<   r>   port	prefixLens         r   rK   z_HostResource.getChildi   s    4<<D!,,JD$t99DDr$Dd###((***Q.T:SQSAT=U=UU	dii(8999k)**-OBQB|**7333r   N)r    r!   r"   rK   r&   r   r   rM   rM   h   s#        4 4 4 4 4r   rM   c                       e Zd ZdZd ZdS )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
    c                 X    |dk    r	d |_         n|dk    rd |_         t                      S )Ns   httpc                      dS )Nr   r&   r&   r   r   <lambda>z/VHostMonsterResource.getChild.<locals>.<lambda>       q r   s   httpsc                      dS )Nr3   r&   r&   r   r   rb   z/VHostMonsterResource.getChild.<locals>.<lambda>   rc   r   )rV   rM   )r   rJ   r<   s      r   rK   zVHostMonsterResource.getChild   s7    7??(yGX(yGr   N)r    r!   r"   r#   rK   r&   r   r   r_   r_   w   s-        	 	    r   r_   N)r#   twisted.pythonr   twisted.webr   r   
Homogenousr   r$   r(   rM   r_   r&   r   r   <module>rh      s   
  !           ' ' ' ' ' ' ' '" " " " "E, " " "0>< >< >< >< ><h' >< >< ><B4 4 4 4 4H% 4 4 4    8,     r   