ó
[³XMc           @   sí   d  d l  Z  d  d l Z d  d l m Z d  d l m Z m Z y e j Wn e k
 rb d Z	 n Xd Z	 d e f d „  ƒ  YZ d e f d „  ƒ  YZ d	 e j e f d
 „  ƒ  YZ d e j e f d „  ƒ  YZ d e j e f d „  ƒ  YZ d S(   iÿÿÿÿN(   t   unittest(   t   IPv4Addresst   UNIXAddresss"   Platform does not support symlinkst   AddressTestCaseMixinc           B   sG   e  Z d  „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z RS(   c         C   sB   |  j  |  j ƒ  |  j ƒ  k ƒ |  j |  j ƒ  |  j ƒ  k ƒ d S(   s  
        Two different address instances, sharing the same properties are
        considered equal by C{==} and not considered not equal by C{!=}.

        Note: When applied via UNIXAddress class, this uses the same
        filename for both objects being compared.
        N(   t
   assertTruet   buildAddresst   assertFalse(   t   self(    (    sF   /usr/lib/python2.7/dist-packages/twisted/internet/test/test_address.pyt   test_addressComparison   s    c   	   	   C   s÷   |  j  ƒ  } d j d d d d d d g ƒ } | | ƒ } t j | | ƒ } |  j d | d | f ƒ |  j | j j | j	 d	 ƒ ƒ g  | j	 d
 ƒ j
 d ƒ D] } | j ƒ  ^ q } |  j | g  |  j D]$ } | d	 t | | d ƒ f ^ qÈ ƒ d S(   sí   
        Verify that the string representation of an address object conforms to a
        simple pattern (the usual one for Python object reprs) and contains
        values which accurately reflect the attributes of the address.
        t    t   ^s   ([^\(]+Address)s   \(s   ([^)]+)s   \)t   $sI   %s does not match the standard __str__ pattern ClassName(arg1, arg2, etc)i   i   t   ,i    N(   R   t   joint   ret   matcht   assertNotEqualst   Nonet   assertEqualst	   __class__t   __name__t   groupt   splitt   stript   addressArgSpect   getattr(	   R   t   stringFunctiont   addrt   patternt   stringValuet   mt   xt   argst   argSpec(    (    sF   /usr/lib/python2.7/dist-packages/twisted/internet/test/test_address.pyt   _stringRepresentation   s&    1c         C   s   |  j  t ƒ d S(   s   
        C{str} can be used to get a string representation of an address instance
        containing information about that address.
        N(   R"   t   str(   R   (    (    sF   /usr/lib/python2.7/dist-packages/twisted/internet/test/test_address.pyt   test_str<   s    c         C   s   |  j  t ƒ d S(   sŽ   
        C{repr} can be used to get a string representation of an address
        instance containing information about that address.
        N(   R"   t   repr(   R   (    (    sF   /usr/lib/python2.7/dist-packages/twisted/internet/test/test_address.pyt	   test_reprD   s    c         C   s4   |  j  ƒ  } i t | 6} |  j | |  j  ƒ  ƒ d S(   s“   
        C{__hash__} can be used to get a hash of an address, allowing
        addresses to be used as keys in dictionaries, for instance.
        N(   R   t   TrueR   (   R   R   t   d(    (    sF   /usr/lib/python2.7/dist-packages/twisted/internet/test/test_address.pyt	   test_hashL   s    c         C   sB   |  j  |  j ƒ  |  j ƒ  k ƒ |  j |  j ƒ  |  j ƒ  k ƒ d S(   s~   
        Check that comparison operators work correctly on address objects
        when a different name is passed in
        N(   R   R   t   buildDifferentAddressR   (   R   (    (    sF   /usr/lib/python2.7/dist-packages/twisted/internet/test/test_address.pyt   test_differentNamesComparisonV   s    c         C   s\   |  j  | g ƒ } |  j | d d t ƒ |  j | d d | ƒ |  j t | ƒ d ƒ d S(   s{   
        Assert that the a DeprecationWarning with the given message was
        emitted against the given method.
        i    t   categoryt   messagei   N(   t   flushWarningsR   t   DeprecationWarningt   len(   R   t
   testMethodR-   t   warnings(    (    sF   /usr/lib/python2.7/dist-packages/twisted/internet/test/test_address.pyt   assertDeprecations_   s    (	   R   t
   __module__R   R"   R$   R&   R)   R+   R3   (    (    (    sF   /usr/lib/python2.7/dist-packages/twisted/internet/test/test_address.pyR      s   					
		t   IPv4AddressTestCaseMixinc           B   s   e  Z d d d f Z RS(	   t   types   %st   hosts   %rt   ports   %d(   s   types   %s(   s   hosts   %r(   R8   s   %d(   R   R4   R   (    (    (    sF   /usr/lib/python2.7/dist-packages/twisted/internet/test/test_address.pyR5   k   s   t   IPv4AddressTCPTestCasec           B   s#   e  Z d  „  Z d „  Z d „  Z RS(   c         C   s   t  d d d ƒ S(   s²   
        Create an arbitrary new L{IPv4Address} instance with a C{"TCP"}
        type.  A new instance is created for each call, but always for the
        same address.
        t   TCPs	   127.0.0.1i    (   R   (   R   (    (    sF   /usr/lib/python2.7/dist-packages/twisted/internet/test/test_address.pyR   q   s    c         C   s   t  d d d ƒ S(   sK   
        Like L{buildAddress}, but with a different fixed address.
        R:   s	   127.0.0.2i    (   R   (   R   (    (    sF   /usr/lib/python2.7/dist-packages/twisted/internet/test/test_address.pyR*   z   s    c         C   s1   d } t  d d d d d ƒ} |  j |  j | ƒ S(   s€   
        If a value is passed for the C{_bwHack} parameter to L{IPv4Address},
        a deprecation warning is emitted.
        sM   twisted.internet.address.IPv4Address._bwHack is deprecated since Twisted 11.0R:   s	   127.0.0.3i    t   _bwHack(   R   R3   t   test_bwHackDeprecation(   R   R-   t   address(    (    sF   /usr/lib/python2.7/dist-packages/twisted/internet/test/test_address.pyR<      s    (   R   R4   R   R*   R<   (    (    (    sF   /usr/lib/python2.7/dist-packages/twisted/internet/test/test_address.pyR9   p   s   			t   IPv4AddressUDPTestCasec           B   s#   e  Z d  „  Z d „  Z d „  Z RS(   c         C   s   t  d d d ƒ S(   s²   
        Create an arbitrary new L{IPv4Address} instance with a C{"UDP"}
        type.  A new instance is created for each call, but always for the
        same address.
        t   UDPs	   127.0.0.1i    (   R   (   R   (    (    sF   /usr/lib/python2.7/dist-packages/twisted/internet/test/test_address.pyR      s    c         C   s   t  d d d ƒ S(   sK   
        Like L{buildAddress}, but with a different fixed address.
        R?   s	   127.0.0.2i    (   R   (   R   (    (    sF   /usr/lib/python2.7/dist-packages/twisted/internet/test/test_address.pyR*   ˜   s    c         C   s1   d } t  d d d d d ƒ} |  j |  j | ƒ S(   s€   
        If a value is passed for the C{_bwHack} parameter to L{IPv4Address},
        a deprecation warning is emitted.
        sM   twisted.internet.address.IPv4Address._bwHack is deprecated since Twisted 11.0R?   s	   127.0.0.3i    R;   (   R   R3   R<   (   R   R-   R=   (    (    sF   /usr/lib/python2.7/dist-packages/twisted/internet/test/test_address.pyR<   Ÿ   s    (   R   R4   R   R*   R<   (    (    (    sF   /usr/lib/python2.7/dist-packages/twisted/internet/test/test_address.pyR>   Ž   s   			t   UNIXAddressTestCasec           B   sV   e  Z d	 Z d „  Z d „  Z d „  Z d „  Z e e _ d „  Z	 e e	 _ d „  Z
 RS(
   t   names   %rc         C   s"   |  j  ƒ  |  _ |  j  ƒ  |  _ d  S(   N(   t   mktempt   _socketAddresst   _otherAddress(   R   (    (    sF   /usr/lib/python2.7/dist-packages/twisted/internet/test/test_address.pyt   setUp¯   s    c         C   s   t  |  j ƒ S(   s•   
        Create an arbitrary new L{UNIXAddress} instance.  A new instance is
        created for each call, but always for the same address.
        (   R   RC   (   R   (    (    sF   /usr/lib/python2.7/dist-packages/twisted/internet/test/test_address.pyR   ´   s    c         C   s   t  |  j ƒ S(   sK   
        Like L{buildAddress}, but with a different fixed address.
        (   R   RD   (   R   (    (    sF   /usr/lib/python2.7/dist-packages/twisted/internet/test/test_address.pyR*   ¼   s    c         C   sf   |  j  ƒ  } t |  j d ƒ |  _ t j t j j |  j ƒ | ƒ |  j t	 |  j ƒ t	 | ƒ k ƒ d S(   sU   
        UNIXAddress objects compare as equal if they link to the same file.
        t   wN(
   RB   t   openRC   t   fdt   ost   symlinkt   patht   abspathR   R   (   R   t   linkName(    (    sF   /usr/lib/python2.7/dist-packages/twisted/internet/test/test_address.pyt   test_comparisonOfLinkedFilesÃ   s
    c         C   so   |  j  ƒ  } t |  j d ƒ |  _ t j t j j |  j ƒ | ƒ |  j t	 t
 |  j ƒ ƒ t	 t
 | ƒ ƒ ƒ d S(   sU   
        UNIXAddress Objects that compare as equal have the same hash value.
        RF   N(   RB   RG   RC   RH   RI   RJ   RK   RL   R   t   hashR   (   R   RM   (    (    sF   /usr/lib/python2.7/dist-packages/twisted/internet/test/test_address.pyt   test_hashOfLinkedFilesÏ   s
    c         C   s1   d } t  |  j ƒ  d d ƒ} |  j |  j | ƒ S(   s€   
        If a value is passed for the C{_bwHack} parameter to L{UNIXAddress},
        a deprecation warning is emitted.
        sM   twisted.internet.address.UNIXAddress._bwHack is deprecated since Twisted 11.0R;   t   UNIX(   R   RB   R3   R<   (   R   R-   R=   (    (    sF   /usr/lib/python2.7/dist-packages/twisted/internet/test/test_address.pyR<   Û   s    (   s   names   %r(   (   s   names   %r(   R   R4   R   RE   R   R*   RN   t   symlinkSkipt   skipRP   R<   (    (    (    sF   /usr/lib/python2.7/dist-packages/twisted/internet/test/test_address.pyR@   ¬   s   									(   R   RI   t   twisted.trialR    t   twisted.internet.addressR   R   RJ   t   AttributeErrorRR   R   t   objectR   R5   t   TestCaseR9   R>   R@   (    (    (    sF   /usr/lib/python2.7/dist-packages/twisted/internet/test/test_address.pyt   <module>   s   
Y