Your IP : 216.73.217.152


Current Path : /opt/alt/python37/lib64/python3.7/site-packages/twisted/names/__pycache__/
Upload File :
Current File : //opt/alt/python37/lib64/python3.7/site-packages/twisted/names/__pycache__/cache.cpython-37.pyc

B

:��]��@sVdZddlmZmZddlmZmZddlmZm	Z	ddl
mZGdd�dej�Z
dS)	z 
An in-memory caching resolver.
�)�division�absolute_import)�dns�common)�failure�log)�deferc@sReZdZdZdZddd�Zdd�Zdd	�Zd
d�Zddd
�Z	ddd�Z
dd�ZdS)�
CacheResolverz�
    A resolver that serves records from a local, memory cache.

    @ivar _reactor: A provider of L{interfaces.IReactorTime}.
    NrcCshtj�|�i|_||_i|_|dkr2ddlm}||_|rdx&|�	�D]\}\}}|�
|||�qFWdS)Nr)�reactor)r�ResolverBase�__init__�cache�verbose�cancel�twisted.internetr
�_reactor�items�cacheResult)�selfr
rr
�query�seconds�payload�r�F/opt/alt/python37/lib64/python3.7/site-packages/twisted/names/cache.pyrszCacheResolver.__init__c
Csh||_|j��}xR|j��D]D\}\}\}}}||}x(|||D]}	|	j|krD|j|=PqDWqWdS)N)�__dict__rrr
r�ttl)
r�state�now�k�when�ans�add�ns�diffZrecrrr�__setstate__(s

zCacheResolver.__setstate__cCs,x|j��D]}|��qW|j��|jS)N)r�values�clearr)r�crrr�__getstate__4s
zCacheResolver.__getstate__c
s|j��}t�|||�}y|j|\}\}}	}
WnBtk
rr|jdkr\t�dt	|��t
�t�
t�|���SX|jr�t�dt	|��||�y8�fdd�|D��fdd�|	D��fdd�|
D�f}Wn&tk
r�t
�t�
t�|���SXt
�|�SdS)N�zCache miss for zCache hit for c	s.g|]&}t�|jj|j|j|j�|j��qSr)r�RRHeader�name�type�clsrr)�.0�r)r#rr�
<listcomp>Ksz)CacheResolver._lookup.<locals>.<listcomp>c	s.g|]&}t�|jj|j|j|j�|j��qSr)rr*r+r,r-rr)r.r/)r#rrr0Msc	s.g|]&}t�|jj|j|j|j�|j��qSr)rr*r+r,r-rr)r.r/)r#rrr0Os)rrrZQueryr
�KeyErrorrr�msg�reprr�failr�Failure�DomainError�
ValueErrorZsucceed)rr+r-r,�timeoutr�qrr Zauthr!�resultr)r#r�_lookup;s*




zCacheResolver._lookupcCst�t�t�|���S)N)rr4rr5rr6)rr+r8rrr�lookupAllRecordsWszCacheResolver.lookupAllRecordscCs�|jdkrt�d|�|p$|j��|f|j|<||jkrH|j|��t|d�t|d�t|d�}|r�|dj}x|D]}t	||j�}q�Wnd}|j�
||j|�|j|<dS)a�
        Cache a DNS entry.

        @param query: a L{dns.Query} instance.

        @param payload: a 3-tuple of lists of L{dns.RRHeader} records, the
            matching result of the query (answers, authority and additional).

        @param cacheTime: The time (seconds since epoch) at which the entry is
            considered to have been added to the cache. If L{None} is given,
            the current time is used.
        r)zAdding %r to cacher�N)rrr2rrr
r�listr�minZ	callLater�
clearEntry)rrrZ	cacheTime�s�mr/rrrr[s

$

zCacheResolver.cacheResultcCs|j|=|j|=dS)N)r
r)rrrrrr@{szCacheResolver.clearEntry)NrN)N)N)�__name__�
__module__�__qualname__�__doc__r
rr$r(r;r<rr@rrrrr	s


 r	N)rF�
__future__rrZ
twisted.namesrrZtwisted.pythonrrrrrr	rrrr�<module>s