HEX
Server: Apache
System: Linux scp1.abinfocom.com 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64
User: confeduphaar (1010)
PHP: 8.1.33
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //usr/lib/python3/dist-packages/twisted/names/test/__pycache__/test_cache.cpython-38.pyc
U


W[4�@sjdZddlmZmZddlZddlmZddlmZddl	m
Z
mZddlm
Z
mZGdd	�d	ej�ZdS)
z#
Tests for L{twisted.names.cache}.
�)�division�absolute_importN)�verifyClass)�unittest)�dns�cache)�task�
interfacesc@s@eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dS)�CachingTestsz+
    Tests for L{cache.CacheResolver}.
    cCsttjtj�dS)zK
        L{cache.CacheResolver} implements L{interfaces.IResolver}
        N)rr	Z	IResolverr�
CacheResolver��self�r�?/usr/lib/python3/dist-packages/twisted/names/test/test_cache.py�test_interfaceszCachingTests.test_interfacecCsFt�tjdtjtjd�t��gggffi�}|�d��|j	gggf�S)N�example.com��name�type�cls)
rrr�QueryZMX�IN�timeZlookupMailExchange�addCallback�assertEqual)r
�crrr�test_lookup s�
�zCachingTests.test_lookupcCs�t�dtjtjdt�dd��gt�dtjtjdt�dd��gt�dtjtjdt�dd��gf}t��}tjdtjtjd�}tj	||�
�|fi|d�}|�d�|�||j�|�
|�d�tj�S)z�
        Cache entries passed into L{cache.CacheResolver.__init__} get
        cancelled just like entries added with cacheResult
        r�<�	127.0.0.1�2�(r�Zreactor)r�RRHeader�Ar�Record_Ar�Clockrrr�seconds�advance�assertNotIn�
assertFailure�
lookupAddress�DomainError)r
�r�clock�queryrrrr�test_constructorExpires(s&
�
�
��
�z$CachingTests.test_constructorExpirescs�t�dtjtjdt�dd��gt�dtjtjdt�dd��gt�dtjtjdt�dd��gf}t��}tj|d�}|�	tj
dtjtjd�|�|�d��fd	d
�}|�d��
|�S)z�
        When a cache lookup finds a cached entry from 1 second ago, it is
        returned with a TTL of original TTL minus the elapsed 1 second.
        rrrrr r!r�cs^��|ddjd���|ddjd���|ddjd���|ddjjd�dS)Nr�;r0�1��'r)rZttlr)�resultrrr�cbLookupVsz0CachingTests.test_normalLookup.<locals>.cbLookup)rr"r#rr$rr%rr�cacheResultrr'r*r)r
r,r-rr6rrr�test_normalLookupCs 
�
�
��
zCachingTests.test_normalLookupcCs�t�dtjtjdt�dd��gt�dtjtjdt�dd��gt�dtjtjdt�dd��gf}t��}tj|d�}tj	dtjtjd�}|�
||�|�d�|�||j�|�
|�d�tj�S)zW
        Once the TTL has been exceeded, the result is removed from the cache.
        rrrrr r!r)rr"r#rr$rr%rrrr7r'r(r)r*r+)r
r,r-rr.rrr�test_cachedResultExpires_s(
�
�
��
�z%CachingTests.test_cachedResultExpirescCs�t�dtjtjdt�dd��gt�dtjtjdt�dd��gt�dtjtjdt�dd��gf}t��}dd�|_tj	tj
dtjtjd�|��|fi|d	�}|�d
�|�
|�d�tj�S)z�
        When the cache is queried exactly as the cached entry should expire but
        before it has actually been cleared, the cache does not return the
        expired entry.
        rrrrr c_sdS)Nr)�args�kwargsrrr�<lambda>��z4CachingTests.test_expiredTTLLookup.<locals>.<lambda>rr!g�����N@)rr"r#rr$rr%Z	callLaterrrrr&r'r)r*r+)r
r,r-rrrr�test_expiredTTLLookupxs.
�
�
��

��
�z"CachingTests.test_expiredTTLLookupN)
�__name__�
__module__�__qualname__�__doc__rrr/r8r9r>rrrrr
sr
)rBZ
__future__rrrZzope.interface.verifyrZ
twisted.trialrZ
twisted.namesrrZtwisted.internetrr	ZTestCaser
rrrr�<module>s