B
    u9aˆi ã               @   s~  d dl Z d dlZd dlZd dlZd dlZd dlZd dlZd dlZG dd„ de jƒZ	G dd„ dƒZ
G dd„ de
ƒZG dd	„ d	e
ƒZG d
d„ de	eƒZG dd„ de	eƒZG dd„ deƒZG dd„ de	eƒZG dd„ de	eƒZG dd„ deƒZG dd„ de	eƒZG dd„ de	eƒZG dd„ de	ƒZejG dd„ dƒƒZejG dd„ dƒƒZG d d!„ d!e jƒZG d"d#„ d#e jƒZed$krze  ¡  dS )%é    Nc               @   s>   e Zd Zedd„ ƒZejdd„ ƒZdd„ Zdd„ Z	d	d
„ Z
dS )ÚBaseTestCasec             C   s   t ‚d S )N)ÚNotImplementedError)Úself© r   ú$/usr/lib/python3.7/test_ipaddress.pyÚfactory$   s    zBaseTestCase.factoryc          	   g   sL   |r|| }|   ||¡}|}|V  W d Q R X |jjd k	rH|  |jj¡ d S )N)ÚassertRaisesRegexZ	exceptionÚ__context__Ú
assertTrueÚ__suppress_context__)r   Úexc_typeÚdetailsÚargsÚcmÚexcr   r   r   ÚassertCleanError(   s    zBaseTestCase.assertCleanErrorc             G   s   | j tj|f|žŽ S )N)r   Ú	ipaddressÚAddressValueError)r   r   r   r   r   r   ÚassertAddressError8   s    zBaseTestCase.assertAddressErrorc             G   s   | j tj|f|žŽ S )N)r   r   ZNetmaskValueError)r   r   r   r   r   r   ÚassertNetmaskError=   s    zBaseTestCase.assertNetmaskErrorc             C   s   |   |  |¡|  |¡¡ d S )N)ÚassertEqualr   )r   ÚlhsÚrhsr   r   r   ÚassertInstancesEqualB   s    z!BaseTestCase.assertInstancesEqualN)Ú__name__Ú
__module__Ú__qualname__Úpropertyr   Ú
contextlibÚcontextmanagerr   r   r   r   r   r   r   r   r      s
   r   c               @   s,   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	S )
ÚCommonTestMixinc          	   C   s$   |   d¡ |  d¡ W d Q R X d S )NzAddress cannot be emptyÚ )r   r   )r   r   r   r   Útest_empty_addressI   s    z"CommonTestMixin.test_empty_addressc          	   C   s.   |   t tdƒ¡¡ |  d¡ W d Q R X d S )Nz1.0g      ð?)r   ÚreÚescapeÚreprr   )r   r   r   r   Útest_floats_rejectedM   s    z$CommonTestMixin.test_floats_rejectedc             C   sB   |   ttj|  d¡¡ |   tt|  d¡¡ |   tt|  d¡¡ d S )Né   )ÚassertRaisesÚ	TypeErrorÚoperatorÚindexr   ÚhexÚbytes)r   r   r   r   Útest_not_an_index_issue15559Q   s    z,CommonTestMixin.test_not_an_index_issue15559c          
   C   s\   xVt tjd ƒD ]D}| j|d. |  |¡}t t ||¡¡}|  ||¡ W d Q R X qW d S )Nr'   )Úproto)ÚrangeÚpickleZHIGHEST_PROTOCOLZsubTestr   ÚloadsÚdumpsr   )r   Úaddrr/   ÚxÚyr   r   r   Úpickle_testX   s
    
zCommonTestMixin.pickle_testN)r   r   r   r"   r&   r.   r7   r   r   r   r   r    G   s   r    c               @   s<   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ Zdd„ ZdS )ÚCommonTestMixin_v4c             C   s   |   dd¡ |   dd¡ d S )Nz000.000.000.000z0.0.0.0z192.168.000.001z192.168.0.1)r   )r   r   r   r   Útest_leading_zerosa   s    z%CommonTestMixin_v4.test_leading_zerosc             C   s   |   dd¡ |   dd¡ d S )Nr   z0.0.0.0l    P z192.168.0.1)r   )r   r   r   r   Útest_inte   s    zCommonTestMixin_v4.test_intc             C   s(   |   t d¡d¡ |   t d¡d¡ d S )NÚ00000000z0.0.0.0Úc0a80001z192.168.0.1)r   r-   Úfromhex)r   r   r   r   Útest_packedi   s    zCommonTestMixin_v4.test_packedc          	   C   s.   d}|   t |¡¡ |  d¡ W d Q R X d S )Nz,-1 (< 0) is not permitted as an IPv4 addresséÿÿÿÿ)r   r#   r$   r   )r   Úmsgr   r   r   Útest_negative_ints_rejectedm   s    z.CommonTestMixin_v4.test_negative_ints_rejectedc          	   C   s2   d}|   t |d ¡¡ |  d¡ W d Q R X d S )Nz1%d (>= 2**32) is not permitted as an IPv4 addressl        )r   r#   r$   r   )r   r@   r   r   r   Útest_large_ints_rejectedr   s    z+CommonTestMixin_v4.test_large_ints_rejectedc                s    ‡ fdd„}|dƒ |dƒ d S )Nc          	      s>   d|  }d}ˆ   t ||| f ¡¡ ˆ  |¡ W d Q R X d S )Nó    z4%r (len %d != 4) is not permitted as an IPv4 address)r   r#   r$   r   )Úlengthr4   r@   )r   r   r   ÚassertBadLengthx   s    zBCommonTestMixin_v4.test_bad_packed_length.<locals>.assertBadLengthé   é   r   )r   rE   r   )r   r   Útest_bad_packed_lengthw   s    z)CommonTestMixin_v4.test_bad_packed_lengthN)	r   r   r   r9   r:   r>   rA   rB   rH   r   r   r   r   r8   _   s   r8   c               @   s<   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ Zdd„ ZdS )ÚCommonTestMixin_v6c             C   s   |   dd¡ |   dd¡ d S )Nz
0000::0000z::z000::c0a8:0001z::c0a8:1)r   )r   r   r   r   r9   „   s    z%CommonTestMixin_v6.test_leading_zerosc             C   s   |   dd¡ |   dd¡ d S )Nr   z::l    P z::c0a8:1)r   )r   r   r   r   r:   ˆ   s    zCommonTestMixin_v6.test_intc             C   sR   dt  d¡ }|  |d¡ dt  d¡ }|  |d¡ t  d¡d }|  |d¡ d S )Ns               r;   z::r<   z::c0a8:1zc0a8:1::)r-   r=   r   )r   r4   r   r   r   r>   Œ   s    zCommonTestMixin_v6.test_packedc          	   C   s.   d}|   t |¡¡ |  d¡ W d Q R X d S )Nz,-1 (< 0) is not permitted as an IPv6 addressr?   )r   r#   r$   r   )r   r@   r   r   r   rA   ”   s    z.CommonTestMixin_v6.test_negative_ints_rejectedc          	   C   s:   d}|   t |dd  ¡¡ |  dd ¡ W d Q R X d S )Nz2%d (>= 2**128) is not permitted as an IPv6 addressé   é€   )r   r#   r$   r   )r   r@   r   r   r   rB   ™   s    z+CommonTestMixin_v6.test_large_ints_rejectedc                s    ‡ fdd„}|dƒ |dƒ d S )Nc          	      sH   d|  }d}ˆ   t ||| f ¡¡ ˆ  |¡ ˆ  |¡ W d Q R X d S )NrC   z5%r (len %d != 16) is not permitted as an IPv6 address)r   r#   r$   r   )rD   r4   r@   )r   r   r   rE   Ÿ   s
    
zBCommonTestMixin_v6.test_bad_packed_length.<locals>.assertBadLengthé   é   r   )r   rE   r   )r   r   rH   ž   s    z)CommonTestMixin_v6.test_bad_packed_lengthN)	r   r   r   r9   r:   r>   rA   rB   rH   r   r   r   r   rI   ‚   s   rI   c               @   sZ   e Zd ZejZdd„ Zdd„ Zdd„ Zdd„ Z	d	d
„ Z
dd„ Zdd„ Zdd„ Zdd„ ZdS )ÚAddressTestCase_v4c          	   C   s*   d}|   d|¡ t |¡ W d Q R X d S )Nz127.0.0.1/24zUnexpected '/' in %r)r   r   ÚIPv4Address)r   r4   r   r   r   Útest_network_passed_as_address­   s    z1AddressTestCase_v4.test_network_passed_as_addressc                sÈ   ‡ fdd„}|dƒ |dƒ |dƒ |dƒ |dƒ |dƒ |d	ƒ |d
ƒ |dƒ |dƒ |dƒ |dƒ |dƒ |dƒ |dƒ |dƒ |dƒ |dƒ |dƒ |dƒ |dƒ |dƒ |dƒ d S )Nc          	      s&   ˆ   d| ¡ t | ¡ W d Q R X d S )NzExpected 4 octets in %r)r   r   rO   )r4   )r   r   r   ÚassertBadSplit³   s    zAAddressTestCase_v4.test_bad_address_split.<locals>.assertBadSplitz127.0.1z42.42.42.42.42z42.42.42z42.42Z42z42..42.42.42z42.42.42.42.z42.42.42.42...z.42.42.42.42z...42.42.42.42z016.016.016z016.016Ú016Z000z0x0a.0x0a.0x0az	0x0a.0x0aÚ0x0aÚ.Úbogusz	bogus.comZ1000Z1000000000000000z192.168.0.1.comr   )r   rQ   r   )r   r   Útest_bad_address_split²   s0    z)AddressTestCase_v4.test_bad_address_splitc                s    ‡ fdd„}|dƒ |dƒ d S )Nc          	      s&   ˆ   d| ¡ t | ¡ W d Q R X d S )NzEmpty octet not permitted in %r)r   r   rO   )r4   )r   r   r   ÚassertBadOctetÐ   s    z;AddressTestCase_v4.test_empty_octet.<locals>.assertBadOctetz	42..42.42z...r   )r   rW   r   )r   r   Útest_empty_octetÏ   s    z#AddressTestCase_v4.test_empty_octetc                sj   ‡ fdd„}|ddƒ |ddƒ |ddƒ |d	d
ƒ |ddƒ |ddƒ |ddƒ |ddƒ |ddƒ d S )Nc          	      s6   d|| f }ˆ   t |¡¡ t | ¡ W d Q R X d S )Nz)Only decimal digits permitted in %r in %r)r   r#   r$   r   rO   )r4   Úoctetr@   )r   r   r   rW   Ù   s    zBAddressTestCase_v4.test_invalid_characters.<locals>.assertBadOctetz0x0a.0x0a.0x0a.0x0arS   z0xa.0x0a.0x0a.0x0aZ0xaz42.42.42.-0z-0z42.42.42.+0z+0z42.42.42.-42z-42z
+1.+2.+3.4z+1z	1.2.3.4e0Z4e0z	1.2.3.4::z4::z1.a.2.3Úar   )r   rW   r   )r   r   Útest_invalid_charactersØ   s    







