U
    
W[<  ã                   @   s2   d dl mZ G dd„ dejƒZdd„ Zdd„ ZdS )	é    )Úresourcec                   @   s,   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	S )
ÚRewriterResourcec                 G   s    t j | ¡ || _ t|ƒ| _d S ©N)r   ÚResourceÚ__init__ÚlistÚrewriteRules)ÚselfZorigr   © r
   ú5/usr/lib/python3/dist-packages/twisted/web/rewrite.pyr   	   s    zRewriterResource.__init__c                 C   s   | j D ]}||ƒ qd S r   )r   )r	   ÚrequestZrewriteRuler
   r
   r   Ú_rewrite   s    
zRewriterResource._rewritec                 C   sH   |j  d|¡ |j ¡  |  |¡ |j  d¡}|j |¡ | j ||¡S )Nr   )ÚpostpathÚinsertÚprepathÚpopr   Úappendr   ZgetChildWithDefault)r	   Úpathr   r
   r
   r   ÚgetChild   s    

zRewriterResource.getChildc                 C   s   |   |¡ | j |¡S r   )r   r   Úrender)r	   r   r
   r
   r   r      s    
zRewriterResource.renderN)Ú__name__Ú
__module__Ú__qualname__r   r   r   r   r
   r
   r
   r   r      s   r   c                 C   sX   | j rT| j d d d… dkrTd| j d dd … g| j d d…< dd | j| j  ¡ | _d S )Nr   é   ú~Zusersú/)r   Újoinr   r   )r   r
   r
   r   ÚtildeToUsers   s     r   c                    s&   ˆ  d¡‰ˆ   d¡‰ ‡ ‡fdd„}|S )a•  
    I am not a very good aliaser. But I'm the best I can be. If I'm
    aliasing to a Resource that generates links, and it uses any parts
    of request.prepath to do so, the links will not be relative to the
    aliased path, but rather to the aliased-to path. That I can't
    alias static.File directory listings that nicely. However, I can
    still be useful, as many resources will play nice.
    r   c                    sN   | j d tˆ ƒ… ˆ krJ| j tˆ ƒd … }ˆ| | _ dd | j| j  ¡ | _d S )Nr   )r   Úlenr   r   r   )r   Zafter©Ú	aliasPathÚ
sourcePathr
   r   Úrewriter/   s    
zalias.<locals>.rewriter)Úsplit)r    r!   r"   r
   r   r   Úalias$   s    	

r$   N)Ztwisted.webr   r   r   r   r$   r
   r
   r
   r   Ú<module>   s   