
    hG                         S r SSKJr  SSKJrJr   " S S\R                  5      r " S S\R                  5      r	 " S S	\R                  5      r
 " S
 S\R                  5      rg)z&
I am a virtual hosts implementation.
    )roots)pagesresourcec                   N    \ rS rSrSr\R                  rS rS r	S r
S rS rSrg	)
VirtualHostCollection   zOWrapper for virtual hosts collection.

This exists for configuration purposes.
c                     Xl         g Nnvh)selfr   s     X/root/1688_scrapy/alibaba-scraper/venv/lib/python3.13/site-packages/twisted/web/vhost.py__init__VirtualHostCollection.__init__   s        c                 J    U R                   R                  R                  5       $ r
   )r   hostsitemsr   s    r   listStaticEntities(VirtualHostCollection.listStaticEntities   s    xx~~##%%r   c                 L    U R                   R                  R                  U 5      $ r
   )r   r   getr   names     r   getStaticEntity%VirtualHostCollection.getStaticEntity   s    xx~~!!$''r   c                 :    U R                   R                  X5        g r
   )r   addHost)r   r   entitys      r   reallyPutEntity%VirtualHostCollection.reallyPutEntity    s    &r   c                 :    U R                   R                  U5        g r
   )r   
removeHostr   s     r   	delEntityVirtualHostCollection.delEntity#   s    D!r   r   N)__name__
__module____qualname____firstlineno____doc__r   Resource
entityTyper   r   r   r!   r%   __static_attributes__ r   r   r   r      s-    
 ""J&('"r   r   c                   L    \ rS rSrSrSrS rS rS rS r	S r
S	 rS
 rS rSrg)NameVirtualHost'   z5I am a resource which represents named virtual hosts.Nc                 P    [         R                  R                  U 5        0 U l        g)zInitialize.N)r   r,   r   r   r   s    r   r   NameVirtualHost.__init__,   s    ""4(
r   c                 ^    [         R                  R                  U 5      S[        U 5      4/-   $ NzVirtual Hosts)r   r,   r   r   r   s    r   r   "NameVirtualHost.listStaticEntities1   s3      33D93D9:=
 
 	
r   c                 b    US:X  a  [        U 5      $ [        R                  R                  X5      $ r6   )r   r   r,   r   r   s     r   r   NameVirtualHost.getStaticEntity6   s,    ?"(..$$44T@@r   c                      X R                   U'   g)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   NameVirtualHost.addHost<   s     !

4r   c                     U R                   U	 g)zRemove a host.Nr;   r   s     r   r$   NameVirtualHost.removeHostI   s    JJtr   c                 p   UR                  S5      nUc(  U R                  =(       d    [        R                  " 5       $ UR	                  5       R                  SS5      S   nU R                  R                  X0R                  5      =(       d,    [        R                  " SSUR                  SS5      < S	35      $ )
z;(Internal) Get the appropriate resource for the given host.s   host   :   r   z	Not Foundzhost asciireplacez not in vhost map)		getHeaderdefaultr   notFoundlowersplitr   r   decode)r   request
hostHeaderhosts       r   _getResourceForRequest&NameVirtualHost._getResourceForRequestM   s    &&w/
<<35>>#33##%++D!4Q7Dzz~~dLL1 
U^^DKK366GH6
 	
r   c                 F    U R                  U5      nUR                  U5      $ )z4Implementation of resource.Resource's render method.)rN   render)r   rK   r<   s      r   rQ   NameVirtualHost.renderY   s!    ++G4||G$$r   c                     U R                  U5      nUR                  (       a7  UR                  R                  SUR                  R                  S5      5        U$ UR                  X5      $ )z6Implementation of resource.Resource's getChild method.r   )rN   isLeafpostpathinsertprepathpopgetChildWithDefault)r   pathrK   r<   s       r   getChildNameVirtualHost.getChild^   sT    ++G4<<##Aw':':2'>?L,,T;;r   r;   )r'   r(   r)   r*   r+   rF   r   r   r   r   r$   rN   rQ   r\   r.   r/   r   r   r1   r1   '   s3    ?G


A!

%
<r   r1   c                       \ rS rSrS rSrg)_HostResourceh   c                    SU;   a   UR                  SS5      u  p4[        U5      nOUSpCUR                  X45        SUR                  5       -   S-   [	        U5      -   [	        UR
                  S   5      -   nSSR                  UR                  5      -   Ul        UR                  US  Ul	        UR
                  S S2	 UR                  R                  U5      $ )NrA   rB   P            /)rI   intsetHostisSecurelenrX   joinrV   r[   urisitegetResourceFor)r   r[   rK   rM   port	prefixLens         r   r\   _HostResource.getChildi   s    4<D!,JDt9Dr$#((**Q.T:SQSAT=UU	dii(8(899kk)*-OOBQB||**733r   r/   N)r'   r(   r)   r*   r\   r.   r/   r   r   r_   r_   h   s    4r   r_   c                       \ rS rSrSrS rSrg)VHostMonsterResourcew   a
  
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                 b    US:X  a  S Ul         [        5       $ US:X  a  S Ul         [        5       $ )Ns   httpc                      g)Nr   r/   r/   r   r   <lambda>/VHostMonsterResource.getChild.<locals>.<lambda>       qr   s   httpsc                      g)NrB   r/   r/   r   r   rw   rx      ry   r   )ri   r_   )r   r[   rK   s      r   r\   VHostMonsterResource.getChild   s5    7?(G  X(Gr   r/   N)r'   r(   r)   r*   r+   r\   r.   r/   r   r   rs   rs   w   s    	r   rs   N)r+   twisted.pythonr   twisted.webr   r   
Homogenousr   r,   r1   r_   rs   r/   r   r   <module>r      s[   
 ! '"E,, "0><h'' ><B4H%% 48,, r   