z*AddressTestCase_v4.test_invalid_charactersc                s$   ‡ fdd„}|ddƒ |ddƒ d S )Nc          	      s6   d}ˆ   t ||| f ¡¡ t | ¡ W d Q R X d S )Nz9Ambiguous (octal/decimal) value in %r not permitted in %r)r   r#   r$   r   rO   )r4   rY   r@   )r   r   r   rW   é   s    zGAddressTestCase_v4.test_octal_decimal_ambiguity.<locals>.assertBadOctetz016.016.016.016rR   z001.000.008.016Z008r   )r   rW   r   )r   r   Útest_octal_decimal_ambiguityè   s    
z/AddressTestCase_v4.test_octal_decimal_ambiguityc                s$   ‡ fdd„}|ddƒ |ddƒ d S )Nc          	      s6   d}ˆ   t ||| f ¡¡ t | ¡ W d Q R X d S )Nz*At most 3 characters permitted in %r in %r)r   r#   r$   r   rO   )r4   rY   r@   )r   r   r   rW   ò   s    z<AddressTestCase_v4.test_octet_length.<locals>.assertBadOctetz0000.000.000.000Z0000z12345.67899.-54321.-98765Z12345r   )r   rW   r   )r   r   Útest_octet_lengthñ   s    
z$AddressTestCase_v4.test_octet_lengthc                s$   ‡ fdd„}|ddƒ |ddƒ d S )Nc          	      s6   d|| f }ˆ   t |¡¡ t | ¡ W d Q R X d S )Nz$Octet %d (> 255) not permitted in %r)r   r#   r$   r   rO   )r4   rY   r@   )r   r   r   rW   û   s    z;AddressTestCase_v4.test_octet_limit.<locals>.assertBadOctetz	257.0.0.0i  z192.168.0.999iç  r   )r   rW   r   )r   r   Útest_octet_limitú   s    
z#AddressTestCase_v4.test_octet_limitc             C   s   |   d¡ d S )Nz	192.0.2.1)r7   )r   r   r   r   Útest_pickle  s    zAddressTestCase_v4.test_picklec             C   s   t  |  d¡¡ d S )Nz	192.0.2.1)ÚweakrefÚrefr   )r   r   r   r   Útest_weakref  s    zAddressTestCase_v4.test_weakrefN)r   r   r   r   rO   r   rP   rV   rX   r[   r\   r]   r^   r_   rb   r   r   r   r   rN   ª   s   				rN   c               @   sz   e Zd ZejZdd„ Zdd„ Zdd„ Zdd„ Z	d	d
„ Z
dd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ ZdS )ÚAddressTestCase_v6c          	   C   s*   d}|   d|¡ t |¡ W d Q R X d S )Nz::1/24zUnexpected '/' in %r)r   r   ÚIPv6Address)r   r4   r   r   r   rP     s    z1AddressTestCase_v6.test_network_passed_as_addressc                s(   ‡ fdd„}|dƒ |dƒ |dƒ d S )Nc          	      s*   d}ˆ   || ¡ t | ¡ W d Q R X d S )NzAt least 3 parts expected in %r)r   r   rd   )r4   r@   )r   r   r   rQ     s    zUAddressTestCase_v6.test_bad_address_split_v6_not_enough_parts.<locals>.assertBadSplitú:z:1z	FEDC:9878r   )r   rQ   r   )r   r   Ú*test_bad_address_split_v6_not_enough_parts  s    z=AddressTestCase_v6.test_bad_address_split_v6_not_enough_partsc                s8   ‡ fdd„}|dƒ |dƒ |dƒ |dƒ |dƒ d S )Nc          	      s*   d}ˆ   || ¡ t | ¡ W d Q R X d S )Nz At most 8 colons permitted in %r)r   r   rd   )r4   r@   )r   r   r   rQ     s    zTAddressTestCase_v6.test_bad_address_split_v6_too_many_colons.<locals>.assertBadSplitz9:8:7:6:5:4:3::2:1z10:9:8:7:6:5:4:3:2:1z::8:7:6:5:4:3:2:1z8:7:6:5:4:3:2:1::z10:9:8:7:6:5:4:3:42.42.42.42r   )r   rQ   r   )r   r   Ú)test_bad_address_split_v6_too_many_colons  s    z<AddressTestCase_v6.test_bad_address_split_v6_too_many_colonsc                s8   ‡ fdd„}|dƒ |dƒ |dƒ |dƒ |dƒ d S )Nc          	      s*   d}ˆ   || ¡ t | ¡ W d Q R X d S )Nz+Exactly 8 parts expected without '::' in %r)r   r   rd   )r4   r@   )r   r   r   rQ   *  s    zSAddressTestCase_v6.test_bad_address_split_v6_too_many_parts.<locals>.assertBadSplitz3ffe:0:0:0:0:0:0:0:1z9:8:7:6:5:4:3:2:1z7:6:5:4:3:2:1z9:8:7:6:5:4:3:42.42.42.42z7:6:5:4:3:42.42.42.42r   )r   rQ   r   )r   r   Ú(test_bad_address_split_v6_too_many_parts)  s    z;AddressTestCase_v6.test_bad_address_split_v6_too_many_partsc                s   ‡ fdd„}|dƒ d S )Nc          	      s*   d}ˆ   || ¡ t | ¡ W d Q R X d S )Nz.Expected at most 7 other parts with '::' in %r)r   r   rd   )r4   r@   )r   r   r   rQ   7  s    zeAddressTestCase_v6.test_bad_address_split_v6_too_many_parts_with_double_colon.<locals>.assertBadSplitz1:2:3:4::5:6:7:8r   )r   rQ   r   )r   r   Ú:test_bad_address_split_v6_too_many_parts_with_double_colon6  s    zMAddressTestCase_v6.test_bad_address_split_v6_too_many_parts_with_double_colonc                s`   ‡ fdd„}|dƒ |dƒ |dƒ |dƒ |dƒ |dƒ |d	ƒ |d
ƒ |dƒ |dƒ d S )Nc          	      s*   d}ˆ   || ¡ t | ¡ W d Q R X d S )Nz At most one '::' permitted in %r)r   r   rd   )r4   r@   )r   r   r   rQ   ?  s    zZAddressTestCase_v6.test_bad_address_split_v6_repeated_double_colon.<locals>.assertBadSplitz
3ffe::1::1z1::2::3::4:5z2001::db:::1z	3ffe::1::z	::3ffe::1z:3ffe::1::1z3ffe::1::1:z:3ffe::1::1:z:::z2001:db8:::1r   )r   rQ   r   )r   r   Ú/test_bad_address_split_v6_repeated_double_colon>  s    zBAddressTestCase_v6.test_bad_address_split_v6_repeated_double_colonc                s0   ‡ fdd„}|dƒ |dƒ |dƒ |dƒ d S )Nc          	      s*   d}ˆ   || ¡ t | ¡ W d Q R X d S )Nz0Leading ':' only permitted as part of '::' in %r)r   r   rd   )r4   r@   )r   r   r   rQ   P  s    zRAddressTestCase_v6.test_bad_address_split_v6_leading_colon.<locals>.assertBadSplitz:2001:db8::1z:1:2:3:4:5:6:7z:1:2:3:4:5:6:z:6:5:4:3:2:1::r   )r   rQ   r   )r   r   Ú'test_bad_address_split_v6_leading_colonO  s
    z:AddressTestCase_v6.test_bad_address_split_v6_leading_colonc                s0   ‡ fdd„}|dƒ |dƒ |dƒ |dƒ d S )Nc          	      s*   d}ˆ   || ¡ t | ¡ W d Q R X d S )Nz1Trailing ':' only permitted as part of '::' in %r)r   r   rd   )r4   r@   )r   r   r   rQ   [  s    zSAddressTestCase_v6.test_bad_address_split_v6_trailing_colon.<locals>.assertBadSplitz2001:db8::1:z1:2:3:4:5:6:7:z
::1.2.3.4:z::7:6:5:4:3:2:r   )r   rQ   r   )r   r   Ú(test_bad_address_split_v6_trailing_colonZ  s
    z;AddressTestCase_v6.test_bad_address_split_v6_trailing_colonc                sB   ‡ fdd„}|ddƒ |ddƒ |ddƒ |d	d
ƒ |ddƒ d S )Nc          	      s(   ˆ   d|| ¡ t | ¡ W d Q R X d S )Nz%s in %r)r   r   rd   )r4   Zv4_error)r   r   r   ÚassertBadAddressPartf  s    zDAddressTestCase_v6.test_bad_v4_part_in.<locals>.assertBadAddressPartz3ffe::1.netzExpected 4 octets in '1.net'z3ffe::127.0.1zExpected 4 octets in '127.0.1'z::1.2.3zExpected 4 octets in '1.2.3'z::1.2.3.4.5z Expected 4 octets in '1.2.3.4.5'z3ffe::1.1.1.netz5Only decimal digits permitted in 'net' in '1.1.1.net'r   )r   rm   r   )r   r   Útest_bad_v4_part_ine  s    
z&AddressTestCase_v6.test_bad_v4_part_inc                sL   ‡ fdd„}|ddƒ |ddƒ |ddƒ |d	d
ƒ |ddƒ |ddƒ d S )Nc          	      s6   d|| f }ˆ   t |¡¡ t | ¡ W d Q R X d S )Nz%Only hex digits permitted in %r in %r)r   r#   r$   r   rd   )r4   Úpartr@   )r   r   r   ÚassertBadPartv  s    zAAddressTestCase_v6.test_invalid_characters.<locals>.assertBadPartz
3ffe::googZgoogz3ffe::-0z-0z3ffe::+0z+0z3ffe::-1z-1z	1.2.3.4::z1.2.3.4z1234:axy::bZaxyr   )r   rp   r   )r   r   r[   u  s    




z*AddressTestCase_v6.test_invalid_charactersc                s8   ‡ fdd„}|ddƒ |ddƒ |ddƒ |d	d
ƒ d S )Nc          	      s,   d}ˆ   ||| ¡ t | ¡ W d Q R X d S )Nz*At most 4 characters permitted in %r in %r)r   r   rd   )r4   ro   r@   )r   r   r   rp   ƒ  s    z:AddressTestCase_v6.test_part_length.<locals>.assertBadPartz::00000Z00000z3ffe::10000Z10000z02001:db8::Z02001z2001:888888::1Z888888r   )r   rp   r   )r   r   Útest_part_length‚  s
    


z#AddressTestCase_v6.test_part_lengthc             C   s   |   d¡ d S )Nz
2001:db8::)r7   )r   r   r   r   r_     s    zAddressTestCase_v6.test_picklec             C   s   t  |  d¡¡ d S )Nz
2001:db8::)r`   ra   r   )r   r   r   r   rb     s    zAddressTestCase_v6.test_weakrefN)r   r   r   r   rd   r   rP   rf   rg   rh   ri   rj   rk   rl   rn   r[   rq   r_   rb   r   r   r   r   rc   
  s   
rc   c               @   sD   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ Zdd„ Zdd„ Z	dS )ÚNetmaskTestMixin_v4c             C   s   |   t|  d¡ƒd¡ d S )Nz1.2.3.4z
1.2.3.4/32)r   Ústrr   )r   r   r   r   Útest_no_mask—  s    z NetmaskTestMixin_v4.test_no_maskc          	   C   s,   d}|   d| ¡ |  |¡ W d Q R X d S )Nz1.2.3.4/32/24zOnly one '/' permitted in %r)r   r   )r   r4   r   r   r   Útest_split_netmaskš  s    z&NetmaskTestMixin_v4.test_split_netmaskc                s\   ‡ fdd„}|ddƒ |ddƒ |ddƒ |ddƒ |d	dƒ |d
dƒ |dt  d¡ƒ d S )Nc          	      s$   ˆ   |¡ ˆ  | ¡ W d Q R X d S )N)r   r   )r4   r   )r   r   r   ÚassertBadAddress   s    zANetmaskTestMixin_v4.test_address_errors.<locals>.assertBadAddressú/zAddress cannot be emptyz/8rU   zExpected 4 octetsz
google.comz10/8z	::1.2.3.4zOnly decimal digitsz	1.2.3.256z256 (> 255))r#   r$   )r   rv   r   )r   r   Útest_address_errorsŸ  s    





