Ë
    ojÍ  ã                   ór   — d Z ddlZddlmZ ddlmZmZ ddlmZm	Z	 ddl
mZ  G d„ dej                  «      Zy)	z#
Tests for L{twisted.names.cache}.
é    N)ÚverifyClass)Ú
interfacesÚtask)ÚcacheÚdns)Úunittestc                   ó4   — e Zd ZdZd„ Zd„ Zd„ Zd„ Zd„ Zd„ Z	y)	ÚCachingTestsz+
    Tests for L{cache.CacheResolver}.
    c                 óT   — t        t        j                  t        j                  «       y)zK
        L{cache.CacheResolver} implements L{interfaces.IResolver}
        N)r   r   Ú	IResolverr   ÚCacheResolver)Úselfs    ú?/usr/lib/python3/dist-packages/twisted/names/test/test_cache.pyÚtest_interfacezCachingTests.test_interface   s   € ô 	”J×(Ñ(¬%×*=Ñ*=Õ>ó    c                 ó  — t        j                  t        j                  dt        j                  t        j
                  ¬«      t        j                  «       g g g ffi«      }|j                  d«      j                  | j                  g g g f«      S )Nó   example.com©ÚnameÚtypeÚcls)
r   r   r   ÚQueryÚMXÚINÚtimeÚlookupMailExchangeÚaddCallbackÚassertEqual)r   Úcs     r   Útest_lookupzCachingTests.test_lookup   sx   € Ü×Ñä—	‘	˜~´C·F±FÄÇÁÔGÜ—I‘I“KØ˜˜R�LðJðó
ˆð ×#Ñ# NÓ3×?Ñ?Ø×Ñ˜r 2 r˜ló
ð 	
r   c                 óV  — t        j                  dt         j                  t         j                  dt        j                  dd«      «      gt        j                  dt         j                  t         j                  dt        j                  dd«      «      gt        j                  dt         j                  t         j                  dt        j                  dd«      «      gf}t        j                  «       }t        j                  dt         j                  t         j                  ¬«      }t        j                  ||j                  «       |fi|¬«      }|j                  d«       | j                  ||j                  «       | j                  |j                  d«      t         j                  «      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   ©Úreactor)r   ÚRRHeaderÚAr   ÚRecord_Ar   ÚClockr   r   r   ÚsecondsÚadvanceÚassertNotInÚassertFailureÚlookupAddressÚDomainError)r   ÚrÚclockÚqueryr   s        r   Útest_constructorExpiresz$CachingTests.test_constructorExpires*   s*  € ô —‘Ø"¤C§E¡E¬3¯6©6°2´s·|±|ÀKÐQSÓ7Tóðô —‘Ø"¤C§E¡E¬3¯6©6°2´s·|±|ÀKÐQSÓ7Tóðô —‘Ø"¤C§E¡E¬3¯6©6°2´s·|±|ÀKÐQSÓ7Tóðð
ˆô$ —
‘
“ˆÜ—	‘	˜~´C·E±E¼s¿v¹vÔFˆä×Ñ ¨¯©«¸!Ð(<Ð =ÀuÔMˆð 	�‰�bÔà×Ñ˜ §¡Ô(à×!Ñ! !§/¡/°.Ó"AÄ3Ç?Á?ÓSÐSr   c                 ó  ‡ — t        j                  dt         j                  t         j                  dt        j                  dd«      «      gt        j                  dt         j                  t         j                  dt        j                  dd«      «      gt        j                  dt         j                  t         j                  dt        j                  dd«      «      gf}t        j                  «       }t        j                  |¬«      }|j                  t        j                  dt         j                  t         j                  ¬«      |«       |j                  d«       ˆ fd	„}|j                  d«      j                  |«      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.
        r   r"   r#   r$   r%   r&   r   é   c                 ó*  •— ‰j                  | d   d   j                  d«       ‰j                  | d   d   j                  d«       ‰j                  | d   d   j                  d«       ‰j                  | d   d   j                  j                  d«       y )Nr   é;   r7   é1   é   é'   r   )r   Úttlr   )Úresultr   s    €r   ÚcbLookupz0CachingTests.test_normalLookup.<locals>.cbLookupl   s�   ø€ Ø×Ñ˜V A™Y q™\×-Ñ-¨rÔ2Ø×Ñ˜V A™Y q™\×-Ñ-¨rÔ2Ø×Ñ˜V A™Y q™\×-Ñ-¨rÔ2Ø×Ñ˜V A™Y q™\×.Ñ.×3Ñ3°^ÕDr   )r   r(   r)   r   r*   r   r+   r   r   ÚcacheResultr   r-   r0   r   )r   r2   r3   r   r?   s   `    r   Útest_normalLookupzCachingTests.test_normalLookupN   s  ø€ ô —‘Ø"¤C§E¡E¬3¯6©6°2´s·|±|ÀKÐQSÓ7Tóðô —‘Ø"¤C§E¡E¬3¯6©6°2´s·|±|ÀKÐQSÓ7Tóðô —‘Ø"¤C§E¡E¬3¯6©6°2´s·|±|ÀKÐQSÓ7Tóðð
ˆô$ —
‘
“ˆä×Ñ¨Ô.ˆØ	�‰”c—i‘i ^¼#¿%¹%ÄSÇVÁVÔLÈaÔPà�‰�aÔô	Eð �‰˜~Ó.×:Ñ:¸8ÓDÐDr   c                 óT  — t        j                  dt         j                  t         j                  dt        j                  dd«      «      gt        j                  dt         j                  t         j                  dt        j                  dd«      «      gt        j                  dt         j                  t         j                  dt        j                  dd«      «      gf}t        j                  «       }t        j                  |¬«      }t        j                  dt         j                  t         j                  ¬«      }|j                  ||«       |j                  d«       | j                  ||j                  «       | j                  |j                  d«      t         j                  «      S )zW
        Once the TTL has been exceeded, the result is removed from the cache.
        r   r"   r#   r$   r%   r&   r   )r   r(   r)   r   r*   r   r+   r   r   r   r@   r-   r.   r/   r0   r1   )r   r2   r3   r   r4   s        r   Útest_cachedResultExpiresz%CachingTests.test_cachedResultExpirest   s$  € ô —‘Ø"¤C§E¡E¬3¯6©6°2´s·|±|ÀKÐQSÓ7Tóðô —‘Ø"¤C§E¡E¬3¯6©6°2´s·|±|ÀKÐQSÓ7Tóðô —‘Ø"¤C§E¡E¬3¯6©6°2´s·|±|ÀKÐQSÓ7Tóðð
ˆô$ —
‘
“ˆä×Ñ¨Ô.ˆÜ—	‘	˜~´C·E±E¼s¿v¹vÔFˆØ	�‰�e˜QÔà�‰�bÔà×Ñ˜ §¡Ô(à×!Ñ! !§/¡/°.Ó"AÄ3Ç?Á?ÓSÐSr   c                 ó*  — t        j                  dt         j                  t         j                  dt        j                  dd«      «      gt        j                  dt         j                  t         j                  dt        j                  dd«      «      gt        j                  dt         j                  t         j                  dt        j                  dd«      «      gf}t        j                  «       }d„ |_        t        j                  t        j                  dt         j                  t         j                  ¬«      |j                  «       |fi|¬«      }|j                  d	«       | j                  |j                  d«      t         j                  «      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.
        r   r"   r#   r$   r%   c                   ó   — y )N© )ÚargsÚkwargss     r   ú<lambda>z4CachingTests.test_expiredTTLLookup.<locals>.<lambda>°   s   � r   r   r&   gÍÌÌÌÌN@)r   r(   r)   r   r*   r   r+   Ú	callLaterr   r   r   r,   r-   r/   r0   r1   )r   r2   r3   r   s       r   Útest_expiredTTLLookupz"CachingTests.test_expiredTTLLookup–   s%  € ô —‘Ø"¤C§E¡E¬3¯6©6°2´s·|±|ÀKÐQSÓ7Tóðô —‘Ø"¤C§E¡E¬3¯6©6°2´s·|±|ÀKÐQSÓ7Tóðô —‘Ø"¤C§E¡E¬3¯6©6°2´s·|±|ÀKÐQSÓ7Tóðð
ˆô$ —
‘
“ˆá6ˆŒä×Ñä—	‘	˜~´C·E±E¼s¿v¹vÔFØ—M‘M“OØðIðð ô
ˆð 	�‰�dÔà×!Ñ! !§/¡/°.Ó"AÄ3Ç?Á?ÓSÐSr   N)
Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r    r5   rA   rC   rK   rF   r   r   r
   r
      s,   „ ñò?ò
ò"TòH$EòL TóD(Tr   r
   )rO   r   Úzope.interface.verifyr   Útwisted.internetr   r   Útwisted.namesr   r   Útwisted.trialr   ÚTestCaser
   rF   r   r   ú<module>rU      s1   ðñó
 å -ç -ß $Ý "ôlT�8×$Ñ$õ lTr   