o
    ¯bK  ã                   @   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)ÚselfÚ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	   ÚrequestÚrewriteRuler   r   r   Ú_rewrite   s   

ÿzRewriterResource._rewritec                 C   sH   |j  d|¡ |j ¡  |  |¡ |j  d¡}|j |¡ | j ||¡S )Nr   )ÚpostpathÚinsertÚprepathÚpopr   Úappendr   Ú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   s`   | j r,| j d d d… dkr.d| j d dd … g| j d d…< dd | j| j  ¡ | _d S d S d S )Nr   é   ú~Ú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                    sR   | j d tˆ ƒ… ˆ kr'| j tˆ ƒd … }ˆ| | _ dd | j| j  ¡ | _d S d S )Nr   )r   Úlenr    r   r   )r   Úafter©Ú	aliasPathÚ
sourcePathr   r   Úrewriter1   s
   
ýzalias.<locals>.rewriter)Úsplit)r%   r&   r'   r   r$   r   Úalias%   s   
	
r)   N)Útwisted.webr   r   r   r!   r)   r   r   r   r   Ú<module>   s   