z'NetmaskTestMixin_v4.test_address_errorsc             C   s¶   |   t|  d¡ƒd¡ xštddƒD ]Œ}d| }|  |¡}|   t|ƒ|¡ |   t|  d|j ¡ƒ|¡ |   t|  d| ¡ƒ|¡ |dkr’dd	|  }|   t|  d|j ¡ƒ|¡ q"W d S )
Nz192.0.2.0/255.255.255.0z192.0.2.0/24r   é!   z
0.0.0.0/%dz
0.0.0.0/%sz0.0.0.0/0%d)é    r   rz   )r   rs   r   r0   ÚnetmaskÚhostmask)r   ÚiÚnet_strÚnetr   r   r   Útest_valid_netmask¬  s    
z&NetmaskTestMixin_v4.test_valid_netmaskc                sœ   ‡ fdd„}|ddƒ |ddƒ |ddƒ |ddƒ |ddƒ |dd	ƒ |dd
ƒ |ddƒ |ddƒ |ddƒ |ddƒ |ddƒ |ddƒ |ddƒ d S )Nc          	      s:   d| }ˆ   t |¡¡ ˆ  d| |f ¡ W d Q R X d S )Nz%r is not a valid netmaskz%s/%s)r   r#   r$   r   )r4   r{   r@   )r   r   r   ÚassertBadNetmaskÁ  s    zANetmaskTestMixin_v4.test_netmask_errors.<locals>.assertBadNetmaskz1.2.3.4r!   z-1z+1z 1 Ú0x1Z33z254.254.255.256z1.a.2.3z1.1.1.1z254.xyz.2.3z240.255.0.0z255.254.128.0z0.1.127.255Úpuddingz::r   )r   r   r   )r   r   Útest_netmask_errorsÀ  s    












z'NetmaskTestMixin_v4.test_netmask_errorsc                s$   ‡ fdd„}|ddƒ |ddƒ d S )Nc          	      s6   d| }ˆ   t |¡¡ ˆ  | |f¡ W d Q R X d S )Nz%r is not a valid netmask)r   r#   r$   r   )r4   r{   r@   )r   r   r   r   Ö  s    zJNetmaskTestMixin_v4.test_netmask_in_tuple_errors.<locals>.assertBadNetmaskz1.1.1.1r?   ry   r   )r   r   r   )r   r   Útest_netmask_in_tuple_errorsÕ  s    
z0NetmaskTestMixin_v4.test_netmask_in_tuple_errorsc             C   s"   |   d¡ |   d¡ |   d¡ d S )Nz192.0.2.0/27z192.0.2.0/31z	192.0.2.0)r7   )r   r   r   r   r_   Ý  s    

zNetmaskTestMixin_v4.test_pickleN)
r   r   r   rt   ru   rx   r€   r„   r…   r_   r   r   r   r   rr   ”  s   rr   c               @   s   e Zd ZejZdS )ÚInterfaceTestCase_v4N)r   r   r   r   ÚIPv4Interfacer   r   r   r   r   r†   ã  s   r†   c               @   s*   e Zd ZejZdd„ Zdd„ Zdd„ ZdS )ÚNetworkTestCase_v4c             C   st   |   |  d¡ |  d¡¡¡ |  |  d¡ |  d¡¡¡ |   |  d¡ |  d¡¡¡ |   |  d¡ |  d¡¡¡ d S )Nz10.0.0.0/30z10.0.1.0/24z10.0.0.0/24)ÚassertFalser   Ú	subnet_ofr
   )r   r   r   r   Útest_subnet_ofê  s    



z!NetworkTestCase_v4.test_subnet_ofc             C   st   |   |  d¡ |  d¡¡¡ |   |  d¡ |  d¡¡¡ |   |  d¡ |  d¡¡¡ |  |  d¡ |  d¡¡¡ d S )Nz10.0.0.0/30z10.0.1.0/24z10.0.0.0/24)r‰   r   Úsupernet_ofr
   )r   r   r   r   Útest_supernet_ofü  s    



z#NetworkTestCase_v4.test_supernet_ofc          	   C   s´   |   t¡ t d¡ t d¡¡ W d Q R X |   t¡ t d¡ t d¡¡ W d Q R X |   t¡ t d¡ t d¡¡ W d Q R X |   t¡ t d¡ t d¡¡ W d Q R X d S )Nz10.0.0.0/30z::1/128)r(   r)   r   ÚIPv4NetworkrŒ   ÚIPv6NetworkrŠ   )r   r   r   r   Útest_subnet_of_mixed_types  s    



z-NetworkTestCase_v4.test_subnet_of_mixed_typesN)	r   r   r   r   rŽ   r   r‹   r   r   r   r   r   r   rˆ   ç  s   rˆ   c               @   s<   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ Zdd„ ZdS )ÚNetmaskTestMixin_v6c          	   C   s,   d}|   d| ¡ |  |¡ W d Q R X d S )Nzcafe:cafe::/128/190zOnly one '/' permitted in %r)r   r   )r   r4   r   r   r   ru      s    z&NetmaskTestMixin_v6.test_split_netmaskc                sL   ‡ fdd„}|ddƒ |ddƒ |ddƒ |ddƒ |d	dƒ |d
dƒ d S )Nc          	      s$   ˆ   |¡ ˆ  | ¡ W d Q R X d S )N)r   r   )r4   r   )r   r   r   rv   &  s    zANetmaskTestMixin_v6.test_address_errors.<locals>.assertBadAddressrw   zAddress cannot be emptyz/8z
google.comzAt least 3 partsz1.2.3.4z10/8z1234:axy::bzOnly hex digitsr   )r   rv   r   )r   r   rx   %  s    




z'NetmaskTestMixin_v6.test_address_errorsc             C   sf   |   t|  d¡ƒd¡ xJtddƒD ]<}d| }|   t|  |¡ƒ|¡ |   t|  d| ¡ƒ|¡ q"W d S )Nz2001:db8::/32r   é   z::/%dz::/0%d)r   rs   r   r0   )r   r}   r~   r   r   r   r€   1  s
    z&NetmaskTestMixin_v6.test_valid_netmaskc                s~   ‡ fdd„}|ddƒ |ddƒ |ddƒ |ddƒ |ddƒ |ddƒ |dd	ƒ |dd
ƒ |ddƒ |ddƒ |ddƒ d S )Nc          	      s:   d| }ˆ   t |¡¡ ˆ  d| |f ¡ W d Q R X d S )Nz%r is not a valid netmaskz%s/%s)r   r#   r$   r   )r4   r{   r@   )r   r   r   r   =  s    zANetmaskTestMixin_v6.test_netmask_errors.<locals>.assertBadNetmaskz::1r!   z1::z-1z+1z 1 r‚   Z129z1.2.3.4rƒ   z::r   )r   r   r   )r   r   r„   <  s    









z'NetmaskTestMixin_v6.test_netmask_errorsc                s$   ‡ fdd„}|ddƒ |ddƒ d S )Nc          	      s6   d| }ˆ   t |¡¡ ˆ  | |f¡ W d Q R X d S )Nz%r is not a valid netmask)r   r#   r$   r   )r4   r{   r@   )r   r   r   r   O  s    zJNetmaskTestMixin_v6.test_netmask_in_tuple_errors.<locals>.assertBadNetmaskz::1r?   r’   r   )r   r   r   )r   r   r…   N  s    
z0NetmaskTestMixin_v6.test_netmask_in_tuple_errorsc             C   s"   |   d¡ |   d¡ |   d¡ d S )Nz2001:db8::1000/124z2001:db8::1000/127z2001:db8::1000)r7   )r   r   r   r   r_   V  s    

zNetmaskTestMixin_v6.test_pickleN)	r   r   r   ru   rx   r€   r„   r…   r_   r   r   r   r   r‘     s   r‘   c               @   s   e Zd ZejZdS )ÚInterfaceTestCase_v6N)r   r   r   r   ÚIPv6Interfacer   r   r   r   r   r“   \  s   r“   c               @   s"   e Zd ZejZdd„ Zdd„ ZdS )ÚNetworkTestCase_v6c             C   st   |   |  d¡ |  d¡¡¡ |  |  d¡ |  d¡¡¡ |   |  d¡ |  d¡¡¡ |   |  d¡ |  d¡¡¡ d S )Nz2000:999::/56z2000:aaa::/48z2000:aaa::/56z2000:bbb::/56)r‰   r   rŠ   r
   )r   r   r   r   r‹   c  s    



z!NetworkTestCase_v6.test_subnet_ofc             C   st   |   |  d¡ |  d¡¡¡ |   |  d¡ |  d¡¡¡ |   |  d¡ |  d¡¡¡ |  |  d¡ |  d¡¡¡ d S )Nz2000:999::/56z2000:aaa::/48z2000:aaa::/56z2000:bbb::/56)r‰   r   rŒ   r
   )r   r   r   r   r   u  s    



z#NetworkTestCase_v6.test_supernet_ofN)r   r   r   r   r   r   r‹   r   r   r   r   r   r•   `  s   r•   c               @   s,   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	S )
ÚFactoryFunctionErrorsc          	   C   s0   d}d}|   t|||¡ ||ƒ W d Q R X d S )NZcamelotz+%r does not appear to be an IPv4 or IPv6 %s)r   Ú
ValueError)r   r   Úkindr4   r@   r   r   r   ÚassertFactoryErrorŠ  s    z(FactoryFunctionErrors.assertFactoryErrorc             C   s   |   tjd¡ d S )NÚaddress)r™   r   Ú
ip_address)r   r   r   r   Útest_ip_address‘  s    z%FactoryFunctionErrors.test_ip_addressc             C   s   |   tjd¡ d S )NZ	interface)r™   r   Úip_interface)r   r   r   r   Útest_ip_interface”  s    z'FactoryFunctionErrors.test_ip_interfacec             C   s   |   tjd¡ d S )NÚnetwork)r™   r   Ú
ip_network)r   r   r   r   Útest_ip_network—  s    z%FactoryFunctionErrors.test_ip_networkN)r   r   r   r™   rœ   rž   r¡   r   r   r   r   r–   ˆ  s   r–   c               @   s   e Zd Zdd„ Zdd„ ZdS )ÚLargestObjectc             C   s
   t |tƒS )N)Ú
isinstancer¢   )r   Úotherr   r   r   Ú__eq__  s    zLargestObject.__eq__c             C   s   dS )NFr   )r   r¤   r   r   r   Ú__lt__Ÿ  s    zLargestObject.__lt__N)r   r   r   r¥   r¦   r   r   r   r   r¢   ›  s   r¢   c               @   s   e Zd Zdd„ Zdd„ ZdS )ÚSmallestObjectc             C   s
   t |tƒS )N)r£   r§   )r   r¤   r   r   r   r¥   ¤  s    zSmallestObject.__eq__c             C   s   dS )NFr   )r   r¤   r   r   r   Ú__gt__¦  s    zSmallestObject.__gt__N)r   r   r   r¥   r¨   r   r   r   r   r§   ¢  s   r§   c               @   sø   e Zd Ze d¡Ze d¡Ze d¡Z	e 
d¡Ze d¡Ze d¡Zee	gZeeg ZeegZeeg Zee Ze d¡Ze d¡Ze d¡Ze 
d¡Ze d¡Ze d¡Zdd„ Zdd„ Zdd„ Zd	d
„ Zdd„ Zdd„ Z dd„ Z!dd„ Z"dd„ Z#dS )ÚComparisonTestsr'   rJ   c             C   sX   t ƒ }xL| jD ]B}|  ||¡ |  ||k¡ |  | |¡t¡ |  | |¡t¡ qW d S )N)ÚobjectÚobjectsÚassertNotEqualr‰   r   r¥   ÚNotImplementedÚ__ne__)r   r¤   Úobjr   r   r   Útest_foreign_type_equalityÀ  s    z*ComparisonTests.test_foreign_type_equalityc             C   s:   x4| j D ]*}x$| j D ]}||kr"q|  ||¡ qW qW d S )N)r«   r¬   )r   r   r   r   r   r   Útest_mixed_type_equalityÉ  s
    z(ComparisonTests.test_mixed_type_equalityc             C   s8   x2| j D ](}|  ||¡ |  ||¡ |  ||¡ qW d S )N)r«   r   ÚassertLessEqualÚassertGreaterEqual)r   r¯   r   r   r   Útest_same_type_equalityÒ  s    z'ComparisonTests.test_same_type_equalityc             C   sÆ   xÀ| j | jf| j| jf| j| jf| j| jf| j| j	f| j
| jffD ]|\}}|  ||¡ |  ||¡ |  ||¡ |  ||¡ |  ||¡ |  ||k¡ |  ||k ¡ |  ||k¡ |  ||k¡ qBW d S )N)Úv4addrÚv4addr2Úv4netÚv4net2Úv4intfÚv4intf2Úv6addrÚv6addr2Úv6netÚv6net2Úv6intfÚv6intf2r¬   Z
assertLessr²   ZassertGreaterr³   r‰   )r   r   r   r   r   r   Útest_same_type_orderingØ  s     




z'ComparisonTests.test_same_type_orderingc             C   sŒ   x| j D ]}|  || j¡ qW x| jD ]}|  || j¡ q&W x$| j| jg D ]}|  || j¡ qLW x$| j| jg D ]}|  || j¡ qrW d S )N)Úv4_addressesÚassertInr·   Úv6_addressesr½   Ú
v4_objectsÚassertNotInÚ
v6_objects)r   r¯   r   r   r   Útest_containmentë  s    z ComparisonTests.test_containmentc                sš   x”| j D ]Š‰ x„| j D ]z‰tˆ tˆƒƒstˆtˆ ƒƒr6q|  t‡ ‡fdd„¡ |  t‡ ‡fdd„¡ |  t‡ ‡fdd„¡ |  t‡ ‡fdd„¡ qW qW d S )Nc                  s   ˆ ˆk S )Nr   r   )r   r   r   r   Ú<lambda>ú  ó    z:ComparisonTests.test_mixed_type_ordering.<locals>.<lambda>c                  s   ˆ ˆkS )Nr   r   )r   r   r   r   rÉ   û  rÊ   c                  s   ˆ ˆkS )Nr   r   )r   r   r   r   rÉ   ü  rÊ   c                  s   ˆ ˆkS )Nr   r   )r   r   r   r   rÉ   ý  rÊ   )r«   r£   Útyper(   r)   )r   r   )r   r   r   Útest_mixed_type_orderingõ  s    z(ComparisonTests.test_mixed_type_orderingc          
   C   s  t ƒ }tƒ }tƒ }xö| jD ]ì}|  t¡ ||k  W d Q R X |  t¡ ||k W d Q R X |  t¡ ||k W d Q R X |  t¡ ||k W d Q R X |  ||k ¡ |  ||k¡ |  ||k¡ |  ||k¡ |  ||k ¡ |  ||k¡ |  ||k¡ |  ||k¡ qW d S )N)rª   r§   r¢   r«   r(   r)   r
   r‰   )r   r¤   ZsmallestZlargestr¯   r   r   r   Útest_foreign_type_orderingÿ  s(    z*ComparisonTests.test_foreign_type_orderingc             C   s‚   | j | j| jg}| j| j| jg}|  |t| jt	j
d¡ |  |t| jt	j
d¡ |  || t| jt	j
d¡ |  tt	 
t¡¡ d S )N)Úkey)rµ   r·   r¹   r»   r½   r¿   r   ÚsortedrÅ   r   Zget_mixed_type_keyrÇ   r«   r­   rª   )r   Z
v4_orderedZ
v6_orderedr   r   r   Útest_mixed_type_key  s    
z#ComparisonTests.test_mixed_type_keyc             C   s¬   t  d¡}t  d¡}t  d¡}t  d¡}|  t|j|¡ |  t|j|¡ |  t|j|¡ |  t|j|¡ |  t|j|¡ |  t|j|¡ |  t|j|¡ |  t|j|¡ d S )Nz1.1.1.1z::1)r   r›   r    r(   r)   r¦   r¨   )r   rµ   r·   r»   r½   r   r   r   Útest_incompatible_versions$  s    



z*ComparisonTests.test_incompatible_versionsN)$r   r   r   r   rO   rµ   rŽ   r·   r‡   r¹   rd   r»   r   r½   r”   r¿   rÂ   rÅ   rÄ   rÇ   r«   r¶   r¸   rº   r¼   r¾   rÀ   r°   r±   r´   rÁ   rÈ   rÌ   rÍ   rÐ   rÑ   r   r   r   r   r©   ©  s4   













		

r©   c               @   sD  e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ Zdd„ Zdd„ Z	dd„ Z
dd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd „ Zd!d"„ Zd#d$„ Zd%d&„ Zd'd(„ Zd)d*„ Zd+d,„ Zd-d.„ Zd/d0„ Zd1d2„ Zd3d4„ Zd5d6„ Zd7d8„ Zd9d:„ Zd;d<„ Z d=d>„ Z!d?d@„ Z"dAdB„ Z#dCdD„ Z$dEdF„ Z%dGdH„ Z&dIdJ„ Z'dKdL„ Z(dMdN„ Z)dOdP„ Z*dQdR„ Z+dSdT„ Z,dUdV„ Z-dWdX„ Z.dYdZ„ Z/d[d\„ Z0d]d^„ Z1d_d`„ Z2dadb„ Z3dcdd„ Z4dedf„ Z5dgdh„ Z6didj„ Z7dkdl„ Z8dmdn„ Z9dodp„ Z:dqdr„ Z;dsdt„ Z<dudv„ Z=dwdx„ Z>dydz„ Z?d{d|„ Z@d}d~„ ZAdd€„ ZBdd‚„ ZCdƒd„„ ZDd…d†„ ZEd‡dˆ„ ZFd‰dŠ„ ZGd‹dŒ„ ZHddŽ„ ZIdS )ÚIpaddrUnitTestc             C   sL   t  d¡| _t  d¡| _t  d¡| _t  d¡| _t  d¡| _	t  
d¡| _d S )Nz1.2.3.4z
1.2.3.4/24z
1.2.3.0/24z2001:658:22a:cafe:200:0:0:1z2001:658:22a:cafe:200:0:0:1/64z2001:658:22a:cafe::/64)r   rO   Úipv4_addressr‡   Úipv4_interfacerŽ   Úipv4_networkr”   Úipv6_addressÚipv6_interfacer   Úipv6_network)r   r   r   r   ÚsetUp8  s    zIpaddrUnitTest.setUpc             C   s0   |   dtt d¡ƒ¡ |   dtt d¡ƒ¡ d S )NzIPv4Interface('1.2.3.4/32')z1.2.3.4zIPv6Interface('::1/128')z::1)r   r%   r   r‡   r”   )r   r   r   r   ÚtestReprC  s    zIpaddrUnitTest.testReprc          	   C   s¢  t  d¡}t  d¡}|  t  d¡|¡ |  t  |df¡|¡ |  t  d¡|¡ |  t  d¡|¡ |  t  |df¡|¡ |  t  d¡|¡ |  t¡ t  d	¡ W d Q R X |  t¡ t  |d
f¡ W d Q R X |  t¡ t  d¡ W d Q R X |  t¡ t  d¡ W d Q R X |  t¡ t  |df¡ W d Q R X |  t¡ t  d¡ W d Q R X t  d¡}|  t jd	dd|¡ |  t j|d
fdd|¡ |  t jddd|¡ |  t jddd|¡ |  t j|dfdd|¡ |  t jddd|¡ t  d¡}t  d¡}|  t  d¡|¡ |  t  |df¡|¡ |  t  d¡|¡ |  t  d¡|¡ |  t  |d
f¡|¡ |  t  d¡|¡ |  t  d	¡t  d¡¡ |  t  d¡t  d¡¡ d S )Nz	192.0.2.1z192.0.2.1/32)z	192.0.2.1rz   rz   )l      rz   )z	192.0.2.1z255.255.255.255z255.255.255.255)l      z255.255.255.255)z	192.0.2.1é   rÛ   )l      rÛ   )z	192.0.2.1z255.255.255.0z255.255.255.0)l      z255.255.255.0z192.0.2.0/24F)Ústrictz	192.0.2.0)z	192.0.2.0z255.255.255.0)l       z255.255.255.0)z	192.0.2.0rÛ   )l       rÛ   z192.0.2.1/24)r   rO   rŽ   r   r(   r—   r‡   )r   Úipr   r   r   r   ÚtestIPv4TupleJ  sh    











zIpaddrUnitTest.testIPv4Tuplec          	   C   sŽ  t  d¡}t  d¡}|  t  d¡|¡ |  t  d¡|¡ |  t  |df¡|¡ t  d¡}t  d¡}|  t  d¡|¡ |  t  d¡|¡ |  t  |d	f¡|¡ t  d
¡}|  t¡ t  d¡ W d Q R X |  t¡ t  d¡ W d Q R X |  t¡ t  |df¡ W d Q R X t  d¡}|  t jddd|¡ |  t jddd|¡ |  t j|dfdd|¡ |  t  d¡t  d¡¡ |  t  d¡t  d¡¡ d S )Nz
2001:db8::z2001:db8::/128)z
2001:db8::Ú128)l	                n†   rK   rß   z2001:db8::/96)z
2001:db8::Ú96)l	                n†   é`   rà   z2001:db8::1)z2001:db8::1rá   )l	               n†   rá   rá   F)rÜ   )z2001:db8::1rà   z2001:db8::1/96)l	               n†   rà   )r   rd   r   r   r(   r—   r”   )r   rÝ   r   r   r   r   ÚtestIPv6Tuple‰  sR    






zIpaddrUnitTest.testIPv6Tuplec             C   st   |   t d¡d t d¡¡ |   t d¡d t d¡¡ |   t d¡d t d¡¡ |   t d¡d t d¡¡ d S )	Nz1.1.1.1éÿ   z1.1.2.0é   z1.1.0.1z::1iþÿ  z::ffff)r   r   rO   rd   )r   r   r   r   ÚtestAddressIntMath»  s    z!IpaddrUnitTest.testAddressIntMathc             C   sP   |   ttjd¡ |   ttjdtj ¡ |   ttjd¡ |   ttjdtj ¡ d S )Nr?   rJ   )r(   r—   r   Zv4_int_to_packedZ
IPV4LENGTHZv6_int_to_packedZ
IPV6LENGTH)r   r   r   r   ÚtestInvalidIntToBytesÅ  s    

z$IpaddrUnitTest.testInvalidIntToBytesc             C   s®   t  d¡}t  d¡}t  d¡}|  tt  |g¡ƒ||fg¡ |  tt  ||g¡ƒ||f||fg¡ |  tt  |||g¡ƒ||fg¡ |  dt  dd¡¡ |  dt| jƒ¡ d S )Nz10.10.10.10z10.10.10.11z10.10.10.12rK   r   zIPv4Network('1.2.3.0/24'))r   rO   r   ÚlistZ_find_address_rangeZ_count_righthand_zero_bitsr%   rÕ   )r   Úip1Úip2Úip3r   r   r   ÚtestInternalsÍ  s    


zIpaddrUnitTest.testInternalsc          	   C   s<   G dd„ dt jƒ}|dƒ}|  td¡ |j W d Q R X d S )Nc               @   s   e Zd ZdS )z8IpaddrUnitTest.testMissingNetworkVersion.<locals>.BrokenN)r   r   r   r   r   r   r   ÚBrokenÛ  s   rì   z	127.0.0.1zBroken.*version)r   Ú_BaseNetworkr   r   Úversion)r   rì   Úbrokenr   r   r   ÚtestMissingNetworkVersionÚ  s    z(IpaddrUnitTest.testMissingNetworkVersionc          	   C   s<   G dd„ dt jƒ}|dƒ}|  td¡ |j W d Q R X d S )Nc               @   s   e Zd ZdS )z6IpaddrUnitTest.testMissingAddressClass.<locals>.BrokenN)r   r   r   r   r   r   r   rì   â  s   rì   z	127.0.0.1zBroken.*address)r   rí   r   r   Z_address_class)r   rì   rï   r   r   r   ÚtestMissingAddressClassá  s    z&IpaddrUnitTest.testMissingAddressClassc             C   sh   |   t| jjƒd¡ |   t| jjƒd¡ |   t| jjƒd¡ |   t| jjƒd¡ |   t| jjƒd¡ d S )Ni z1.2.3.0l	           à/YE ƒ   z2001:658:22a:cafe::z::ffff:ffff:ffff:ffff)r   ÚintrÕ   Únetwork_addressrs   rØ   r|   )r   r   r   r   ÚtestGetNetworkè  s    zIpaddrUnitTest.testGetNetworkc             C   s¬   |   | jjt d¡j¡ t d¡}t d¡}|   |t t|jƒ¡¡ |   |t t|jƒ¡¡ d}|   | jjt 	|¡j¡ |   t | j
j¡jd¡ |   t | jj¡jd¡ d S )Niz1.2.3.4z2001:658:22a:cafe:200:0:0:1l	         à/YE ƒ   é   é   )r   rÔ   Ú_ipr   r‡   r    rò   ró   r×   r”   rÓ   rî   rÖ   )r   Úipv4Úipv6Zv6_intr   r   r   ÚtestIpFromIntó  s    



zIpaddrUnitTest.testIpFromIntc             C   sv   t j}|  | jjt  d¡j¡ |  |dƒ|dƒ¡ |  | jjt  d¡j¡ |  |dƒ|dƒ¡ |  |dƒ|dƒ¡ d S )	Ns   z255.254.253.252s   ÿþýüs    X*Êþ      zffff:2:3:4:ffff::s   ÿÿ   ÿÿ      z::s                   )r   r›   r   rÔ   r÷   r   r×   rÝ   )r   rš   r   r   r   ÚtestIpFromPacked  s    






zIpaddrUnitTest.testIpFromPackedc             C   sT   |   t| jjƒd¡ |   t| jjƒd¡ |   t| jjƒd¡ |   t| jjƒd¡ d S )Niz1.2.3.4l	         à/YE ƒ   z2001:658:22a:cafe:200::1)r   rò   rÔ   rÝ   rs   r×   )r   r   r   r   Ú	testGetIp  s    zIpaddrUnitTest.testGetIpc             C   sP   |   t| jjƒd¡ |   t| jjƒd¡ |   t| jjƒd¡ |   | jjd¡ d S )Nl    ÿ z255.255.255.0l	           ðÿÿÿÿ é@   )r   rò   rÕ   r{   rs   rØ   Ú	prefixlen)r   r   r   r   ÚtestGetNetmask  s
    zIpaddrUnitTest.testGetNetmaskc             C   s”   t  d¡}|  t|jjƒd¡ |  | d¡d¡ |  | d¡¡ |  | d¡¡ |  	| d¡¡ t  
d¡}|  t|jjƒd¡ |  | d¡d¡ d S )Nz	1.2.3.4/0r   Ú0z0.0.0.0Úinvalidz::1/0)r   r‡   r   rò   rŸ   r{   Z_prefix_from_prefix_stringr
   Ú_is_valid_netmaskr‰   r”   )r   Zipv4_zero_netmaskZipv6_zero_netmaskr   r   r   ÚtestZeroNetmask%  s    

zIpaddrUnitTest.testZeroNetmaskc             C   s²   | j }|  | d¡¡ |  | d¡¡ |  | d¡¡ |  | d¡¡ |  | d¡¡ |  | d¡¡ |  | d¡¡ |  | d¡¡ |  | d¡¡ t d	¡}|  |jd
¡ d S )Nr  z128.128.128.128z128.128.128.127z128.128.128.255z255.128.128.128z128.255.255.255z255.255.255.255z1.2.3.4z127.0.0.0/0.0.0.255rÛ   )	rÕ   r‰   r  r
   Z_is_hostmaskr   rŽ   r   rþ   )r   r   r   r   r   ÚtestIPv4NetAndHostmasks1  s    
z&IpaddrUnitTest.testIPv4NetAndHostmasksc             C   sT   |   t| jjƒd¡ |   t| jjƒd¡ |   t| jjƒd¡ |   t| jjƒd¡ d S )Niÿz	1.2.3.255l	   ÿÿÿÿï/YE ƒ   z%2001:658:22a:cafe:ffff:ffff:ffff:ffff)r   rò   rÕ   Úbroadcast_addressrs   rØ   )r   r   r   r   ÚtestGetBroadcastA  s    zIpaddrUnitTest.testGetBroadcastc             C   s(   |   | jjjd¡ |   | jjjd¡ d S )NrÛ   rý   )r   rÔ   rŸ   rþ   r×   )r   r   r   r   ÚtestGetPrefixlenJ  s    zIpaddrUnitTest.testGetPrefixlenc             C   s˜   |   | j ¡ jd¡ |   t| j ¡ jƒd¡ |   t d¡j ¡ t 	d¡¡ |   | j
 ¡ jd¡ |   t| j
 ¡ jƒd¡ |   t d¡j ¡ t d¡¡ d S )Né   z1.2.2.0z	0.0.0.0/0é?   z2001:658:22a:cafe::z::0/0)r   rÕ   Úsupernetrþ   rs   ró   r   r‡   rŸ   rŽ   rØ   r”   r   )r   r   r   r   ÚtestGetSupernetN  s    zIpaddrUnitTest.testGetSupernetc             C   sd   |   | j d¡jd¡ |   t| j d¡jƒd¡ |   | j d¡jd¡ |   t| j d¡jƒd¡ d S )NrF   é   z1.2.0.0é=   z2001:658:22a:caf8::)r   rÕ   r
  rþ   rs   ró   rØ   )r   r   r   r   ÚtestGetSupernet3\  s    zIpaddrUnitTest.testGetSupernet3c             C   s˜   | j t| jjddd | j t| jjdd |  | jjdd| jjdd¡ | j t| jjddd | j t| jjdd |  | jjdd| jjd	d¡ d S )
NrJ   r'   )Úprefixlen_diffÚ
new_prefixé   )r  )r  é   éA   é>   )r(   r—   rÕ   r
  r   rØ   )r   r   r   r   ÚtestGetSupernet4e  s    

zIpaddrUnitTest.testGetSupernet4c             C   s  t | j ¡ ƒ}|  dt|ƒ¡ |  t d¡|d ¡ |  t d¡|d ¡ t d¡}t | ¡ ƒ}|  dt|ƒ¡ |  t d¡|d ¡ |  t d	¡|d ¡ t d
¡t d¡g}d}d}|  |t t 	|¡ ¡ ƒ¡ |  |t t 	|¡ ¡ ƒ¡ |  t t 	|¡ ¡ ƒt t 	|¡ ¡ ƒ¡ t d¡t d¡g}d}d}|  |t t 	|¡ ¡ ƒ¡ |  |t t 	|¡ ¡ ƒ¡ |  t t 	|¡ ¡ ƒt t 	|¡ ¡ ƒ¡ d S )Néþ   z1.2.3.1r   z	1.2.3.254r?   z2001:658:22a:cafe::/120rã   z2001:658:22a:cafe::1z2001:658:22a:cafe::ffz2.0.0.0z2.0.0.1z
2.0.0.0/31)z2.0.0.0é   z2001:658:22a:cafe::z2001:658:22a:cafe::/127)z2001:658:22a:cafe::é   )
rç   rÕ   Úhostsr   Úlenr   rO   r   rd   r    )r   r  rØ   ZaddrsZstr_argsZtpl_argsr   r   r   Ú	testHostst  s2    
zIpaddrUnitTest.testHostsc             C   s¸   |   t| jjddƒt| jjddƒ¡ |  tt| jjdd¡ |  tt| jjddd¡ |   t| jjddƒt| jjddƒ¡ |  tt| jjd	d¡ |  tt| jjddd¡ d S )
NrF   )r  é   )r  r  )r  r  rõ   éD   r	  )r   rÏ   rÕ   Úsubnetsr(   r—   rç   rØ   )r   r   r   r   ÚtestFancySubnetting“  s    
z"IpaddrUnitTest.testFancySubnettingc             C   s|   |   t| j ¡ ƒd jd¡ |   tt| j ¡ ƒd jƒd¡ |   tt| j ¡ ƒd jƒd¡ |   t| j ¡ ƒd jd¡ d S )Nr   r  z1.2.3.0r'   z	1.2.3.128r  )r   rç   rÕ   r  rþ   rs   ró   rØ   )r   r   r   r   ÚtestGetSubnets£  s    zIpaddrUnitTest.testGetSubnetsc             C   sN   t  d¡}dd„ | ¡ D ƒ}dd„ | d¡D ƒ}|  |dg¡ |  ||¡ d S )Nz
1.2.3.4/32c             S   s   g | ]}t |ƒ‘qS r   )rs   )Ú.0r5   r   r   r   ú
<listcomp>°  s    z;IpaddrUnitTest.testGetSubnetForSingle32.<locals>.<listcomp>c             S   s   g | ]}t |ƒ‘qS r   )rs   )r!  r5   r   r   r   r"  ±  s    rJ   )r   rŽ   r  r   )r   rÝ   Úsubnets1Úsubnets2r   r   r   ÚtestGetSubnetForSingle32®  s
    
z'IpaddrUnitTest.testGetSubnetForSingle32c             C   sN   t  d¡}dd„ | ¡ D ƒ}dd„ | d¡D ƒ}|  |dg¡ |  ||¡ d S )Nz::1/128c             S   s   g | ]}t |ƒ‘qS r   )rs   )r!  r5   r   r   r   r"  ·  s    z<IpaddrUnitTest.testGetSubnetForSingle128.<locals>.<listcomp>c             S   s   g | ]}t |ƒ‘qS r   )rs   )r!  r5   r   r   r   r"  ¸  s    rJ   )r   r   r  r   )r   rÝ   r#  r$  r   r   r   ÚtestGetSubnetForSingle128µ  s
    
z(IpaddrUnitTest.testGetSubnetForSingle128c             C   sX   dd„ | j  d¡D ƒ}|  |ddddg¡ dd„ | j d¡D ƒ}|  |d	d
ddg¡ d S )Nc             S   s   g | ]}t |ƒ‘qS r   )rs   )r!  r5   r   r   r   r"  ½  s    z.IpaddrUnitTest.testSubnet2.<locals>.<listcomp>rJ   z
1.2.3.0/26z1.2.3.64/26z1.2.3.128/26z1.2.3.192/26c             S   s   g | ]}t |ƒ‘qS r   )rs   )r!  r5   r   r   r   r"  Â  s    z2001:658:22a:cafe::/66z2001:658:22a:cafe:4000::/66z2001:658:22a:cafe:8000::/66z2001:658:22a:cafe:c000::/66)rÕ   r  r   rØ   )r   ZipsZipsv6r   r   r   ÚtestSubnet2¼  s    zIpaddrUnitTest.testSubnet2c             C   sÀ   dd„ | j  d¡D ƒ}|  |d d… dddg¡ |  |dd … d	d
dg¡ |  t|ƒd¡ t d¡}dd„ | d¡D ƒ}|  |d d… dddg¡ |  |dd … dddg¡ |  t|ƒd¡ d S )Nc             S   s   g | ]}t |ƒ‘qS r   )rs   )r!  r5   r   r   r   r"  Ë  s    z2IpaddrUnitTest.testGetSubnets3.<locals>.<listcomp>é   rF   z
1.2.3.0/32z
1.2.3.1/32z
1.2.3.2/32éýÿÿÿz1.2.3.253/32z1.2.3.254/32z1.2.3.255/32rä   z2001:658:22a:cafe::/120c             S   s   g | ]}t |ƒ‘qS r   )rs   )r!  r5   r   r   r   r"  Ó  s    z2001:658:22a:cafe::/128z2001:658:22a:cafe::1/128z2001:658:22a:cafe::2/128z2001:658:22a:cafe::fd/128z2001:658:22a:cafe::fe/128z2001:658:22a:cafe::ff/128)rÕ   r  r   r  r   r   )r   r  rØ   r   r   r   ÚtestGetSubnets3Ê  s"    
zIpaddrUnitTest.testGetSubnets3c             C   s`   |   tt| jj d¡¡ |   tt| j d¡¡ |   tt| jj d¡¡ |   tt| j d¡¡ d S )Né	   r  )	r(   r—   rç   rÔ   rŸ   r  rÕ   r×   rØ   )r   r   r   r   ÚtestSubnetFailsForLargeCidrDiffÞ  s    z.IpaddrUnitTest.testSubnetFailsForLargeCidrDiffc             C   s,   |   t| jjjd¡ |   t| jjjd¡ d S )Nr  r  )r(   r—   rÔ   rŸ   r
  r×   )r   r   r   r   Ú!testSupernetFailsForLargeCidrDiffè  s    z0IpaddrUnitTest.testSupernetFailsForLargeCidrDiffc             C   s`   |   tt| jj d¡¡ |   tt| j d¡¡ |   tt| jj d¡¡ |   tt| j d¡¡ d S )Nr?   )	r(   r—   rç   rÔ   rŸ   r  rÕ   r×   rØ   )r   r   r   r   Ú"testSubnetFailsForNegativeCidrDiffî  s    z1IpaddrUnitTest.testSubnetFailsForNegativeCidrDiffc             C   s„   |   | jjd¡ |   t| j ¡ ƒd jd¡ |   | j ¡ jd¡ |   | jjd¡ |   t| j ¡ ƒd jd¡ |   | j ¡ jd¡ d S )Nrä   r   rK   i   l            l            l             )r   rÕ   Znum_addressesrç   r  r
  rØ   )r   r   r   r   ÚtestGetNum_Addressesø  s    z#IpaddrUnitTest.testGetNum_Addressesc             C   s`   |   t d¡| j¡ |  t d¡| j¡ t d¡}|   || j¡ |  t d¡ t d¡¡¡ d S )Nz1.2.3.128/25z
1.2.4.1/24z1.2.3.37z
1.1.0.0/16z
1.0.0.0/15)	rÃ   r   r‡   rÕ   rÆ   rO   r‰   rŽ   Ú__contains__)r   Úaddr1r   r   r   ÚtestContains  s    
zIpaddrUnitTest.testContainsc             C   sT   |   t| jd ƒd¡ |  t| jjd¡ |   t| jd ƒd¡ |  t| jjd¡ d S )NrG   z1.2.3.5rä   z2001:658:22a:cafe::5l            )r   rs   rÕ   r(   Ú
IndexErrorÚ__getitem__rØ   )r   r   r   r   ÚtestNth  s
    zIpaddrUnitTest.testNthc             C   sˆ   t  d¡}|  d|j¡ t|ƒ}|  dt|d ƒ¡ |  dt|d ƒ¡ |  dt|d ƒ¡ |  dt|d ƒ¡ |  |d |d ¡ d S )Nz172.31.255.128/255.255.255.240é   z172.31.255.128r   z172.31.255.143r?   )r   rŽ   r   rþ   rç   rs   )r   r4   Z	addr_listr   r   r   ÚtestGetitem  s    
zIpaddrUnitTest.testGetitemc             C   sè   |   | jt d¡k¡ |  | jt d¡k¡ |  | jt d¡k¡ |  | jdk¡ |  | jg k¡ |  | jdk¡ |   | jt d¡k¡ |  | jt d¡k¡ |  | jt d¡k¡ |  | jdk¡ |  | jg k¡ |  | jdk¡ d S )Nz
1.2.3.4/24z
1.2.3.4/23z::1.2.3.4/24r!   rJ   z2001:658:22a:cafe:200::1/64z2001:658:22a:cafe:200::1/63)r
   rÔ   r   r‡   r‰   r”   r×   )r   r   r   r   Ú	testEqual$  s$    zIpaddrUnitTest.testEqualc             C   st  |   | jt d¡k¡ |  | jt d¡k¡ |  | jt d¡k¡ |  | jdk¡ |  | jg k¡ |  | jdk¡ |  | jt d¡k¡ |  | jdk¡ |  | jg k¡ |  | jdk¡ |   | jt d¡k¡ |  | jt d¡k¡ |  | jt d¡k¡ |  | jdk¡ |  | jg k¡ |  | jdk¡ |  | j	t d	¡k¡ |  | j	dk¡ |  | j	g k¡ |  | j	dk¡ d S )
Nz
1.2.3.4/24z
1.2.3.4/23z::1.2.3.4/24r!   rJ   z1.2.3.5z2001:658:22a:cafe:200::1/64z2001:658:22a:cafe:200::1/63z1.2.3.4)
r‰   rÔ   r   r‡   r
   r”   rÓ   rO   r×   rÖ   )r   r   r   r   ÚtestNotEqual9  s8    zIpaddrUnitTest.testNotEqualc             C   s   |   tt d¡ƒd¡ d S )Nz1.2.3.4/255.255.255.255z
1.2.3.4/32)r   rs   r   r‡   )r   r   r   r   ÚtestSlash32ConstructorZ  s    
z%IpaddrUnitTest.testSlash32Constructorc             C   s   |   tt d¡ƒd¡ d S )Nz::1/128)r   rs   r   r”   )r   r   r   r   ÚtestSlash128Constructor^  s    z&IpaddrUnitTest.testSlash128Constructorc             C   s   |   tt d¡ƒd¡ d S )Nz1.2.3.4/0.0.0.0z	1.2.3.4/0)r   rs   r   r‡   )r   r   r   r   ÚtestSlash0Constructorb  s    z$IpaddrUnitTest.testSlash0Constructorc             C   s\  t  d¡}t  d¡}t  d¡}t  d¡}t  d¡}t  d¡}t  ||||||g¡}|  t|ƒt  d¡t  d¡g¡ t  d¡}t  d¡}t  d¡}t  d¡}t  ||||g¡}|  t|ƒt  d¡g¡ t  d¡}t  d	¡}t  d
¡}t  d¡}t  d¡}t  d¡}t  ||||||g¡}|  t|ƒt  d¡t  d¡g¡ t  ||g¡}|  t|ƒt  d¡g¡ t  d¡ }}	|  tt  ||	g¡ƒ|g¡ t  d¡ }}	|  tt  ||	g¡ƒt  d¡g¡ t  d¡}t  d¡}t  d¡}t  |||g¡}|  t|ƒ|g¡ t  d¡t  d¡ft  d¡t  d¡ft  d¡t  d¡fg}
x&|
D ]\}}|  	t
t j||g¡ q6W d S )Nz1.1.1.0z1.1.1.1z1.1.1.2z1.1.1.3z1.1.1.4z
1.1.1.0/30z
1.1.1.4/32z
1.1.0.0/24z
1.1.1.0/24z
1.1.2.0/24z
1.1.3.0/24z
1.1.4.0/24z
1.1.0.0/22z
1.1.0.0/23z
1.1.1.1/32z
2001::/100z
2001::/120z	2001::/96z::1z
1.1.0.0/32z
2001::/128)r   rO   Zcollapse_addressesr   rç   rŽ   r    r   r›   r(   r)   )r   rè   ré   rê   Úip4Zip5Zip6Z	collapsedZip_same1Zip_same2Zaddr_tuplesr   r   r   ÚtestCollapsingf  sl    





























zIpaddrUnitTest.testCollapsingc          	   C   sØ  t j}t  d¡}t  d¡}G dd„ dt jƒ}|dƒ}|dƒ}|  tt|||ƒ¡ |  tt||t  d¡ƒ¡ |  t|||ƒƒd t  	d¡¡ t  d¡}|  t|||ƒƒt  	d	¡t  	d¡g¡ t  
d¡}t  
t j
j¡}|  t  d
¡gt|||ƒƒ¡ t  d¡}t  d¡}|  t|||ƒƒd t  	d¡¡ t  d¡}|  t|||ƒƒt  	d¡t  	d¡g¡ |  tt|t  d¡t  d¡ƒ¡ |  tt|t  	d¡t  	d¡ƒ¡ |  tt|t  	d¡t  	d¡ƒ¡ |  tt|t  d¡t  	d¡ƒ¡ d S )Nz1.1.1.0z	1.1.1.255c               @   s   e Zd Zedd„ ƒZdS )z3IpaddrUnitTest.testSummarizing.<locals>.IPv7Addressc             S   s   dS )Né   r   )r   r   r   r   rî   ¾  s    z;IpaddrUnitTest.testSummarizing.<locals>.IPv7Address.versionN)r   r   r   r   rî   r   r   r   r   ÚIPv7Address½  s   r@  z::1r   z
1.1.1.0/24z1.1.1.8z
1.1.1.0/29z	0.0.0.0/0z1::z$1:ffff:ffff:ffff:ffff:ffff:ffff:ffffz1::/16z2::z2::/128z1.1.0.0z::)r   Zsummarize_address_ranger›   rd   r(   r—   rç   r)   r   r    rO   Z	_ALL_ONESrŽ   )r   Z	summarizerè   ré   r@  Zip_invalid1Zip_invalid2r   r   r   ÚtestSummarizingµ  sP    










zIpaddrUnitTest.testSummarizingc             C   sl   |   t d¡t d¡k¡ |   t d¡t d¡k¡ |   t d¡t d¡k¡ |   t d¡t d¡k¡ d S )Nz1.1.1.1z1.1.1.2z::1z::2)r
   r   r›   )r   r   r   r   ÚtestAddressComparisonñ  s    z$IpaddrUnitTest.testAddressComparisonc             C   sp  |   t d¡t d¡k¡ |   t d¡t d¡k ¡ |   t d¡t d¡k ¡ |   t d¡t d¡k ¡ |   t d¡t d¡k¡ |   t d¡t d¡k¡ |   t d¡t d¡k¡ |   t d¡t d¡k¡ |   t d¡t d¡k ¡ |   t d¡t d¡k ¡ |   t d¡t d¡k ¡ |   t d¡t d¡k¡ |   t d¡t d¡k¡ |   t d¡t d¡k¡ d S )	Nz
1.1.1.1/24z
1.1.1.1/16z
1.1.1.2/24z
1.1.1.2/16z::1/64z::1/80z::2/64z::2/48)r
   r   r   )r   r   r   r   ÚtestInterfaceComparisonû  s8    z&IpaddrUnitTest.testInterfaceComparisonc       	      C   sb  t  d¡}t  d¡}t  d¡}|  ||k ¡ |  ||k¡ |  | |¡d¡ |  | |¡d¡ |  | |¡d¡ |  | |¡d¡ |  | |¡d¡ |  | ¡ | ¡ k ¡ t  d¡}t  d¡}t  d	¡}|  ||k ¡ |  ||k¡ |  | |¡d¡ |  | ¡ | ¡ k ¡ |  t| j	j| j
¡ t  d
¡}t  d¡}|  t|j|¡ |  t|j|¡ |  t|j|¡ |  t|j|¡ t  d¡}|  ||k ¡ |  ||k¡ t  d¡}|  ||k ¡ |  ||k ¡ |  ||k¡ |  ||k¡ t  d¡}|  ||k ¡ |  ||k ¡ |  ||k¡ |  ||k¡ t  d¡}t  d¡}t  d¡}t  d¡}||||g}||||g}| ¡  |  ||¡ ||||g}| ¡  |  ||¡ |  | t  d¡¡t¡ |  | t  d¡¡t¡ |  t  d¡t  d¡k¡ |  t  d¡t  d¡k¡ |  t  d¡t  d¡k¡ |  t  d¡t  d¡k¡ |  t  d¡t  d¡k¡ |  t  d¡t  d¡k¡ d S )Nz
1.1.1.0/24z
1.1.1.0/32z
1.1.2.0/24r   r?   r'   z2001:2000::/96z2001:2001::/96z2001:ffff:2000::/96z::/0z	0.0.0.0/0z10.1.2.128/25z10.1.3.0/24z10.1.3.0/25z10.10.10.0/31z
10.10.10.0z10.10.10.2/31z
10.10.10.2z1.1.1.1z1.1.1.2z::1z::2)r   rŽ   r
   r   Zcompare_networksZ_get_networks_keyr   r(   r)   rÕ   rØ   r”   r‡   r¦   r¨   r    r‰   ÚsortZassertIsr›   r­   )	r   rè   ré   rê   rù   rø   r=  rÏ   Zunsortedr   r   r   ÚtestNetworkComparison  s†    














z$IpaddrUnitTest.testNetworkComparisonc             C   s$   |   ttjd¡ |   ttjd¡ d S )Nz192.168.1.1/24z::1/120)r(   r—   r   r    )r   r   r   r   ÚtestStrictNetworksp  s    z!IpaddrUnitTest.testStrictNetworksc             C   sV   t  d¡}t  d¡}t  d¡}|  | j |¡¡ |  | j |¡¡ |  | |¡¡ d S )Nz
1.2.3.0/30z
1.2.2.0/24z1.2.2.64/26)r   rŽ   r
   rÕ   Zoverlapsr‰   )r   r¤   Zother2Zother3r   r   r   ÚtestOverlapst  s    


zIpaddrUnitTest.testOverlapsc             C   sh   d}t  |¡}t  d| ¡}|  t|jƒt|jƒ¡ t  d| ¡}|  |j|j¡ |  t jt jd¡ d S )Nz192.168.0.1z::%sz	::ffff:%sz2001:1.1.1.1:1.1.1.1)	r   r‡   r”   r   rò   rÝ   r¬   r(   r   )r   Zipv4_stringrø   Zv4compat_ipv6Zv4mapped_ipv6r   r   r   ÚtestEmbeddedIpv4|  s    
zIpaddrUnitTest.testEmbeddedIpv4c             C   s4   |   t d¡t d¡¡ |   t d¡t d¡¡ d S )Nz::FFFF:192.0.2.1z::FFFF:c000:201zFFFF::192.0.2.1zFFFF::c000:201)r   r   r›   )r   r   r   r   ÚtestIPv6AddressTooLarge‡  s    z&IpaddrUnitTest.testIPv6AddressTooLargec             C   s$   |   | jjd¡ |   | jjd¡ d S )Nrõ   rö   )r   rÓ   rî   rÖ   )r   r   r   r   ÚtestIPVersion  s    zIpaddrUnitTest.testIPVersionc             C   s$   |   | jjd¡ |   | jjd¡ d S )Nrz   rK   )r   rÔ   Zmax_prefixlenr×   )r   r   r   r   ÚtestMaxPrefixLength“  s    z"IpaddrUnitTest.testMaxPrefixLengthc             C   s`   |   | jjd¡ |   t d¡jd¡ |   | jjd¡ |   t d¡jd¡ |   t d¡jd¡ d S )	Ns   z255.254.253.252s   ÿþýüs    X*Êþ      zffff:2:3:4:ffff::s   ÿÿ   ÿÿ      z::1:0:0:0:0s                  )r   rÓ   Zpackedr   r‡   rÖ   r”   )r   r   r   r   Ú
testPacked—  s    

zIpaddrUnitTest.testPackedc             C   st   t  d¡}t  d¡}t  d¡}t  d¡}|  t jt|ƒ¡ |  t jt|ƒ¡ |  t jt|ƒ¡ |  t jt|ƒ¡ d S )Nz1.2.3.4z	::1.2.3.4)	r   r    r›   r   rŽ   rË   rO   r   rd   )r   Zipv4netZipv4addrZipv6netZipv6addrr   r   r   Ú
testIpType¥  s    



zIpaddrUnitTest.testIpTypec             C   s  |   dt d¡j¡ |   dt d¡j¡ |   dt d¡j¡ |   dt d¡j¡ |   dt d¡j¡ |   dt d¡j¡ |   dt d¡j¡ |   dt d¡j¡ |   dt d	¡j¡ |   dt d
¡j¡ |   dt d¡j¡ |   dt d¡j¡ |   dt d¡j¡ |   dt d¡j¡ |   dt d¡j¡ |   dt d¡j¡ |   dt d¡j¡ |   dt d¡j	¡ |   dt d¡j¡ |   dt d¡j	¡ |   dt 
d¡j¡ |   dt 
d¡j¡ |   dt 
d¡j¡ |   dt 
d¡j¡ |   dt 
d¡j¡ |   dt 
d¡j¡ |   dt 
d¡j¡ |   dt 
d¡j¡ |   dt 
d¡j¡ |   dt 
d	¡j¡ |   dt 
d
¡j¡ |   dt 
d¡j¡ |   dt 
d¡j¡ |  t 
d¡j	¡ |  t 
d¡j	¡ |   dt 
d¡j¡ |   dt 
d¡j¡ |   dt 
d¡j¡ |   dt d¡j¡ d S )NTz224.1.1.1/31Fz	240.0.0.0z192.168.1.1/17z192.169.0.0z10.255.255.255z11.0.0.0z172.31.255.255z
172.32.0.0z169.254.1.0/24z169.254.100.200/24z169.255.100.200/24z127.100.200.254/32z127.42.0.0/16z	128.0.0.0z100.64.0.0/10z192.0.2.128/25z192.0.3.0/24z0.0.0.0z	224.1.1.1z	240.0.0.1z239.255.255.255z192.168.1.1z169.254.100.200z169.255.100.200z	192.0.7.1z203.0.113.1z127.100.200.254z
127.42.0.0)r   r   r   Úis_multicastr    Úis_reservedÚ
is_privateÚis_link_localÚis_loopbackÚ	is_globalr›   Úis_unspecifiedr
   r‰   )r   r   r   r   ÚtestReservedIpv4¯  sx    
















zIpaddrUnitTest.testReservedIpv4c             C   sÔ  |   dt d¡j¡ |   dt dd d ¡j¡ |   dt d¡j¡ |   dt d¡j¡ |   dt d	¡j¡ |   dt d
¡j¡ |   dt d¡j¡ |   dt d¡j¡ |   dt d¡j¡ |   dt d¡j¡ |   dt d¡j¡ |   dt d¡j¡ |   dt d¡j¡ |   dt d¡j¡ |   dt d¡j¡ |   dt d¡j¡ |   dt d¡j¡ |   dt d¡j¡ |   dt d¡j¡ |   dt d¡j¡ |   dt d¡j	¡ |   dt d¡j	¡ |   dt d¡j	¡ |   dt d¡j¡ |   dt d¡j
¡ |   dt d¡j¡ |   dt dd d ¡j¡ |   dt d¡j¡ |   dt d¡j¡ |   dt d	¡j¡ |   dt d
¡j¡ |   dt d¡j¡ |   dt d¡j¡ |   dt d¡j¡ |   dt d¡j¡ |   dt d¡j¡ |   dt d¡j¡ |   dt d¡j¡ |   dt d¡j¡ |   dt d¡j¡ |   dt d¡j¡ |   dt d¡j¡ |   dt d¡j¡ |   dt d¡j¡ |   dt d¡j	¡ |   dt d¡j	¡ |   dt d¡j¡ |   dt d¡j¡ d S )NTzffff::rJ   rK   r'   zff00::Fzfdff::zfecf::zfeff:ffff:ffff:ffff::z
fbf:ffff::zfc00::zfc00:ffff:ffff:ffff::zfbff:ffff::zfe00::zfea0::zfebf:ffff::zfe7f:ffff::zfec0::z	0:0::0:01z::1/127z::z::2z0::0z::1z::/127z2001::1/128z
200::1/128z100::z4000::1/128)r   r   r    rN  Zis_site_localrP  rQ  r   rR  rT  rS  r›   rO  )r   r   r   r   ÚtestReservedIpv6ø  sx    



















zIpaddrUnitTest.testReservedIpv6c             C   sL   |   t d¡jt d¡¡ |   t d¡jd ¡ |   t d¡jt d¡¡ d S )Nz::ffff:192.168.1.1z192.168.1.1z
::c0a8:101z::ffff:c0a8:101)r   r   r›   Zipv4_mapped)r   r   r   r   ÚtestIpv4MappedE  s    
zIpaddrUnitTest.testIpv4Mappedc             C   s  t  d¡}t  d¡}t  d¡}t  d¡}t  d¡}t  d¡}|  tt| |¡ƒƒt  d¡t  d¡g¡ |  tt| |¡¡ |  t	t| |¡¡ |  t	t| |¡¡ |  t| |¡ƒg ¡ |  tt| |¡ƒƒt  d	¡t  d
¡t  d¡t  d¡t  d¡t  d¡t  d¡t  d¡g¡ d S )Nz10.1.1.0/24z10.1.1.0/26z10.2.1.0/24z10.1.1.0z2001:db8::0/32z10.1.1.5/32z10.1.1.64/26z10.1.1.128/25z10.1.1.0/30z10.1.1.4/32z10.1.1.6/31z10.1.1.8/29z10.1.1.16/28z10.1.1.32/27)
r   r    r›   r   rÏ   rç   Zaddress_excluder(   r—   r)   )r   r1  Úaddr2Úaddr3Úaddr4Úaddr5Úaddr6r   r   r   ÚtestAddrExcludeM  s,    





zIpaddrUnitTest.testAddrExcludec          
   C   sæ   |   tt d¡ƒtt d¡ƒ¡ |   tt d¡ƒtt d¡ƒ¡ |   tt d¡ƒtt d¡ƒ¡ |   tt d¡ƒtt tt d¡jƒ¡ƒ¡ t d¡}t d¡}i }d || j< d || j	< d ||< d ||< |  
| j|¡ |  
||¡ d S )Nz10.1.1.0/24z10.1.1.0z1.2.3.4z1::)r   Úhashr   r   r    r›   rò   r÷   rÓ   rÖ   rÃ   )r   rè   ré   Zdummyr   r   r   ÚtestHashe  s$    



zIpaddrUnitTest.testHashc             C   s6   | j }|  d|j¡ | j}|  t|jdd d ¡ d S )Nz
1.2.3.0/24rJ   rK   r'   )rÕ   r   Ú
compressedrØ   r(   r—   Z_string_from_ip_int)r   r   r   r   r   ÚtestIPBasesz  s    zIpaddrUnitTest.testIPBasesc             C   sD   | j }|  d|j¡ |  d|j¡ |  d|j¡ |  dt|ƒ¡ d S )Nz2001:658:22a:cafe::/64z)2001:658:22a:cafe::/ffff:ffff:ffff:ffff::z)2001:658:22a:cafe::/::ffff:ffff:ffff:ffff)rØ   r   Úwith_prefixlenÚwith_netmaskÚwith_hostmaskrs   )r   r   r   r   r   ÚtestIPv6NetworkHelpers€  s    z%IpaddrUnitTest.testIPv6NetworkHelpersc             C   sD   | j }|  d|j¡ |  d|j¡ |  d|j¡ |  dt|ƒ¡ d S )Nz
1.2.3.0/24z1.2.3.0/255.255.255.0z1.2.3.0/0.0.0.255)rÕ   r   rb  rc  rd  rs   )r   r   r   r   r   ÚtestIPv4NetworkHelpers‰  s
    z%IpaddrUnitTest.testIPv4NetworkHelpersc             C   s|   t  d¡}t  |¡}t  d¡}t  |¡}t  d¡}t  d¡}|  ||¡ |  ||¡ |  |t  |¡¡ |  |t  |¡¡ d S )Nz10.1.1.0/24z2001:658:22a:cafe:200::1/64z1.1.1.1z2001:658:22a:cafe:200::1)r   r    r   rO   rd   r   )r   r1  rX  rY  rZ  r[  r\  r   r   r   ÚtestCopyConstructor  s    





z"IpaddrUnitTest.testCopyConstructorc             C   s^   ddddddddd	d
dddddddddœ}x.t | ¡ ƒD ]\}}|  |tt |¡ƒ¡ q8W d S )Nz1:2:3:4:5:6:7:8/128z2001:0:0:4::8/128z2001::4:5:6:7:8/128z2001:0:3:4:5:6:7:8/128z0:0:3::ffff/128z::4:0:0:0:ffff/128z::5:0:0:ffff/128z1::4:0:0:7:8/128z::/128z::/0z::1/128z2001:658:22a:cafe::/66z::102:304/128z1:2:3:4:5:ffff:102:304/128z0:7:6:5:4:3:2:1/128z0:7:6:5:4:3:2:0/128z7:6:5:4:3:2:1:0/128z0:6:5:4:3:2:1:0/128)z1:2:3:4:5:6:7:8z2001:0:0:4:0:0:0:8z2001:0:0:4:5:6:7:8z2001:0:3:4:5:6:7:8z0:0:3:0:0:0:0:ffffz0:0:0:4:0:0:0:ffffz0:0:0:0:5:0:0:ffffz1:0:0:4:0:0:7:8z0:0:0:0:0:0:0:0z0:0:0:0:0:0:0:0/0z0:0:0:0:0:0:0:1z*2001:0658:022a:cafe:0000:0000:0000:0000/66z	::1.2.3.4z1:2:3:4:5:ffff:1.2.3.4z::7:6:5:4:3:2:1z::7:6:5:4:3:2:0z7:6:5:4:3:2:1::z0:6:5:4:3:2:1::)rç   Úitemsr   rs   r   r”   )r   Ztest_addressesZuncompressedr`  r   r   r   ÚtestCompressIPv6Address  s*    z&IpaddrUnitTest.testCompressIPv6Addressc             C   sx   t  d¡}t  d¡}t  d¡}t  d¡}|  d|j¡ |  dt  d¡j¡ |  d|j¡ |  d	|j¡ |  d|j¡ d S )
Nz2001::1z2001:0:5ef5:79fd:0:59d:a0e5:ba1z	2001::/96z192.168.178.1z+2001:0000:0000:0000:0000:0000:0000:0001/128z+0000:0000:0000:0000:0000:0000:0000:0001/128z::1/128z'2001:0000:5ef5:79fd:0000:059d:a0e5:0ba1z*2001:0000:0000:0000:0000:0000:0000:0000/96)r   r”   rd   r   rO   r   Zexploded)r   r1  rX  rY  rZ  r   r   r   ÚtestExplodeShortHandIpStr·  s    



z(IpaddrUnitTest.testExplodeShortHandIpStrc             C   s4   t  d¡}t  d¡}|  d|j¡ |  d|j¡ d S )Nz	127.0.0.1z2001:db8::1z1.0.0.127.in-addr.arpazH1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.8.b.d.0.1.0.0.2.ip6.arpa)r   rO   rd   r   Zreverse_pointer)r   r1  rX  r   r   r   ÚtestReversePointerÇ  s
    

z!IpaddrUnitTest.testReversePointerc             C   s(   |   dt| jƒ¡ |   dt| jƒ¡ d S )Nil	         à/YE ƒ   )r   rò   rÓ   rÖ   )r   r   r   r   ÚtestIntRepresentationÏ  s    z$IpaddrUnitTest.testIntRepresentationc             C   s,   |   t d¡jd¡ |   t d¡jd¡ d S )Nr'   rõ   rö   )r   r   r    rî   r   )r   r   r   r   ÚtestForceVersionÔ  s    zIpaddrUnitTest.testForceVersionc             C   sd   |   | jjd¡ |   | jjd¡ |   | jjd¡ |   | jjd¡ |   | jjd¡ |   | jjd¡ d S )Nz
1.2.3.4/24z1.2.3.4/255.255.255.0z1.2.3.4/0.0.0.255z2001:658:22a:cafe:200::1/64z.2001:658:22a:cafe:200::1/ffff:ffff:ffff:ffff::z.2001:658:22a:cafe:200::1/::ffff:ffff:ffff:ffff)r   rÔ   rb  rc  rd  r×   )r   r   r   r   ÚtestWithStarØ  s    




zIpaddrUnitTest.testWithStarc             C   s„  |   d| jj¡ |   d| jj¡ |   d| jj¡ |  | jjt d¡¡ |  | jjt d¡¡ |  | jjt d¡¡ |  	d| jj¡ |  	d| jj¡ |   d| j
j¡ |   d| j
j¡ |  | j
jt d¡¡ |  | jjjt d¡¡ |  | j
jt d¡¡ |  | j
jt d	¡¡ |  | jjjt d¡¡ |  | jjjt d	¡¡ |  	d| j
j¡ |  	d| j
j¡ |  	d| jjj¡ |  	d| jjj¡ d S )
Nró   r  r|   z1.2.3.0z	1.2.3.255z	0.0.0.255z2001:658:22a:cafe::z%2001:658:22a:cafe:ffff:ffff:ffff:ffffz::ffff:ffff:ffff:ffff)rÆ   rÕ   Ú_cacher   ró   r   rO   r  r|   rÃ   rØ   rd   r×   rŸ   )r   r   r   r   ÚtestNetworkElementCachingè  s>    




z(IpaddrUnitTest.testNetworkElementCachingc             C   sˆ   t  d¡}t  d¡}d}|  ||ft  |¡j¡ d}|  t  |¡j¡ d}|  t  |¡j¡ t  d¡}|  t  d¡t  d¡f|j¡ d S )	Nz65.54.227.120z
192.0.2.45z'2001:0000:4136:e378:8000:63bf:3fff:fdd2z#2000::4136:e378:8000:63bf:3fff:fdd2z'2001:0001:4136:e378:8000:63bf:3fff:fdd2z2001:0:5ef5:79fd:0:59d:a0e5:ba1z94.245.121.253z95.26.244.94)r   rO   r   r›   Zteredor‰   rd   )r   ZserverZclientZteredo_addrÚbad_addrr   r   r   Ú
testTeredo  s    




zIpaddrUnitTest.testTeredoc             C   s8   t  d¡}t  d¡}|  t  d¡|j¡ |  |j¡ d S )Nz2002:ac1d:2d64::1z2000:ac1d:2d64::1z172.29.45.100)r   r›   r   rO   Z	sixtofourr‰   )r   Zsixtofouraddrrq  r   r   r   Útestsixtofour'  s
    

zIpaddrUnitTest.testsixtofourN)Jr   r   r   rÙ   rÚ   rÞ   râ   rå   ræ   rë   rð   rñ   rô   rú   rû   rü   rÿ   r  r  r  r  r  r  r  r  r  r   r%  r&  r'  r*  r,  r-  r.  r/  r2  r5  r7  r8  r9  r:  r;  r<  r>  rA  rB  rC  rE  rF  rG  rH  rI  rJ  rK  rL  rM  rU  rV  rW  r]  r_  ra  re  rf  rg  ri  rj  rk  rl  rm  rn  rp  rr  rs  r   r   r   r   rÒ   6  sŽ   ?2
			

!O<
V
IM	-rÒ   Ú__main__)Zunittestr#   r   Ú	functoolsr*   r1   r   r`   ZTestCaser   r    r8   rI   rN   rc   rr   r†   rˆ   r‘   r“   r•   r–   Útotal_orderingr¢   r§   r©   rÒ   r   Úmainr   r   r   r   Ú<module>   sL   6#(` O6?(           
