
    <e                    L   d 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ddlm	Z	m
Z
  G d dej                  Z G d d          Z G d d	e          Z G d
 de          Z G d dee          Z G d dee          Z G d de          Z G d dee          Z G d dee          Z G d de          Z G d dee          Z G d dee          Z G d de          Z G d dej                  Z G d  d!ej                  Zed"k    r ej                     dS dS )#zUnittest for ipaddress module.    N)LARGESTSMALLESTc                   V    e Zd Zed             Zej        d             Zd Zd Z	d Z
dS )BaseTestCasec                     t           N)NotImplementedErrorselfs    */usr/lib/python3.11/test/test_ipaddress.pyfactoryzBaseTestCase.factory$   s    !!    c              '      K   |r||z  }|                      ||          }|5 }|V  ddd           n# 1 swxY w Y   |j        j        !|                     |j        j                   dS dS )z{
        Ensure exception does not display a context by default

        Wraps unittest.TestCase.assertRaisesRegex
        N)assertRaisesRegex	exception__context__
assertTrue__suppress_context__)r   exc_typedetailsargscmexcs         r   assertCleanErrorzBaseTestCase.assertCleanError(   s        	%nG##Hg66 	3III	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 =$0OOCM>????? 10s   377c                 4     | j         t          j        |g|R  S )z Ensure a clean AddressValueError)r   	ipaddressAddressValueErrorr   r   r   s      r   assertAddressErrorzBaseTestCase.assertAddressError8   .    $t$Y%@%,5/35 5 5 	5r   c                 4     | j         t          j        |g|R  S )z Ensure a clean NetmaskValueError)r   r   NetmaskValueErrorr   s      r   assertNetmaskErrorzBaseTestCase.assertNetmaskError=   r    r   c                 ~    |                      |                     |          |                     |                     dS )z8Check constructor arguments produce equivalent instancesN)assertEqualr   r   lhsrhss      r   assertInstancesEqualz!BaseTestCase.assertInstancesEqualB   s6    c**DLL,=,=>>>>>r   N)__name__
__module____qualname__propertyr   
contextlibcontextmanagerr   r   r#   r)    r   r   r   r      s~        & " " X" @ @ @5 5 5
5 5 5
? ? ? ? ?r   r   c                   &    e Zd Zd Zd Zd Zd ZdS )CommonTestMixinc                     |                      d          5  |                     d           d d d            d S # 1 swxY w Y   d S )NAddress cannot be empty r   r   r
   s    r   test_empty_addressz"CommonTestMixin.test_empty_addressI   s    $$%>?? 	 	LL	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s   9= =c                     |                      t          j        t          d                              5  |                     d           d d d            d S # 1 swxY w Y   d S )Nz1.0g      ?)r   reescapereprr   r
   s    r   test_floats_rejectedz$CommonTestMixin.test_floats_rejectedM   s    $$RYtE{{%;%;<< 	 	LL	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	   AAAc                 H   |                      t          t          j        |                     d                     |                      t          t
          |                     d                     |                      t          t          |                     d                     d S )N   )assertRaises	TypeErroroperatorindexr   hexbytesr
   s    r   test_not_an_index_issue15559z,CommonTestMixin.test_not_an_index_issue15559Q   sr     	)X^T\\!__EEE)S$,,q//:::)UDLLOO<<<<<r   c                 D   t          t          j        dz             D ]}|                     |          5  |                     |          }t          j        t          j        ||                    }|                     ||           d d d            n# 1 swxY w Y   d S )Nr?   )proto)rangepickleHIGHEST_PROTOCOLsubTestr   loadsdumpsr%   )r   addrrH   xys        r   pickle_testzCommonTestMixin.pickle_testX   s    62Q677 	' 	'EE** ' 'LL&&La!7!788  A&&&' ' ' ' ' ' ' ' ' ' ' ' ' ' '	' 	's   ABB	B	N)r*   r+   r,   r7   r<   rF   rR   r0   r   r   r2   r2   G   sP            = = =' ' ' ' 'r   r2   c                   2    e Zd Zd Zd Zd Zd Zd Zd ZdS )CommonTestMixin_v4c                     d}g d}|D ]r}|                      |          5  |                     |          5  |                     |           d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   sd S )Nz(Leading zeros are not permitted in '\d+')z000.000.000.000z192.168.000.001z016.016.016.016z001.000.008.016z	01.2.3.40z	1.02.3.40z	1.2.03.40z	1.2.3.040)address)rL   r   r   )r   msg	addressesrV   s       r   test_leading_zerosz%CommonTestMixin_v4.test_leading_zerosb   s   9	
 	
 	
	 ! 	* 	*Gg.. * *,,S11 * *LL)))* * * * * * * * * * * * * * ** * * * * * * * * * * * * * *	* 	*s4   A0AA0AA0 A!A00A4	7A4	c                 ^    |                      dd           |                      dd           d S )Nr   0.0.0.0    P 192.168.0.1r)   r
   s    r   test_intzCommonTestMixin_v4.test_intt   s4    !!!Y///!!*m<<<<<r   c                     |                      t                              d          d           |                      t                              d          d           d S )N00000000r[   c0a80001r]   )r)   rE   fromhexr
   s    r   test_packedzCommonTestMixin_v4.test_packedx   sL    !!%--
";";YGGG!!%--
";";]KKKKKr   c                     d}|                      t          j        |                    5  |                     d           d d d            d S # 1 swxY w Y   d S )Nz,-1 (< 0) is not permitted as an IPv4 addressr   r9   r:   r   r   rW   s     r   test_negative_ints_rejectedz.CommonTestMixin_v4.test_negative_ints_rejected|       <$$RYs^^44 	 	LL	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	   AAAc                     d}|                      t          j        |dz                      5  |                     d           d d d            d S # 1 swxY w Y   d S )Nz1%d (>= 2**32) is not permitted as an IPv4 addressl        rg   rh   s     r   test_large_ints_rejectedz+CommonTestMixin_v4.test_large_ints_rejected   s    A$$RYsU{%;%;<< 	  	 LL	  	  	  	  	  	  	  	  	  	  	  	  	  	  	  	  	  	 s   AAAc                 >      fd} |d            |d           d S )Nc                     d| z  }d}                     t          j        ||| fz                      5                      |           d d d            d S # 1 swxY w Y   d S )N    z4%r (len %d != 4) is not permitted as an IPv4 addressrg   lengthrO   rW   r   s      r   assertBadLengthzBCommonTestMixin_v4.test_bad_packed_length.<locals>.assertBadLength   s    6>DHC((3$3G)H)HII # #T"""# # # # # # # # # # # # # # # # # #r=         r0   r   rs   s   ` r   test_bad_packed_lengthz)CommonTestMixin_v4.test_bad_packed_length   sD    	# 	# 	# 	# 	# 	r   N)	r*   r+   r,   rY   r_   rd   ri   rm   rw   r0   r   r   rT   rT   `   sq        * * *$= = =L L L  
     
    r   rT   c                   >    e Zd Zd Zd Zd Zd Zd Zd Zd Z	d Z
d	S )
CommonTestMixin_v6c                 ^    |                      dd           |                      dd           d S )Nz
0000::0000::z000::c0a8:0001::c0a8:1r^   r
   s    r   rY   z%CommonTestMixin_v6.test_leading_zeros   s5    !!,555!!"2J?????r   c                 ^    |                      dd           |                      dd           d S )Nr   r{   r\   r|   r^   r
   s    r   r_   zCommonTestMixin_v6.test_int   s4    !!!T***!!*j99999r   c                 8   dt                               d          z   }|                     |d           dt                               d          z   }|                     |d           t                               d          dz   }|                     |d           d S )Ns               ra   r{   rb   r|   zc0a8:1::)rE   rc   r)   r   rO   s     r   rd   zCommonTestMixin_v6.test_packed   s    %--
333!!$---%--
333!!$
333}}Z((83!!$
33333r   c                     d}|                      t          j        |                    5  |                     d           d d d            d S # 1 swxY w Y   d S )Nz,-1 (< 0) is not permitted as an IPv6 addressrf   rg   rh   s     r   ri   z.CommonTestMixin_v6.test_negative_ints_rejected   rj   rk   c                     d}|                      t          j        |ddz  z                      5  |                     ddz             d d d            d S # 1 swxY w Y   d S )Nz2%d (>= 2**128) is not permitted as an IPv6 address      rg   rh   s     r   rm   z+CommonTestMixin_v6.test_large_ints_rejected   s    B$$RYsQV|%<%<== 	! 	!LLC   	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	!s   AAAc                 >      fd} |d            |d           d S )Nc                     d| z  }d}                     t          j        ||| fz                      5                      |                               |           d d d            d S # 1 swxY w Y   d S )Nrp   z5%r (len %d != 16) is not permitted as an IPv6 addressrg   rq   s      r   rs   zBCommonTestMixin_v6.test_bad_packed_length.<locals>.assertBadLength   s    6>DIC((3$3G)H)HII # #T"""T"""# # # # # # # # # # # # # # # # # #s   +A--A14A1      r0   rv   s   ` r   rw   z)CommonTestMixin_v6.test_bad_packed_length   sD    	# 	# 	# 	# 	# 	r   c                     d}|                      d|          5  |                     |           d d d            d S # 1 swxY w Y   d S )Nz::1%Invalid IPv6 address: "%r"r6   r   rV   s     r   test_blank_scope_idz&CommonTestMixin_v6.test_blank_scope_id   s    $$%A7KK 	" 	"LL!!!	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	"   <A A c                     d}|                      d|          5  |                     |           d d d            d S # 1 swxY w Y   d S )Nz
::1%scope%r   r6   r   s     r   "test_invalid_scope_id_with_percentz5CommonTestMixin_v6.test_invalid_scope_id_with_percent   s    $$%A7KK 	" 	"LL!!!	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	"r   N)r*   r+   r,   rY   r_   rd   ri   rm   rw   r   r   r0   r   r   ry   ry      s        @ @ @: : :4 4 4  
! ! !
	 	 	" " "
" " " " "r   ry   c                   R    e Zd Zej        Zd Zd Zd Zd Z	d Z
d Zd Zd Zd	 Zd
S )AddressTestCase_v4c                     t          j        d          }g d}|D ])\  }}|                     |t          ||                     *d S )N1.2.3.42))b 00000001000000100000001100101010)nr   )rP   0102032a)X0102032A)_b'0000_0001_0000_0010_0000_0011_0010_1010)_nr   )_x	0102_032a)_X	0102_032A)#b"0b00000001000000100000001100101010)#nr   )#x
0x0102032a)#X
0X0102032A)#_b)0b0000_0001_0000_0010_0000_0011_0010_1010)#_nr   )#_x0x0102_032a)#_X0X0102_032A)sr   )r5   r   )r   IPv4Addressr%   format)r   v4v4_pairsfmttxts        r   test_formatzAddressTestCase_v4.test_format   sc    ":..
 
 
( # 	3 	3JS#S&S//2222	3 	3r   c                     d}|                      d|          5  t          j        |           d d d            d S # 1 swxY w Y   d S )Nz127.0.0.1/24Unexpected '/' in %rr   r   r   r   s     r   test_network_passed_as_addressz1AddressTestCase_v4.test_network_passed_as_address   s    $$%;TBB 	( 	(!$'''	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	(s   ;??c                      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                                          d|           5  t          j        |            d d d            d S # 1 swxY w Y   d S )NzExpected 4 octets in %rr   rO   r   s    r   assertBadSplitzAAddressTestCase_v4.test_bad_address_split.<locals>.assertBadSplit   s    (()BDII , ,%d+++, , , , , , , , , , , , , , , , , ,   :>>z127.0.1z42.42.42.42.42z42.42.42z42.42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016000z0x0a.0x0a.0x0az	0x0a.0x0a0x0a.bogusz	bogus.com10001000000000000000z192.168.0.1.comr0   r   r   s   ` r   test_bad_address_splitz)AddressTestCase_v4.test_bad_address_split   s   	, 	, 	, 	, 	, 	y!!!'(((z"""wt~&&&~&&&'(((~&&&'(((}%%%y!!!uu'((({###vsw{###v)***()))))r   c                 >      fd} |d            |d           d S )Nc                                          d|           5  t          j        |            d d d            d S # 1 swxY w Y   d S )NzEmpty octet not permitted in %rr   r   s    r   assertBadOctetz;AddressTestCase_v4.test_empty_octet.<locals>.assertBadOctet  s    (()J)-/ / , ,%d+++, , , , , , , , , , , , , , , , , ,r   z	42..42.42z...r0   r   r   s   ` r   test_empty_octetz#AddressTestCase_v4.test_empty_octet   sD    	, 	, 	, 	, 	,
 	{###ur   c                       fd} |dd            |dd            |dd            |dd	            |d
d            |dd            |dd            |dd            |dd           d S )Nc                     d|d| }                     t          j        |                    5  t          j        |            d d d            d S # 1 swxY w Y   d S )Nz!Only decimal digits permitted in  in r   r9   r:   r   r   rO   octetrW   r   s      r   r   zBAddressTestCase_v4.test_invalid_characters.<locals>.assertBadOctet
  s     AFMC((388 , ,%d+++, , , , , , , , , , , , , , , , , ,s   AAAz0x0a.0x0a.0x0a.0x0ar   z0xa.0x0a.0x0a.0x0a0xaz42.42.42.-0-0z42.42.42.+0+0z42.42.42.-42z-42z
+1.+2.+3.4+1z	1.2.3.4e04e0	1.2.3.4::z4::1.a.2.3ar0   r   s   ` r   test_invalid_charactersz*AddressTestCase_v4.test_invalid_characters	  s    	, 	, 	, 	, 	,
 	,f555+U333}d+++}d+++~u---|T***{E***{E***y#&&&&&r   c                 B      fd} |dd            |dd           d S )Nc                     d}                     t          j        ||| fz                      5  t          j        |            d d d            d S # 1 swxY w Y   d S )Nz*At most 3 characters permitted in %r in %rr   r   s      r   r   z<AddressTestCase_v4.test_octet_length.<locals>.assertBadOctet  s    >C((3%3F)G)GHH , ,%d+++, , , , , , , , , , , , , , , , , ,   AAAz0000.000.000.0000000z12345.67899.-54321.-9876512345r0   r   s   ` r   test_octet_lengthz$AddressTestCase_v4.test_octet_length  sJ    	, 	, 	, 	, 	,
 	)62222G<<<<<r   c                 B      fd} |dd            |dd           d S )Nc                     d|| fz  }                     t          j        |                    5  t          j        |            d d d            d S # 1 swxY w Y   d S )Nz$Octet %d (> 255) not permitted in %rr   r   s      r   r   z;AddressTestCase_v4.test_octet_limit.<locals>.assertBadOctet#  s    8E4=HC((388 , ,%d+++, , , , , , , , , , , , , , , , , ,r   z	257.0.0.0i  z192.168.0.999i  r0   r   s   ` r   test_octet_limitz#AddressTestCase_v4.test_octet_limit"  sH    	, 	, 	, 	, 	,
 	{C(((,,,,,r   c                 0    |                      d           d S N	192.0.2.1rR   r
   s    r   test_picklezAddressTestCase_v4.test_pickle+  s    %%%%%r   c                 T    t          j        |                     d                     d S r   weakrefrefr   r
   s    r   test_weakrefzAddressTestCase_v4.test_weakref.  s$    DLL--.....r   N)r*   r+   r,   r   r   r   r   r   r   r   r   r   r   r   r   r0   r   r   r   r      s        #G3 3 32( ( (
* * *:  ' ' ' = = =- - -& & &/ / / / /r   r   c                   p    e Zd Zej        Zd Zd Zd Zd Z	d Z
d Zd Zd Zd	 Zd
 Zd Zd Zd Zd ZdS )AddressTestCase_v6c                     t          j        d          }g d}|D ])\  }}|                     |t          ||                     *d S )Nz
::1.2.3.42))r   ڀ00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000100000001100101010)r    0000000000000000000000000102032a)rP   r   )r    0000000000000000000000000102032A)r   ڟ0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0001_0000_0010_0000_0011_0010_1010)r   '0000_0000_0000_0000_0000_0000_0102_032a)r   r   )r   '0000_0000_0000_0000_0000_0000_0102_032A)r   ڂ0b00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000100000001100101010)r   "0x0000000000000000000000000102032a)r   r   )r   "0X0000000000000000000000000102032A)r   ڡ0b0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0001_0000_0010_0000_0011_0010_1010)r   )0x0000_0000_0000_0000_0000_0000_0102_032a)r   r   )r   )0X0000_0000_0000_0000_0000_0000_0102_032A)r   	::102:32a)r5   r   )r   IPv6Addressr%   r   )r   v6v6_pairsr   r   s        r   r   zAddressTestCase_v6.test_format5  sd    "<00!
 !
 !
F # 	3 	3JS#S&S//2222	3 	3r   c                 >      fd} |d            |d           d S )Nc                     d}                     ||           5  t          j        |            d d d            d S # 1 swxY w Y   d S )Nr   )r   r   r   rO   rW   r   s     r   r   zIAddressTestCase_v6.test_network_passed_as_address.<locals>.assertBadSplit_  s    (C((d33 , ,%d+++, , , , , , , , , , , , , , , , , ,s   <A A z::1/24z::1%scope_id/24r0   r   s   ` r   r   z1AddressTestCase_v6.test_network_passed_as_address^  sE    	, 	, 	, 	, 	, 	x   ()))))r   c                       fd} |d            |d            |d            |d            |d            |d           d S )Nc                     d}                     ||                     d          d                   5  t          j        |            d d d            d S # 1 swxY w Y   d S )NzAt least 3 parts expected in %r%r   r   splitr   r   r  s     r   r   zUAddressTestCase_v6.test_bad_address_split_v6_not_enough_parts.<locals>.assertBadSplitg  s    3C((djjooa.@AA , ,%d+++, , , , , , , , , , , , , , , , , ,   AAA:z:1z	FEDC:9878z:%scopez:1%scopezFEDC:9878%scoper0   r   s   ` r   *test_bad_address_split_v6_not_enough_partsz=AddressTestCase_v6.test_bad_address_split_v6_not_enough_partsf  s    	, 	, 	, 	, 	,
 	st{###y!!!z"""()))))r   c                       fd} |d            |d            |d            |d            |d            |d            |d            |d	            |d
            |d           d S )Nc                     d}                     ||                     d          d                   5  t          j        |            d d d            d S # 1 swxY w Y   d S )Nz At most 8 colons permitted in %rr  r   r	  r  s     r   r   zTAddressTestCase_v6.test_bad_address_split_v6_too_many_colons.<locals>.assertBadSplitt      4C((djjooa.@AA , ,%d+++, , , , , , , , , , , , , , , , , ,r  z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.42z9:8:7:6:5:4:3::2:1%scopez10:9:8:7:6:5:4:3:2:1%scopez::8:7:6:5:4:3:2:1%scopez8:7:6:5:4:3:2:1::%scopez"10:9:8:7:6:5:4:3:42.42.42.42%scoper0   r   s   ` r   )test_bad_address_split_v6_too_many_colonsz<AddressTestCase_v6.test_bad_address_split_v6_too_many_colonss  s    	, 	, 	, 	, 	,
 	+,,,-...*+++*+++56661222344401110111;<<<<<r   c                       fd} |d            |d            |d            |d            |d            |d            |d            |d	            |d
            |d           d S )Nc                     d}                     ||                     d          d                   5  t          j        |            d d d            d S # 1 swxY w Y   d S )Nz+Exactly 8 parts expected without '::' in %rr  r   r	  r  s     r   r   zSAddressTestCase_v6.test_bad_address_split_v6_too_many_parts.<locals>.assertBadSplit  s    ?C((djjooa.@AA , ,%d+++, , , , , , , , , , , , , , , , , ,r  z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.42z3ffe:0:0:0:0:0:0:0:1%scopez9:8:7:6:5:4:3:2:1%scopez7:6:5:4:3:2:1%scopez9:8:7:6:5:4:3:42.42.42.42%scopez7:6:5:4:3:42.42.42.42%scoper0   r   s   ` r   (test_bad_address_split_v6_too_many_partsz;AddressTestCase_v6.test_bad_address_split_v6_too_many_parts  s    	, 	, 	, 	, 	,
 	-...*+++'''2333.///34440111,---8999455555r   c                 >      fd} |d            |d           d S )Nc                     d}                     ||                     d          d                   5  t          j        |            d d d            d S # 1 swxY w Y   d S )Nz.Expected at most 7 other parts with '::' in %rr  r   r	  r  s     r   r   zeAddressTestCase_v6.test_bad_address_split_v6_too_many_parts_with_double_colon.<locals>.assertBadSplit  s    BC((djjooa.@AA , ,%d+++, , , , , , , , , , , , , , , , , ,r  z1:2:3:4::5:6:7:8z1:2:3:4::5:6:7:8%scoper0   r   s   ` r   :test_bad_address_split_v6_too_many_parts_with_double_colonzMAddressTestCase_v6.test_bad_address_split_v6_too_many_parts_with_double_colon  sF    	, 	, 	, 	, 	,
 	)***/00000r   c                      fd} |d            |d            |d            |d            |d            |d            |d            |d	            |d
            |d            |d            |d            |d            |d            |d            |d            |d            |d            |d            |d           d S )Nc                     d}                     ||                     d          d                   5  t          j        |            d d d            d S # 1 swxY w Y   d S )Nz At most one '::' permitted in %rr  r   r	  r  s     r   r   zZAddressTestCase_v6.test_bad_address_split_v6_repeated_double_colon.<locals>.assertBadSplit  r  r  z
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:::1z3ffe::1::1%scopez1::2::3::4:5%scopez2001::db:::1%scopez3ffe::1::%scopez::3ffe::1%scopez:3ffe::1::1%scopez3ffe::1::1:%scopez:3ffe::1::1:%scopez	:::%scopez2001:db8:::1%scoper0   r   s   ` r   /test_bad_address_split_v6_repeated_double_colonzBAddressTestCase_v6.test_bad_address_split_v6_repeated_double_colon  sm   	, 	, 	, 	, 	,
 	|$$$~&&&~&&&{###{###}%%%}%%%~&&&u~&&&)***+,,,+,,,()))()))*+++*++++,,,{###+,,,,,r   c                       fd} |d            |d            |d            |d            |d            |d            |d            |d	           d S )
Nc                     d}                     ||                     d          d                   5  t          j        |            d d d            d S # 1 swxY w Y   d S )Nz0Leading ':' only permitted as part of '::' in %rr  r   r	  r  s     r   r   zRAddressTestCase_v6.test_bad_address_split_v6_leading_colon.<locals>.assertBadSplit  s    DC((djjooa.@AA , ,%d+++, , , , , , , , , , , , , , , , , ,r  z:2001:db8::1z:1:2:3:4:5:6:7z:1:2:3:4:5:6:z:6:5:4:3:2:1::z:2001:db8::1%scopez:1:2:3:4:5:6:7%scopez:1:2:3:4:5:6:%scopez:6:5:4:3:2:1::%scoper0   r   s   ` r   'test_bad_address_split_v6_leading_colonz:AddressTestCase_v6.test_bad_address_split_v6_leading_colon  s    	, 	, 	, 	, 	,
 	~&&&'(((''''(((+,,,-...,----.....r   c                       fd} |d            |d            |d            |d            |d            |d            |d            |d	           d S )
Nc                     d}                     ||                     d          d                   5  t          j        |            d d d            d S # 1 swxY w Y   d S )Nz1Trailing ':' only permitted as part of '::' in %rr  r   r	  r  s     r   r   zSAddressTestCase_v6.test_bad_address_split_v6_trailing_colon.<locals>.assertBadSplit  s    EC((djjooa.@AA , ,%d+++, , , , , , , , , , , , , , , , , ,r  z2001:db8::1:z1:2:3:4:5:6:7:z
::1.2.3.4:z::7:6:5:4:3:2:z2001:db8::1:%scopez1:2:3:4:5:6:7:%scopez::1.2.3.4:%scopez::7:6:5:4:3:2:%scoper0   r   s   ` r   (test_bad_address_split_v6_trailing_colonz;AddressTestCase_v6.test_bad_address_split_v6_trailing_colon  s    	, 	, 	, 	, 	,
 	~&&&'(((|$$$'(((+,,,-...)***-.....r   c                      fd} |dd            |dd            |dd            |dd	            |d
d            |dd            |dd            |dd            |dd	            |dd           d S )Nc                                          d||                     d          d                   5  t          j        |            d d d            d S # 1 swxY w Y   d S )Nz%s in %rr  r   r	  )rO   v4_errorr   s     r   assertBadAddressPartzDAddressTestCase_v6.test_bad_v4_part_in.<locals>.assertBadAddressPart  s    ((Xtzz#q?QRR , ,%d+++, , , , , , , , , , , , , , , , , ,s   AAAz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'z3ffe::1.net%scopez3ffe::127.0.1%scopez::1.2.3%scopez::1.2.3.4.5%scopez3ffe::1.1.1.net%scoper0   )r   r$  s   ` r   test_bad_v4_part_inz&AddressTestCase_v6.test_bad_v4_part_in  s1   	, 	, 	, 	, 	, 	],JKKK_=	? 	? 	?Y;	= 	= 	=]?	A 	A 	A..	/ 	/ 	/ 	02PQQQ2=	? 	? 	?_;	= 	= 	=0?	A 	A 	A4.	/ 	/ 	/ 	/ 	/r   c                 2     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                     d|d|                      d          d         }                    t          j        |                    5  t	          j        |            d d d            d S # 1 swxY w Y   d S )NzOnly hex digits permitted in r   r  r   )r
  r   r9   r:   r   r   rO   partrW   r   s      r   assertBadPartzAAddressTestCase_v6.test_invalid_characters.<locals>.assertBadPart  s     =ATT4::c??STCUCUVC((388 , ,%d+++, , , , , , , , , , , , , , , , , ,s   
A,,A03A0z
3ffe::googgoogz3ffe::-0r   z3ffe::+0r   z3ffe::-1-1r   1.2.3.41234:axy::baxyz3ffe::goog%scopez3ffe::-0%scopez3ffe::+0%scopez3ffe::-1%scopez1.2.3.4::%scope1234:axy::b%scoper0   r   r*  s   ` r   r   z*AddressTestCase_v6.test_invalid_characters  s   	, 	, 	, 	, 	,
 	lF+++j$'''j$'''j$'''k9---mU+++(&111&---&---&---'333)511111r   c                       fd} |dd            |dd            |dd            |dd	            |d
d            |dd            |dd            |dd	           d S )Nc                     d}                     |||                     d          d                   5  t          j        |            d d d            d S # 1 swxY w Y   d S )Nz*At most 4 characters permitted in %r in %rr  r   r	  r(  s      r   r*  z:AddressTestCase_v6.test_part_length.<locals>.assertBadPart  s    >C((dDJJsOOA4FGG , ,%d+++, , , , , , , , , , , , , , , , , ,s   AAAz::0000000000z3ffe::1000010000z02001:db8::02001z2001:888888::1888888z::00000%scopez3ffe::10000%scopez02001:db8::%scopez2001:888888::1%scoper0   r1  s   ` r   test_part_lengthz#AddressTestCase_v6.test_part_length  s    	, 	, 	, 	, 	,
 	i)))mW---mW---&111ow///)7333)7333,h77777r   c                 0    |                      d           d S )N
2001:db8::r   r
   s    r   r   zAddressTestCase_v6.test_pickle  s    &&&&&r   c                     t          j        |                     d                     t          j        |                     d                     d S )Nr:  2001:db8::%scoper   r
   s    r   r   zAddressTestCase_v6.test_weakref"  sA    DLL..///DLL!34455555r   N)r*   r+   r,   r   r   r   r   r   r  r  r  r  r  r  r   r%  r   r8  r   r   r0   r   r   r   r   2  s        #G'3 '3 '3R* * ** * *= = =(6 6 6(1 1 1- - -8/ / / / / / / / /62 2 2(8 8 8 ' ' '6 6 6 6 6r   r   c                   <    e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
d	S )
NetmaskTestMixin_v4;Input validation on interfaces and networks is very similarc                     dD ]}|                      |          }|                     t          |          d           |                     t          |j                  d           |                     t          |j                  d           d S )N)r-     
1.2.3.4/32255.255.255.255r[   r   r%   strnetmaskhostmask)r   rV   nets      r   test_no_maskz NetmaskTestMixin_v4.test_no_mask*  s    C 	; 	;G,,w''CSXX|444S--/@AAAS..	::::		; 	;r   c                     d}|                      d|z            5  |                     |           d d d            d S # 1 swxY w Y   d S )Nz1.2.3.4/32/24Only one '/' permitted in %rr6   r   s     r   test_split_netmaskz&NetmaskTestMixin_v4.test_split_netmask3  s    $$%Cd%JKK 	 	LL	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s   >AAc                       fd} |dd            |dd            |dd            |dd            |dd            |d	d
            |dt          j        d                     d S )Nc                                          |          5                      |            d d d            d S # 1 swxY w Y   d S r   r6   rO   r   r   s     r   assertBadAddresszANetmaskTestMixin_v4.test_address_errors.<locals>.assertBadAddress9      ((11 # #T"""# # # # # # # # # # # # # # # # # #   :>>/r4   /8r   zExpected 4 octets
google.com10/8	::1.2.3.4zOnly decimal digitsz	1.2.3.256z256 (> 255))r9   r:   r   rQ  s   ` r   test_address_errorsz'NetmaskTestMixin_v4.test_address_errors8  s    	# 	# 	# 	# 	# 	78888999"5666':;;;!4555&;<<<bi&>&>?????r   c           	         |                      t          |                     d                    d           |                      t          |                     d                    d           |                      t          |                     d                    d           |                      t          |                     d                    d           t          dd          D ]}d|z  }|                     |          }|                      t          |          |           |                      t          |                     d	|j        z                      |           |                      t          |                     d
|z                      |           |dv rdd|z
  z  }|                      t          |                     d	|j        z                      |           d S )N	192.0.2.0   192.0.2.0/24)r]  24r]  255.255.255.0z192.0.2.0/255.255.255.0r   !   z
0.0.0.0/%dz
0.0.0.0/%sz0.0.0.0/0%d)    r   rd  )r%   rF  r   rI   rG  rH  )r   inet_strrI  s       r   test_valid_netmaskz&NetmaskTestMixin_v4.test_valid_netmaskE  s   T\\*;<<==~NNNT\\*=>>??PPPT\\*HIIJJ'	) 	) 	)T\\*CDDEE'	) 	) 	)q" 	I 	IA"Q&G,,w''CSXXw///DLL!;<<==wH H H Sma.?!@!@AA7KKK G||&"q&1DLL!<==>>I I I I	I 	Ir   c                 b     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 S )Nc                     d|z  }                     t          j        |                    5                      | d|           d d d            d S # 1 swxY w Y   d S N%r is not a valid netmaskrT  r#   r9   r:   r   rO   rG  rW   r   s      r   assertBadNetmaskzANetmaskTestMixin_v4.test_netmask_errors.<locals>.assertBadNetmask^      -7C((388 8 8gg67778 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8   AAAr-  r5   r,  r    1 0x133z254.254.255.256r   1.1.1.1z254.xyz.2.3z240.255.0.0z255.254.128.0z0.1.127.255puddingr{   r0   r   rn  s   ` r   test_netmask_errorsz'NetmaskTestMixin_v4.test_netmask_errors]  s/   	8 	8 	8 	8 	8
 	B'''D)))D)))E***E***D)))$5666I...M222M222O444M222I...D)))))r   c                 B      fd} |dd            |dd           d S )Nc                     d|z  }                     t          j        |                    5                      | |f           d d d            d S # 1 swxY w Y   d S Nrk  rl  rm  s      r   rn  zJNetmaskTestMixin_v4.test_netmask_in_tuple_errors.<locals>.assertBadNetmasks      -7C((388 . .dG_---. . . . . . . . . . . . . . . . . .   AAArt  rf   rc  r0   rv  s   ` r   test_netmask_in_tuple_errorsz0NetmaskTestMixin_v4.test_netmask_in_tuple_errorsr  sJ    	. 	. 	. 	. 	. 	B'''B'''''r   c                     |                      d           |                      d           |                      d           d S )Nz192.0.2.0/27z192.0.2.0/31r]  r   r
   s    r   r   zNetmaskTestMixin_v4.test_picklez  sD    ((((((%%%%%r   Nr*   r+   r,   __doc__rJ  rM  rZ  rg  rw  r}  r   r0   r   r   r>  r>  '  s        EE; ; ;  
@ @ @I I I0* * **( ( (& & & & &r   r>  c                       e Zd Zej        ZdS )InterfaceTestCase_v4N)r*   r+   r,   r   IPv4Interfacer   r0   r   r   r  r            %GGGr   r  c                   .    e Zd Zej        Zd Zd Zd ZdS )NetworkTestCase_v4c                 v   |                      |                     d                              |                     d                               |                     |                     d                              |                     d                               |                      |                     d                              |                     d                               |                      |                     d                              |                     d                               d S N10.0.0.0/30z10.0.1.0/24z10.0.0.0/24assertFalser   	subnet_ofr   r
   s    r   test_subnet_ofz!NetworkTestCase_v4.test_subnet_of  s(   LL''11]++- -	. 	. 	. 	LL''11]++- -	. 	. 	. 	LL''11]++- -	. 	. 	. 	LL''11]++- -	. 	. 	. 	. 	.r   c                 v   |                      |                     d                              |                     d                               |                      |                     d                              |                     d                               |                      |                     d                              |                     d                               |                     |                     d                              |                     d                               d S r  r  r   supernet_ofr   r
   s    r   test_supernet_ofz#NetworkTestCase_v4.test_supernet_of  s(   LL''33]++- -	. 	. 	. 	LL''33]++- -	. 	. 	. 	LL''33]++- -	. 	. 	. 	LL''33]++- -	. 	. 	. 	. 	.r   c                 `   |                      t                    5  t          j        d                              t          j        d                     d d d            n# 1 swxY w Y   |                      t                    5  t          j        d                              t          j        d                     d d d            n# 1 swxY w Y   |                      t                    5  t          j        d                              t          j        d                     d d d            n# 1 swxY w Y   |                      t                    5  t          j        d                              t          j        d                     d d d            d S # 1 swxY w Y   d S )Nr  ::1/128)r@   rA   r   IPv4Networkr  IPv6Networkr  r
   s    r   test_subnet_of_mixed_typesz-NetworkTestCase_v4.test_subnet_of_mixed_types  s   y)) 	2 	2!-00<<%i002 2 2	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 y)) 	6 	6!),,88%m446 6 6	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 y)) 	2 	2!-00::%i002 2 2	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 y)) 	6 	6!),,66%m446 6 6	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6sG   :A!!A%(A%:CCC1:D77D;>D;:F##F'*F'N)	r*   r+   r,   r   r  r   r  r  r  r0   r   r   r  r    sI        #G. . .$. . .$6 6 6 6 6r   r  c                   <    e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
d	S )
NetmaskTestMixin_v6r?  c                 0   dD ]}|                      |          }|                     t          |          d           |                     t          |j                  d           |                     t          |j                  d           |                      d          }|                     t          |          d           |                     t          |j                  d           |                     t          |j                  d           d S )N)::1r?   s                  r  z'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffffr{   	::1%scope::1%scope/128rE  )r   rV   rI  
scoped_nets       r   rJ  z NetmaskTestMixin_v6.test_no_mask  s    7 	6 	6G,,w''CSXXy111S--/XYYYS..5555 \\+..
Z/:::Z/002[\\\Z011488888r   c                 $   d}|                      d|z            5  |                     |           d d d            n# 1 swxY w Y   d}|                      d|z            5  |                     |           d d d            d S # 1 swxY w Y   d S )Nzcafe:cafe::/128/190rL  zcafe:cafe::%scope/128/190r6   )r   rO   scoped_addrs      r   rM  z&NetmaskTestMixin_v6.test_split_netmask  s   $$$%Cd%JKK 	 	LL	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 2$$%Ck%QRR 	& 	&LL%%%	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	&s!   =AA"BB	B	c                 2     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                                          |          5                      |            d d d            d S # 1 swxY w Y   d S r   r6   rP  s     r   rQ  zANetmaskTestMixin_v6.test_address_errors.<locals>.assertBadAddress  rR  rS  rT  r4   rU  rV  zAt least 3 partsr-  rW  r.  zOnly hex digitsz/%scopez/%scope8zgoogle.com%scopez1.2.3.4%scopez
10%scope/8r0  r0   rY  s   ` r   rZ  z'NetmaskTestMixin_v6.test_address_errors  s   	# 	# 	# 	# 	# 	78888999'9:::$6777!3444(9:::$=>>>%>???+-?@@@*<==='9:::,.?@@@@@r   c           	         |                      t          |                     d                    d           |                      t          |                     d                    d           |                      t          |                     d                    d           t          dd          D ]v}d|z  }|                      t          |                     |                    |           |                      t          |                     d|z                      |           w|                      t          |                     d                    d           t          dd          D ]v}d|z  }|                      t          |                     |                    |           |                      t          |                     d|z                      |           wd S )	N)r:  rd  2001:db8::/32)r:  32r      z::/%dz::/0%dz2001:db8::%scope/32)r%   rF  r   rI   )r   re  rf  s      r   rg  z&NetmaskTestMixin_v6.test_valid_netmask  s    	T\\*<==>>(	* 	* 	*T\\*>??@@(	* 	* 	*T\\/::;;_MMMq# 	G 	GAkGSg!6!677AAAShl!;!;<<gFFFFT\\*?@@AACXYYYq# 	G 	GAkGSg!6!677AAAShl!;!;<<gFFFF	G 	Gr   c                 2     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                     d|z  }                     t          j        |                    5                      | d|           d d d            d S # 1 swxY w Y   d S rj  rl  rm  s      r   rn  zANetmaskTestMixin_v6.test_netmask_errors.<locals>.assertBadNetmask  ro  rp  r  r5   1::r,  r   rq  rr  129r-  ru  r{   r  r0   rv  s   ` r   rw  z'NetmaskTestMixin_v6.test_netmask_errors  s   	8 	8 	8 	8 	8
 	###&&&&&&%%%%%%&&&&&&&&&	***	***t$$$i00000r   c                 Z      fd} |dd            |dd            |dd           d S )Nc                     d|z  }                     t          j        |                    5                      | |f           d d d            d S # 1 swxY w Y   d S rz  rl  rm  s      r   rn  zJNetmaskTestMixin_v6.test_netmask_in_tuple_errors.<locals>.assertBadNetmask  r{  r|  r  rf   r  r  r0   rv  s   ` r   r}  z0NetmaskTestMixin_v6.test_netmask_in_tuple_errors  s]    	. 	. 	. 	. 	. 	###$$$c*****r   c                     |                      d           |                      d           |                      d           |                      d           d S )Nz2001:db8::1000/124z2001:db8::1000/127z2001:db8::1000z2001:db8::1000%scoper   r
   s    r   r   zNetmaskTestMixin_v6.test_pickle  s\    -...-...)***/00000r   Nr  r0   r   r   r  r    s        EE9 9 9& & &A A A&G G G.1 1 1(+ + +1 1 1 1 1r   r  c                       e Zd Zej        ZdS )InterfaceTestCase_v6N)r*   r+   r,   r   IPv6Interfacer   r0   r   r   r  r  #  r  r   r  c                   (    e Zd Zej        Zd Zd ZdS )NetworkTestCase_v6c                    |                      |                     d                              |                     d                               |                     |                     d                              |                     d                               |                      |                     d                              |                     d                               |                      |                     d                              |                     d                               |                      |                     d                              |                     d                               |                     |                     d                              |                     d                               d S )N2000:999::/562000:aaa::/482000:aaa::/562000:bbb::/56z2000:999::%scope/56z2000:aaa::%scope/48z2000:aaa::%scope/56r  r
   s    r   r  z!NetworkTestCase_v6.test_subnet_of*  s   LL))33_--/ /	0 	0 	0 	LL))33_--/ /	0 	0 	0 	LL))33_--/ /	0 	0 	0 	LL))33_--/ /	0 	0 	0 	LL.//992335 5	6 	6 	6 	LL.//992335 5	6 	6 	6 	6 	6r   c                 v   |                      |                     d                              |                     d                               |                      |                     d                              |                     d                               |                      |                     d                              |                     d                               |                     |                     d                              |                     d                               d S )Nr  r  r  r  r  r
   s    r   r  z#NetworkTestCase_v6.test_supernet_ofC  s(   LL))55_--/ /	0 	0 	0 	LL))55_--/ /	0 	0 	0 	LL))55_--/ /	0 	0 	0 	LL))55_--/ /	0 	0 	0 	0 	0r   N)r*   r+   r,   r   r  r   r  r  r0   r   r   r  r  '  s:        #G6 6 620 0 0 0 0r   r  c                   &    e Zd Zd Zd Zd Zd ZdS )FactoryFunctionErrorsc                     d}d}|                      t          |||          5   ||           ddd           dS # 1 swxY w Y   dS )z3Ensure a clean ValueError with the expected messagecamelotz+%r does not appear to be an IPv4 or IPv6 %sN)r   
ValueError)r   r   kindrO   rW   s        r   assertFactoryErrorz(FactoryFunctionErrors.assertFactoryErrorX  s    ;"":sD$?? 	 	GDMMM	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s   ;??c                 F    |                      t          j        d           d S )NrV   )r  r   
ip_addressr
   s    r   test_ip_addressz%FactoryFunctionErrors.test_ip_address_  !    	 4i@@@@@r   c                 F    |                      t          j        d           d S )N	interface)r  r   ip_interfacer
   s    r   test_ip_interfacez'FactoryFunctionErrors.test_ip_interfaceb  s!    	 6DDDDDr   c                 F    |                      t          j        d           d S )Nnetwork)r  r   
ip_networkr
   s    r   test_ip_networkz%FactoryFunctionErrors.test_ip_networke  r  r   N)r*   r+   r,   r  r  r  r  r0   r   r   r  r  V  s[          A A AE E EA A A A Ar   r  c                      e Zd Z ej        d          Z ej        d          Z ej        d          Z	 ej
        d          Z ej        d          Z ej        d          Z ej
        d          Z ej        d          Z ej        d          Zee	gZeegz   ZeegZeegz   ZeegZeegz   Zeez   Zeez   Z ej        d          Z ej        d          Z ej        d          Z ej
        d          Z ej        d          Z ej        d          Z  ej
        d          Z! ej        d          Z" ej        d          Z#d Z$d Z%d Z&d Z'd	 Z(d
 Z)d Z*d Z+d Z,d Z-d Z.dS )ComparisonTestsr?   r  r   	::2%scopec                 L   t                      }| j        D ]}|                     ||           |                     ||k               |                     |                    |          t                     |                     |                    |          t                     d S r   )objectobjects_with_scopedassertNotEqualr  r%   __eq__NotImplemented__ne__r   otherobjs      r   test_foreign_type_equalityz*ComparisonTests.test_foreign_type_equality  s    + 	@ 	@CU+++SE\***SZZ..???SZZ..????		@ 	@r   c                 d    | j         D ]'}| j         D ]}||u r|                     ||           (d S r   )objectsr  r&   s      r   test_mixed_type_equalityz(ComparisonTests.test_mixed_type_equality  sZ     < 	. 	.C| . .#::##C----.	. 	.r   c                 r    t          | j        | j                  D ]\  }}|                     ||           d S r   )zip
v6_objectsv6_scoped_objectsr  r&   s      r   test_scoped_ipv6_equalityz)ComparisonTests.test_scoped_ipv6_equality  sG    DOT-CDD 	* 	*HCS))))	* 	*r   c                 Z    | j         D ]"}| j        D ]}|                     ||           #d S r   )
v4_objectsr  r  r&   s      r   test_v4_with_v6_scoped_equalityz/ComparisonTests.test_v4_with_v6_scoped_equality  sM    ? 	. 	.C- . .##C----.	. 	.r   c                     | j         D ]D}|                     ||           |                     ||           |                     ||           Ed S r   )r  r%   assertLessEqualassertGreaterEqualr   r  s     r   test_same_type_equalityz'ComparisonTests.test_same_type_equality  sc    + 	. 	.CS#&&&  c***##C----	. 	.r   c           
         | j         | j        f| j        | j        f| j        | j        f| j        | j        f| j        | j	        f| j
        | j        f| j        | j        f| j        | j        f| j        | j        ff	D ]\  }}|                     ||           |                     ||           |                     ||           |                     ||           |                     ||           |                     ||k               |                     ||k                |                     ||k               |                     ||k               d S r   )v4addrv4addr2v4netv4net2v4intfv4intf2v6addrv6addr2v6netv6net2v6intfv6intf2v6addr_scopedv6addr2_scopedv6net_scopedv6net2_scopedv6intf_scopedv6intf2_scopedr  
assertLessr  assertGreaterr  r  r&   s      r   test_same_type_orderingz'ComparisonTests.test_same_type_ordering  sd   [$,'Z%[$,'[$,'Z%[$,'!45 23!45

 	) 	)HC S)))OOC%%%  c***sC(((##C---S3Y'''S3Y'''SCZ(((SCZ(((('	) 	)r   c                 @   | j         D ]}|                     || j                   | j        | j        z   D ]}|                     || j                   | j        | j        z   D ]}|                     || j                   | j        | j        | j        gz   D ]}|                     || j                   | j        | j        | j        gz   D ]}|                     || j                   | j	        | j
        z   | j        gz   D ]}|                     || j                   d S r   )v4_addressesassertInr  v6_addressesv6_scoped_addressesr  r  r  assertNotInr  r  r  s     r   test_containmentz ComparisonTests.test_containment  sR   $ 	+ 	+CMM#tz****$t'?? 	+ 	+CMM#tz****$t'?? 	2 	2CMM#t01111?dj$2C%DD 	. 	.CS$*----?dj$2C%DD 	5 	5CS$"34444?T%;;tzlJ 	. 	.CS$*----	. 	.r   c                    | j         D ]Ê| j         D ]t          t                              st          t                              r=|                     t          fd           |                     t          fd           |                     t          fd           |                     t          fd           d S )Nc                       k     S r   r0   r'   r(   s   r   <lambda>z:ComparisonTests.test_mixed_type_ordering.<locals>.<lambda>      S3Y r   c                       k    S r   r0   r  s   r   r	  z:ComparisonTests.test_mixed_type_ordering.<locals>.<lambda>  r
  r   c                       k    S r   r0   r  s   r   r	  z:ComparisonTests.test_mixed_type_ordering.<locals>.<lambda>      SCZ r   c                       k    S r   r0   r  s   r   r	  z:ComparisonTests.test_mixed_type_ordering.<locals>.<lambda>  r  r   )r  
isinstancetyper@   rA   r&   s    @@r   test_mixed_type_orderingz(ComparisonTests.test_mixed_type_ordering  s    + 	A 	AC/ A Ac499-- Cc1K1K !!)->->->->->???!!)->->->->->???!!)-?-?-?-?-?@@@!!)-?-?-?-?-?@@@@A	A 	Ar   c                    t                      }| j        D ]}|                     t                    5  ||k      d d d            n# 1 swxY w Y   |                     t                    5  ||k     d d d            n# 1 swxY w Y   |                     t                    5  ||k     d d d            n# 1 swxY w Y   |                     t                    5  ||k     d d d            n# 1 swxY w Y   |                     |t
          k                |                     |t
          k               |                     |t
          k               |                     |t
          k               |                     |t          k                |                     |t          k               |                     |t          k               |                     |t          k               d S r   )r  r  r@   rA   r   r   r  r   r  s      r   test_foreign_type_orderingz*ComparisonTests.test_foreign_type_ordering  s   + 	- 	-C""9--  e              ""9--  e              ""9--  u              ""9--  u              OOC'M***S7]+++OOC7N+++SG^,,,S8^,,,OOC(N+++SH_---OOC8O,,,,!	- 	-sG   AA
	A
	+A>>B	B	#B66B:	=B:	C..C2	5C2	c                    | j         | j        | j        g}| j        | j        | j        g}| j        | j        | j        g}| 	                    |t          | j        t          j                             | 	                    |t          | j        t          j                             | 	                    |t          | j        t          j                             | 	                    ||z   t          | j        | j        z   t          j                             | 	                    t           t          j        t"                               d S )N)key)r  r  r  r  r  r  r  r  r  r%   sortedr  r   get_mixed_type_keyr  r  r  r  )r   
v4_ordered
v6_orderedv6_scoped_ordereds       r   test_mixed_type_keyz#ComparisonTests.test_mixed_type_key  sk   k4:t{;
k4:t{;
!/1BDDVW$-$@B B B	C 	C 	C 	$-$@B B B	C 	C 	C 	* 6$-$@B B B	C 	C 	C 	&77$2H H$-$@B B B	C 	C 	C 	)Ef)M)MNNNNNr   c                    t          j        d          }t          j        d          }t          j        d          }t          j        d          }t          j        d          }t          j        d          }|                     t          |j        |           |                     t          |j        |           |                     t          |j        |           |                     t          |j        |           |                     t          |j        |           |                     t          |j        |           |                     t          |j        |           |                     t          |j        |           |                     t          |j        |           |                     t          |j        |           |                     t          |j        |           |                     t          |j        |           |                     t          |j        |           |                     t          |j        |           |                     t          |j        |           |                     t          |j        |           d S )Nrt  r  r  )r   r  r  r@   rA   __lt____gt__)r   r  r  r  r  r  r  s          r   test_incompatible_versionsz*ComparisonTests.test_incompatible_versions   s   %i00$Y//%e,,$U++!,[99 +K88)V]F;;;)V]F;;;)U\5999)U\5999)V]F;;;)V]F;;;)U\5999)U\5999)V]MBBB)V]MBBB)U\<@@@)U\<@@@)]%96BBB)]%96BBB)\%8%@@@)\%8%@@@@@r   N)/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  r  r  r  r  r  r  r  r  r  r  r  r  r  r0   r   r   r  r  i  se       "Y"1%%F!I!!$$E$Y$Q''F"Y"1%%F!I!!$$E$Y$Q''F)I)+66M')'44L*9*;77MF#L'JF#L'J(-8+|n<:%G!$55#i#A&&G"Y"1%%F%i%a((G#i#A&&G"Y"1%%F%i%a((G*Y*;77N)I)+66M,Y,[99N@ @ @. . .* * *. . .
. . .) ) ),. . .A A A- - -(O O O&A A A A Ar   r  c                      e Zd Zd Zd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Z d Z!d  Z"d! Z#d" Z$d# Z%d$ Z&d% Z'd& Z(d' Z)d( Z*d) Z+d* Z,d+ Z-d, Z.d- Z/d. Z0d/ Z1d0 Z2d1 Z3d2 Z4d3 Z5d4 Z6d5 Z7d6 Z8d7 Z9d8 Z:d9 Z;d: Z<d; Z=d< Z>d= Z?d> Z@d? ZAd@ ZBdA ZCdB ZDdC ZEdD ZFdE ZGdF ZHdG ZIdH ZJdI ZKdJ ZLdKS )LIpaddrUnitTestc                    t          j        d          | _        t          j        d          | _        t          j        d          | _        t          j        d          | _        t          j        d          | _	        t          j
        d          | _        t          j        d          | _        t          j        d          | _        t          j
        d	          | _        d S )
Nr-  
1.2.3.4/24
1.2.3.0/242001:658:22a:cafe:200:0:0:1z2001:658:22a:cafe:200:0:0:1/642001:658:22a:cafe::/64!2001:658:22a:cafe:200:0:0:1%scopez$2001:658:22a:cafe:200:0:0:1%scope/64z2001:658:22a:cafe::%scope/64)r   r   ipv4_addressr  ipv4_interfacer  ipv4_networkr  ipv6_addressipv6_interfacer  ipv6_networkipv6_scoped_addressipv6_scoped_interfaceipv6_scoped_networkr
   s    r   setUpzIpaddrUnitTest.setUp   s    %1)<<'5lCC%1,??%3)+ +'5,. .%12JKK#,#:/$1 $1 %.%<2&4 &4"#,#89W#X#X   r   c                 D   |                      dt          t          j        d                               |                      dt          t          j        d                               |                      dt          t          j        d                               d S )NzIPv4Interface('1.2.3.4/32')r-  zIPv6Interface('::1/128')r  zIPv6Interface('::1%scope/128')r  )r%   r;   r   r  r  r
   s    r   testReprzIpaddrUnitTest.testRepr0  s    6i5i@@AA	C 	C 	C3i5e<<==	? 	? 	?9i5kBBCC	E 	E 	E 	E 	Er   c                    t          j        d          }t          j        d          }|                     t          j        d          |           |                     t          j        |df          |           |                     t          j        d          |           |                     t          j        d          |           |                     t          j        |df          |           |                     t          j        d          |           |                     t
                    5  t          j        d	           d d d            n# 1 swxY w Y   |                     t
                    5  t          j        |d
f           d d d            n# 1 swxY w Y   |                     t
                    5  t          j        d           d d d            n# 1 swxY w Y   |                     t
                    5  t          j        d           d d d            n# 1 swxY w Y   |                     t
                    5  t          j        |df           d d d            n# 1 swxY w Y   |                     t
                    5  t          j        d           d d d            n# 1 swxY w Y   t          j        d          }|                     t          j        d	d          |           |                     t          j        |d
fd          |           |                     t          j        dd          |           |                     t          j        dd          |           |                     t          j        |dfd          |           |                     t          j        dd          |           t          j        d          }t          j        d          }|                     t          j        d          |           |                     t          j        |df          |           |                     t          j        d          |           |                     t          j        d          |           |                     t          j        |d
f          |           |                     t          j        d          |           |                     t          j        d	          t          j        d                     |                     t          j        d          t          j        d                     |                     t
                    5  t          j        d           d d d            n# 1 swxY w Y   |                     t
                    5  t          j        d           d d d            d S # 1 swxY w Y   d S )Nr   z192.0.2.1/32)r   rd  rd  )      rd  )r   rD  rD  )r5  rD  )r   r^  r^  )r5  r^  )r   rb  rb  )r5  rb  r_  Fstrictr]  ra  )       rb  r\  )r8  r^  z192.0.2.1/24)r   z255.255.255.255.0)r   r   r  r%   r@   r  r  r  )r   iprI  s      r   testIPv4TuplezIpaddrUnitTest.testIPv4Tuple9  s~   ";//#N33./@AA3GGG.Bx88#>>>./?@@#FFF. 0C D DEH	J 	J 	J.0A0C D DEH	J 	J 	J. 0C D DEH	J 	J 	J z** 	5 	5!"3444	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5z** 	, 	,!2r(+++	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	,z** 	4 	4!"2333	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4z** 	B 	B!"@AAA	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	Bz** 	9 	9!2"7888	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9z** 	A 	A!"?@@@	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A #N33./@6;= = =>A	C 	C 	C.Bx6;= = =>A	C 	C 	C./?6;= = =>A	C 	C 	C. 0A6;= = =>A	C 	C 	C 	.0?0A6;= = =>A	C 	C 	C 	. 0A6;= = =>A	C 	C 	C
 ";//#N33. 0A B BCF	H 	H 	H.0?0A B BCF	H 	H 	H. 0A B BCF	H 	H 	H./@AA3GGG.Bx88#>>>./?@@#FFF01BCC"0@@	B 	B 	B01ABB"0@@	B 	B 	B z** 	F 	F!"DEEE	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	F z** 	E 	E !CDDD	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	Es   7EEE=F  F$'F$G&&G*-G*H,,H03H0I44I8;I8J::J>J>V$$V(+V(	W++W/2W/c                    t          j        d          }t          j        d          }|                     t          j        d          |           |                     t          j        d          |           |                     t          j        |df          |           t          j        d          }t          j        d          }|                     t          j        d          |           |                     t          j        d          |           |                     t          j        |d	f          |           t          j        d
          }t          j        d          }|                     t
                    5  t          j        d           d d d            n# 1 swxY w Y   |                     t
                    5  t          j        d           d d d            n# 1 swxY w Y   |                     t
                    5  t          j        |df           d d d            n# 1 swxY w Y   t          j        d          }|                     t          j        dd          |           |                     t          j        dd          |           |                     t          j        |dfd          |           |                     t          j        d          t          j        d                     |                     t          j        d          t          j        d                     t          j        d          }|                     t
                    5  t          j        d           d d d            n# 1 swxY w Y   |                     t
                    5  t          j        |df           d d d            n# 1 swxY w Y   |                     t
                    5  t          j        d           d d d            n# 1 swxY w Y   |                     t
                    5  t          j        d           d d d            d S # 1 swxY w Y   d S )Nr:  z2001:db8::/128)r:  128)	                n   r   r<  z2001:db8::/96)r:  96)r=  `   r>  r<  2001:db8::1)r@  r?  )	               n   r?  r?  Fr6  )r@  r>  z2001:db8::1/96)rA  r>  2001:db8::1%scope)rB  r?  )r@  rb  )r   r   r  r%   r@   r  r  r  )r   r9  rI  	ip_scopeds       r   testIPv6TuplezIpaddrUnitTest.testIPv6Tuple  sS   "<00#$455./DEE	 	 	.=? ?	 	 	 	.E{;;	 	 	"<00#O44./CDD	 	 	.<> >	 	 	 	.Dz::	 	 	 )*<==	 "=11z** 	7 	7!"5666	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7z** 	= 	=! #< = = =	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= z** 	, 	,!2r(+++	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, #O44./B6;= = =	 	 	 	.I$)+ + + 	 	 	 	.BxFFF	 	 	 	01FGG"01ABB	D 	D 	D0>@ @"01ABB	D 	D 	D )*=>>	z** 	= 	=!";<<<	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	=z** 	3 	3!9b/222	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3
 z** 	D 	D!"BCCC	D 	D 	D 	D 	D 	D 	D 	D 	D 	D 	D 	D 	D 	D 	D z** 	C 	C !ABBB	C 	C 	C 	C 	C 	C 	C 	C 	C 	C 	C 	C 	C 	C 	C 	C 	C 	Cs~   F((F,/F,G..G25G2H66H:=H:7NNN=O  O$'O$P&&P*-P*Q--Q14Q1c                    |                      t          j        d          dz   t          j        d                     |                      t          j        d          dz
  t          j        d                     |                      t          j        d          dz   t          j        d                     |                      t          j        d          dz
  t          j        d                     |                     t          j        d	          dz   t          j        d
                     |                     t          j        d
          dz
  t          j        d	                     d S )Nrt     z1.1.2.0   z1.1.0.1r  i  z::ffffr  z::ffff%scope)r%   r   r   r   r  r
   s    r   testAddressIntMathz!IpaddrUnitTest.testAddressIntMath  sd   .y99C?".y99	; 	; 	;.y99C?".y99	; 	; 	;.u55C".x88	: 	: 	:.x88IF".u55	7 	7 	7I1+>>)L%1.AA	C 	C 	CI1.AAYO%1+>>	@ 	@ 	@ 	@ 	@r   c                 j   |                      t          t          j        d           |                      t          t          j        dt          j        z             |                      t          t          j        d           |                      t          t          j        dt          j        z             d S )Nrf   r   )r@   r  r   v4_int_to_packed
IPV4LENGTHv6_int_to_packed
IPV6LENGTHr
   s    r   testInvalidIntToBytesz$IpaddrUnitTest.testInvalidIntToBytes  s    *i&@"EEE*i&@y33	5 	5 	5*i&@"EEE*i&@y33	5 	5 	5 	5 	5r   c           	         t          j        d          }t          j        d          }t          j        d          }|                     t          t          j        |g                    ||fg           |                     t          t          j        ||g                    ||f||fg           |                     t          t          j        |||g                    ||fg           |                     dt          j        dd                     |                     dt          | j                             d S )Nz10.10.10.10z10.10.10.11z10.10.10.12r   r   zIPv4Network('1.2.3.0/24'))r   r   r%   list_find_address_range_count_righthand_zero_bitsr;   r*  )r   ip1ip2ip3s       r   testInternalszIpaddrUnitTest.testInternals  s2   #M22#M22#M22i;SEBBCC*	' 	' 	'i;S#JGGHH*sCj1	3 	3 	3i;S#sOLLMM*	' 	' 	'iB1cJJKKK4d4;L6M6MNNNNNr   c                    |                      t          | j        j                  d           |                      t	          | j        j                  d           |                      t          | j        j                  d           |                      t	          | j        j                  d           |                      t	          | j        j                  d           |                      t          | j        j                  d           |                      t	          | j        j                  d           |                      t	          | j        j                  d           d S )Ni 1.2.3.0l	           /YE    2001:658:22a:cafe::::ffff:ffff:ffff:ffffz2001:658:22a:cafe::%scope)r%   intr*  network_addressrF  r-  rH  r0  r
   s    r   testGetNetworkzIpaddrUnitTest.testGetNetwork  s\   T.>??JJJT.>??KKKT.>???	A 	A 	AT.>??.	0 	0 	0T.7880	2 	2 	2T5EFF?	A 	A 	AT5EFF4	6 	6 	6T5>??0	2 	2 	2 	2 	2r   c                 r   |                      | j        j        t          j        d          j                   t          j        d          }t          j        d          }t          j        d          }|                      |t          j        t          |j                                       |                      |t          j        t          |j                                       |                     |t          j        t          |j                                       d}|                      | j	        j        t          j
        |          j                   |                      | j        j        t          j
        |          j                   |                      t          j        | j        j                  j        d           |                      t          j        | j        j                  j        d           |                      t          j        | j        j                  j        d           d S )NrA  r-  r%  r'  	         /YE          )r%   r)  _ipr   r  r  r[  r\  r  r,  r  r/  r(  versionr+  r.  )r   ipv4ipv6ipv6_scopedv6_ints        r   testIpFromIntzIpaddrUnitTest.testIpFromInt  s   ,0"0::>	@ 	@ 	@ #I..#$ABB*+NOOy3C8L4M4MNNOOOy3C8L4M4MNNOOOK)=c+B]>^>^)_)_```7,0"088<	> 	> 	>37"088<	> 	> 	> 	-d.?.CDDL	 	 	-d.?.CDDL	 	 	-d.F.JKKS	 	 	 	 	r   c                    t           j        }|                     | j        j        t          j        d          j                   |                      |d           |d                     |                     | j        j        t          j        d          j                   |                      |d           |d                     |                      |d           |d                     d S )	NrB  255.254.253.252       X*      ffff:2:3:4:ffff::            r{   s                   )r   r  r%   r)  rb  r  r,  r9  r   s     r   testIpFromPackedzIpaddrUnitTest.testIpFromPacked  s    &,0"/0CDDH	J 	J 	J!233 !455	7 	7 	7,/"/89 99;	= 	= 	= 	!455  "6 7 7	8 	8 	8 	 ..	0 	0 	0 	0 	0r   c                 "   |                      t          | j        j                  d           |                      t	          | j        j                  d           |                      t          | j        j                  d           |                      t	          | j        j                  d           |                      t          | j        j                  d           |                      t	          | j        j                  d           d S )NrA  r-  r_  2001:658:22a:cafe:200::1)r%   r[  r)  r9  rF  r,  r/  r
   s    r   	testGetIpzIpaddrUnitTest.testGetIp  s   T0344h???T0344i@@@T0344?	A 	A 	AT03443	5 	5 	5T7:;;?	A 	A 	AT7:;;3	5 	5 	5 	5 	5r   c                    |                      | j        j        d            |                      t          | j        j                  d           |                      | j        j        d            |                      t          | j        j                  d           |                      | j        j        j        d            |                      t          | j	        j        j                  d           d S )Nscope)
r%   r+  scope_idrF  r.  r,  r/  r-  r\  r0  r
   s    r   testGetScopeIdzIpaddrUnitTest.testGetScopeId,  s    *3	 	 	T5>?? 	" 	" 	",5	 	 	T7@AA 	" 	" 	"*:C	 	 	T5ENOO 	" 	" 	" 	" 	"r   c                    |                      t          | j        j                  d           |                      t	          | j        j                  d           |                      t          | j        j                  d           |                      | j        j        d           |                      t          | j        j                  d           |                      | j        j        d           d S )Nl     rb  l	            @   )r%   r[  r*  rG  rF  r-  	prefixlenr0  r
   s    r   testGetNetmaskzIpaddrUnitTest.testGetNetmask:  s    T.677DDDT.677IIIT.677@	B 	B 	B*4b999T5=>>@	B 	B 	B1;R@@@@@r   c                    t          j        d          }|                     t          |j        j                  d           |                     |                    d          d           t          j        d          }|                     t          |j        j                  d           |                     |                    d          d           t          j        d          }|                     t          |j        j                  d           |                     |                    d          d           d S )N	1.2.3.4/0r   0z::1/0z::1%scope/0)r   r  r%   r[  r  rG  _prefix_from_prefix_stringr  )r   ipv4_zero_netmaskipv6_zero_netmaskipv6_scoped_zero_netmasks       r   testZeroNetmaskzIpaddrUnitTest.testZeroNetmaskD  s   %3K@@.6>??CCC*EEcJJANNN%3G<<.6>??CCC*EEcJJANNN#,#:=#I#I 5=EFFJJJ1LLSQQSTUUUUUr   c                 d    t          j        d          }|                     |j        d           d S )Nz127.0.0.0/0.0.0.255r^  )r   r  r%   ry  r   rI  s     r   testIPv4NetzIpaddrUnitTest.testIPv4NetQ  s1    #$9::+++++r   c                 "   |                      t          | j        j                  d           |                      t	          | j        j                  d           |                      t          | j        j                  d           |                      t	          | j        j                  d           |                      t          | j        j                  d           |                      t	          | j        j                  d           d S )Ni	1.2.3.255l	   /YE    %2001:658:22a:cafe:ffff:ffff:ffff:ffff)r%   r[  r*  broadcast_addressrF  r-  r0  r
   s    r   testGetBroadcastzIpaddrUnitTest.testGetBroadcastU  s   T.@AA8LLLT.@AA;OOOT.@AA?	A 	A 	AT.@AA@	B 	B 	B 	T5GHH?	A 	A 	AT5GHH@	B 	B 	B 	B 	Br   c                     |                      | j        j        j        d           |                      | j        j        j        d           |                      | j        j        j        d           d S )Nr^  rx  )r%   r)  r  ry  r,  r/  r
   s    r   testGetPrefixlenzIpaddrUnitTest.testGetPrefixlenc  se    ,4>CCC,4>CCC3;ErJJJJJr   c                    |                      | j                                        j        d           |                      t	          | j                                        j                  d           |                      t          j        d          j                                        t          j	        d                     |                      | j
                                        j        d           |                      t	          | j
                                        j                  d           |                      t          j        d          j                                        t          j        d                     |                      | j                                        j        d           |                      t	          | j                                        j                  d           d S )N   z1.2.2.0	0.0.0.0/0?   rY  z::0/0)r%   r*  supernetry  rF  r\  r   r  r  r  r-  r  r  r0  r
   s    r   testGetSupernetzIpaddrUnitTest.testGetSuperneth  s   *3355?DDDT.7799IJJ"	$ 	$ 	$#K008AACC!+..	0 	0 	0 	*3355?DDDT.7799IJJ.	0 	0 	0099AJJLL".w77	9 	9 	91::<<FKKKT5>>@@PQQ.	0 	0 	0 	0 	0r   c                    |                      | j                            d          j        d           |                      t	          | j                            d          j                  d           |                      | j                            d          j        d           |                      t	          | j                            d          j                  d           |                      | j                            d          j        d           |                      t	          | j                            d          j                  d           d S )Nrt      z1.2.0.0=   z2001:658:22a:caf8::)r%   r*  r  ry  rF  r\  r-  r0  r
   s    r   testGetSupernet3zIpaddrUnitTest.testGetSupernet3y  s7   *33A66@"EEET.77::JKK"	$ 	$ 	$ 	*33A66@"EEET.77::JKK.	0 	0 	01::1==GLLLT5>>qAAQRR.	0 	0 	0 	0 	0r   c                    |                      t          | j        j        dd           |                      t          | j        j        d           |                     | j                            d          | j                            d                     |                      t          | j        j        dd           |                      t          | j        j        d           |                     | j                            d          | j                            d	                     |                      t          | j        j        dd           |                      t          | j        j        d           |                     | j                            d          | j                            d	                     d S )
Nr   r?   prefixlen_diff
new_prefix   r  r     A   >   )r@   r  r*  r  r%   r-  r0  r
   s    r   testGetSupernet4zIpaddrUnitTest.testGetSupernet4  s   *d&7&@)*q 	 	: 	: 	:*d&7&@%' 	 	) 	) 	)*3313EE*33r3BB	D 	D 	D 	*d&7&@)*q 	 	: 	: 	:*d&7&@%' 	 	) 	) 	)*3313EE*33r3BB	D 	D 	D*d&>&G)*q 	 	: 	: 	:*d&>&G%' 	 	) 	) 	)1::!:LL1::b:II	K 	K 	K 	K 	Kr   c                 d   t          | j                                                  }|                     dt	          |                     |                     t          j        d          |d                    |                     t          j        d          |d                    t          j        d          }t          |                                          }|                     dt	          |                     |                     t          j        d          |d                    |                     t          j        d	          |d                    t          j        d
          }t          |                                          }|                     dt	          |                     |                     t          j        d          |d                    |                     t          j        d	          |d                    t          j        d          t          j        d          g}d}d}|                     |t          t          j	        |                                                               |                     |t          t          j	        |                                                               |                     t          t          j	        |                                                    t          t          j	        |                                                               t          j        d          g}d}d}|                     |t          t          j	        |                                                               |                     |t          t          j	        |                                                               |                     t          t          j	        |                                                    t          t          j	        |                                                               t          j        d          t          j        d          g}d}d}|                     |t          t          j	        |                                                               |                     |t          t          j	        |                                                               |                     t          t          j	        |                                                    t          t          j	        |                                                               t          j        d          g}d}d}|                     |t          t          j	        |                                                               |                     |t          t          j	        |                                                               |                     t          t          j	        |                                                    t          t          j	        |                                                               d S )N   z1.2.3.1r   z	1.2.3.254rf   2001:658:22a:cafe::/120rF  2001:658:22a:cafe::1z2001:658:22a:cafe::ffz2001:658:22a:cafe::%scope/1202.0.0.0z2.0.0.1z
2.0.0.0/31)r     r-  rC  )r-  rd  rY  z2001:658:22a:cafe::/127)rY     2001:658:22a:cafe::1/128)r  r   )
rP  r*  hostsr%   lenr   r   r  r   r  )r   r  r-  r0  addrsstr_argstpl_argss          r   	testHostszIpaddrUnitTest.testHosts  sv   T&,,..//c%jj))).y9958DDD.{;;U2YGGG ,-FGG\''))**c%jj)))./EFFaQQQ./FGGrSSS'34STT(..0011c%jj)))./EFFaQQQ./FGGrSSS &y11&y113"Y%9(%C%C%I%I%K%K L LMMMY%9(%C%C%I%I%K%K L LMMMi28<<BBDDEEi28<<BBDDEE	G 	G 	G &y112"Y%9(%C%C%I%I%K%K L LMMMY%9(%C%C%I%I%K%K L LMMMi28<<BBDDEEi28<<BBDDEE	G 	G 	G &'<==&'=>>@,/Y%9(%C%C%I%I%K%K L LMMMY%9(%C%C%I%I%K%K L LMMMi28<<BBDDEEi28<<BBDDEE	G 	G 	G &'=>>A-0Y%9(%C%C%I%I%K%K L LMMMY%9(%C%C%I%I%K%K L LMMMi28<<BBDDEEi28<<BBDDEE	G 	G 	G 	G 	Gr   c                    |                      t          | j                            d                    t          | j                            d                               |                     t
          t          | j                            d                     |                     t
          t          | j                            dd                     |                      t          | j                            d                    t          | j                            d                               |                     t
          t          | j                            d	                     |                     t
          t          | j                            dd                     |                      t          | j                            d                    t          | j                            d                               |                     t
          t          | j                            d	                     |                     t
          t          | j                            dd                     d S )
Nrt   r     r  r  r  r`  D   r  )	r%   r  r*  subnetsr@   r  rP  r-  r0  r
   s    r   testFancySubnettingz"IpaddrUnitTest.testFancySubnetting  s    1 9 9 9 K KLL 1 9 9R 9 H HII	K 	K 	K*d+33r3BB	D 	D 	D*d+331>@ 4 B B	C 	C 	C 	 1 9 9 9 K KLL 1 9 9R 9 H HII	K 	K 	K*d+33r3BB	D 	D 	D*d+331>@ 4 B B	C 	C 	C 	 8 @ @PQ @ R RSS 8 @ @B @ O OPP	R 	R 	R*d2::b:II	K 	K 	K*d2::!FH ; J J	K 	K 	K 	K 	Kr   c                    |                      t          | j                                                  d         j        d           |                      t          t          | j                                                  d         j                  d           |                      t          t          | j                                                  d         j                  d           |                      t          | j                                                  d         j        d           |                      t          | j                                                  d         j        d           d S )Nr   r  rX  r?   z	1.2.3.128r  )	r%   rP  r*  r  ry  rF  r\  r-  r0  r
   s    r   testGetSubnetszIpaddrUnitTest.testGetSubnets  sP   d/7799::1=GLLLT%--//1 11244CE E"	$ 	$ 	$ 	T%--//1 11244CE E$	& 	& 	& 	d/7799::1=GLLLd6>>@@AA!DNPRSSSSSr   c                    t          j        d          }d |                                D             }d |                    d          D             }|                     |dg           |                     ||           d S )NrC  c                 ,    g | ]}t          |          S r0   rF  .0rP   s     r   
<listcomp>z;IpaddrUnitTest.testGetSubnetForSingle32.<locals>.<listcomp>      111qCFF111r   c                 ,    g | ]}t          |          S r0   r  r  s     r   r  z;IpaddrUnitTest.testGetSubnetForSingle32.<locals>.<listcomp>      222qCFF222r   r   )r   r  r  r%   )r   r9  subnets1subnets2s       r   testGetSubnetForSingle32z'IpaddrUnitTest.testGetSubnetForSingle32  s~    "<0011BJJLL11122BJJqMM222L>2228,,,,,r   c                    t          j        d          }d |                                D             }d |                    d          D             }|                     |dg           |                     ||           t          j        d          }d |                                D             }d |                    d          D             }|                     |dg           |                     ||           d S )Nr  c                 ,    g | ]}t          |          S r0   r  r  s     r   r  z<IpaddrUnitTest.testGetSubnetForSingle128.<locals>.<listcomp>  r  r   c                 ,    g | ]}t          |          S r0   r  r  s     r   r  z<IpaddrUnitTest.testGetSubnetForSingle128.<locals>.<listcomp>  r  r   r   r  c                 ,    g | ]}t          |          S r0   r  r  s     r   r  z<IpaddrUnitTest.testGetSubnetForSingle128.<locals>.<listcomp>  s    888qCFF888r   c                 ,    g | ]}t          |          S r0   r  r  s     r   r  z<IpaddrUnitTest.testGetSubnetForSingle128.<locals>.<listcomp>  s    999qCFF999r   )r   r  r  r%   )r   r9  r  r  rC  s        r   testGetSubnetForSingle128z(IpaddrUnitTest.testGetSubnetForSingle128  s    "9--11BJJLL11122BJJqMM222I;///8,,,)/::	88I$5$5$7$788899I$5$5a$8$8999O#45558,,,,,r   c                     d | j                             d          D             }|                     |g d           d | j                            d          D             }|                     |g d           d S )Nc                 ,    g | ]}t          |          S r0   r  r  s     r   r  z.IpaddrUnitTest.testSubnet2.<locals>.<listcomp>  s    <<<!s1vv<<<r   r   )z
1.2.3.0/26z1.2.3.64/26z1.2.3.128/26z1.2.3.192/26c                 ,    g | ]}t          |          S r0   r  r  s     r   r  z.IpaddrUnitTest.testSubnet2.<locals>.<listcomp>  s    >>>AQ>>>r   )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   ipsipsv6s      r   testSubnet2zIpaddrUnitTest.testSubnet2  s    <<t088;;<<<III	K 	K 	K ?>!2!:!:1!=!=>>>, , ,	- 	- 	- 	- 	-r   c                 @   d | j                             d          D             }|                     |d d         g d           |                     |dd          g d           |                     t          |          d           t	          j        d          }d	 |                    d          D             }|                     |d d         g d
           |                     |dd          g d           |                     t          |          d           d S )Nc                 ,    g | ]}t          |          S r0   r  r  s     r   r  z2IpaddrUnitTest.testGetSubnets3.<locals>.<listcomp>  s    @@@a3q66@@@r      rt   )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/32rG  r  c                 ,    g | ]}t          |          S r0   r  r  s     r   r  z2IpaddrUnitTest.testGetSubnets3.<locals>.<listcomp>  s    ;;;a3q66;;;r   )z2001:658:22a:cafe::/128r  z2001:658:22a:cafe::2/128)z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-  s      r   testGetSubnets3zIpaddrUnitTest.testGetSubnets3  sR   @@4#4#<#<Q#?#?@@@!666	8 	8 	8<<<	> 	> 	>Ws+++ ,-FGG;;<#7#7#:#:;;;!) ) )	* 	* 	* 	* * *	+ 	+ 	+ 	Ws+++++r   c                    |                      t          t          | j        j                            d                     |                      t          t          | j                            d                     |                      t          t          | j        j                            d                     |                      t          t          | j                            d                     |                      t          t          | j	        j                            d                     |                      t          t          | j
                            d                     d S )N	   r  r@   r  rP  r)  r  r  r*  r,  r-  r/  r0  r
   s    r   testSubnetFailsForLargeCidrDiffz.IpaddrUnitTest.testSubnetFailsForLargeCidrDiff)  sC   *d-5==a@@	B 	B 	B*d+33A66	8 	8 	8*d-5==bAA	C 	C 	C*d+33B77	9 	9 	9*d4<DDRHH	J 	J 	J*d2::2>>	@ 	@ 	@ 	@ 	@r   c                    |                      t          | j        j        j        d           |                      t          | j        j        j        d           |                      t          | j        j        j        d           d S )Nr  r  )r@   r  r)  r  r  r,  r/  r
   s    r   !testSupernetFailsForLargeCidrDiffz0IpaddrUnitTest.testSupernetFailsForLargeCidrDiff7  s    *-5>	D 	D 	D*-5>	D 	D 	D*4<Er	K 	K 	K 	K 	Kr   c                    |                      t          t          | j        j                            d                     |                      t          t          | j                            d                     |                      t          t          | j        j                            d                     |                      t          t          | j                            d                     |                      t          t          | j	        j                            d                     |                      t          t          | j
                            d                     d S )Nrf   r  r
   s    r   "testSubnetFailsForNegativeCidrDiffz1IpaddrUnitTest.testSubnetFailsForNegativeCidrDiff?  sC   *d-5==bAA	C 	C 	C*d+33B77	9 	9 	9*d-5==bAA	C 	C 	C*d+33B77	9 	9 	9*d4<DDRHH	J 	J 	J*d2::2>>	@ 	@ 	@ 	@ 	@r   c                    |                      | j        j        d           |                      t          | j                                                  d         j        d           |                      | j                                        j        d           |                      | j        j        d           |                      t          | j                                                  d         j        d           |                      | j                                        j        d           |                      | j        j        d           |                      t          | j                                                  d         j        d           |                      | j                                        j        d           d S )NrG  r   r   i               l            l             )r%   r*  num_addressesrP  r  r  r-  r0  r
   s    r   testGetNum_Addressesz#IpaddrUnitTest.testGetNum_AddressesM  s   *8#>>>d/7799::1=K	 	 	*3355CSIII*8:NOOOd/7799::1=K,	. 	. 	.*3355C-	/ 	/ 	/1?AUVVVd6>>@@AA!DR,	. 	. 	.1::<<J-	/ 	/ 	/ 	/ 	/r   c                    |                      t          j        d          | j                   |                     t          j        d          | j                   t          j        d          }|                      || j                   |                     t          j        d                              t          j        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  r   r  r  __contains__)r   addr1s     r   testContainszIpaddrUnitTest.testContains^  s    i-n=='	) 	) 	)0>>*	, 	, 	, %j11eT./// 	.|<<II%l335 5 	6 	6 	6 	6 	6r   c                    |                      t          | j        d                   d           |                     t          | j        j        d           |                      t          | j        d                   d           |                     t          | j        j        d           |                      t          | j        d                   d           |                     t          | j        j        d           d S )Nru   1.2.3.5rG  z2001:658:22a:cafe::5r  )r%   rF  r*  r@   
IndexError__getitem__r-  r0  r
   s    r   testNthzIpaddrUnitTest.testNthk  s    T.q122I>>>*d&7&CSIIIT.q122/	1 	1 	1*d&7&CWMMMT5a899/	1 	1 	1*d&>&JGTTTTTr   c                    t          j        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.143rf   )r   r  r%   ry  rP  rF  )r   rO   	addr_lists      r   testGetitemzIpaddrUnitTest.testGetitemv  s    $%EFFT^,,,JJ	)3y|+<+<===)3tAw<<888)3y}+=+=>>>)3tBx==9992R11111r   c                    |                      | j        t          j        d          k               |                     | j        t          j        d          k               |                     | j        t          j        d          k               |                     | j        t          j        d          k               |                     | j        dk               |                     | j        g k               |                     | j        dk               |                      | j        t          j        d          k               |                     | j        t          j        d          k               |                     | j        t          j        d          k               |                     | j        dk               |                     | j        g k               |                     | j        dk               |                      | j        t          j        d	          k               |                     | j        t          j        d
          k               |                     | j        t          j        d          k               |                     | j        t          j        d          k               |                     | j        t          j        d          k               |                     | j        dk               |                     | j        g k               |                     | j        dk               d S )Nr#  
1.2.3.4/23::1.2.3.4/24::1.2.3.4%scope/24r5   r   2001:658:22a:cafe:200::1/642001:658:22a:cafe:200::1/63!2001:658:22a:cafe:200::1%scope/64!2001:658:22a:cafe:200::1%scope/63)r   r)  r   r  r  r  r,  r/  r
   s    r   	testEqualzIpaddrUnitTest.testEqual  sn   +!/==> 	? 	? 	?,"0>>? 	@ 	@ 	@,"0@@A 	B 	B 	B,"01EFFG 	H 	H 	H,2333,2333,1222+#$ABBC 	D 	D 	D,#$ABBC 	D 	D 	D,"0>>? 	@ 	@ 	@,2333,2333,12222#$GHHI 	J 	J 	J3#$GHHI 	J 	J 	J3#$ABBC 	D 	D 	D3#$ABBC 	D 	D 	D3"0>>? 	@ 	@ 	@3r9:::3r9:::3q899999r   c                 	   |                      | j        t          j        d          k               |                     | j        t          j        d          k               |                     | j        t          j        d          k               |                     | j        t          j        d          k               |                     | j        dk               |                     | j        g k               |                     | j        dk               |                     | j        t          j        d          k               |                     | j        dk               |                     | j        g k               |                     | j        dk               |                      | j        t          j        d          k               |                     | j        t          j        d	          k               |                     | j        t          j        d          k               |                     | j        dk               |                     | j        g k               |                     | j        dk               |                     | j	        t          j        d
          k               |                     | j	        dk               |                     | j	        g k               |                     | j	        dk               |                      | j
        t          j        d          k               |                     | j
        t          j        d          k               |                     | j
        t          j        d          k               |                     | j
        t          j        d	          k               |                     | j
        t          j        d          k               |                     | j
        dk               |                     | j
        g k               |                     | j
        dk               |                     | j        t          j        d
          k               |                     | j        dk               |                     | j        g k               |                     | j        dk               d S )Nr#  r  r  r  r5   r   r  r  r  r-  r  r  )r  r)  r   r  r   r  r(  r   r,  r+  r/  r.  r
   s    r   testNotEqualzIpaddrUnitTest.testNotEqual  s   ,"0>>? 	@ 	@ 	@+!/==> 	? 	? 	?+!/??@ 	A 	A 	A+!/0DEEF 	G 	G 	G+r1222+r1222+q0111)".y99: 	; 	; 	;)R/000)R/000)Q.///,#$ABBC 	D 	D 	D+#$ABBC 	D 	D 	D+!/==> 	? 	? 	?+r1222+r1222+q0111)!-i889 	: 	: 	:)R/000)R/000)Q.///3#$GHHI 	J 	J 	J2#$GHHI 	J 	J 	J2#$ABBC 	D 	D 	D2#$ABBC 	D 	D 	D2!/==> 	? 	? 	?2b89992b89992a78880!-i889 	: 	: 	:0B67770B67770A566666r   c                 p    |                      t          t          j        d                    d           d S )Nz1.2.3.4/255.255.255.255rC  r%   rF  r   r  r
   s    r   testSlash32Constructorz%IpaddrUnitTest.testSlash32Constructor  sE    Y4-/ / 0 01=	? 	? 	? 	? 	?r   c                     |                      t          t          j        d                    d           |                      t          t          j        d                    d           d S )Nr  r  )r%   rF  r   r  r
   s    r   testSlash128Constructorz&IpaddrUnitTest.testSlash128Constructor  sl    Y4Y??@@"+	- 	- 	-Y4_EEFF"1	3 	3 	3 	3 	3r   c                 p    |                      t          t          j        d                    d           d S )Nz1.2.3.4/0.0.0.0r|  r  r
   s    r   testSlash0Constructorz$IpaddrUnitTest.testSlash0Constructor  s=    Y45FGGHH%	' 	' 	' 	' 	'r   c                    t          j        d          }t          j        d          }t          j        d          }t          j        d          }t          j        d          }t          j        d          }t          j        ||||||g          }|                     t	          |          t          j        d          t          j        d          g           t          j        d          }t          j        d          }t          j        d          }t          j        d          }t          j        ||||g          }|                     t	          |          t          j        d          g           t          j        d          }t          j        d	          }t          j        d
          }t          j        d          }t          j        d          }t          j        d          }t          j        ||||||g          }|                     t	          |          t          j        d          t          j        d          g           t          j        ||g          }|                     t	          |          t          j        d          g           t          j        d          x}}	|                     t	          t          j        ||	g                    |g           t          j        d          x}}	|                     t	          t          j        ||	g                    t          j        d          g           t          j        d          }t          j        d          }t          j        d          }t          j        |||g          }|                     t	          |          |g           t          j        d          }t          j        d          }t          j        d          }t          j        |||g          }|                     t	          |          |g           t          j        d          t          j        d          ft          j        d          t          j        d          ft          j        d          t          j        d          fg}
|
D ]-\  }}| 	                    t          t           j        ||g           .t          j        d          t          j        d          ft          j        d          t          j        d          ft          j        d          t          j        d          fg}
|
D ]-\  }}| 	                    t          t           j        ||g           .d S )N1.1.1.0rt  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/24
1.1.1.0/24
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::/120	2001::/96z2001::%scope/100z2001::%scope/120z2001::%scope/96r  z
1.1.0.0/32z
2001::/128r  z2001::%scope/128)r   r   collapse_addressesr%   rP  r  r  r  r  r@   rA   )r   rS  rT  rU  ip4ip5ip6	collapsedip_same1ip_same2addr_tupless              r   testCollapsingzIpaddrUnitTest.testCollapsing  sW   #I..#I..#I..#I..#I..#I..0#sCc*, ,	i&|44&|446	7 	7 	7
 #I..#I..#I..#I.. 0#sC1EFF	i#/==>	@ 	@ 	@ #L11#L11#L11#L11#L11 #L110#sCc582: ; ;	i#/==#/==?	@ 	@ 	@
 0#s<<	i#/==>	@ 	@ 	@ (3LAAA8i:x(* * + +"	% 	% 	%
 (3I>>>8i:x(* * + +#.|<<=	? 	? 	? #L11#L11#K000#sCAA	i3%000#$677#$677#$5660#sCAA	i3%000 %i00%e,,.&|44&|446&|44&|446
 $ 	* 	*HCi)E"Cj* * * * %i00%k224&|44&'9::<&|44&'9::<
 $ 	* 	*HCi)E"Cj* * * *	* 	*r   c           
      "
   t           j        }t          j        d          }t          j        d          } G d dt           j                  } |d          } |d          }|                     t
          t           |||                     |                     t          t           ||t          j        d                               |                     t          t           ||t          j        d                               |                     t           |||                    d         t          j	        d                     t          j        d	          }|                     t           |||                    t          j	        d
          t          j	        d	          g           t          j
        d          }t          j
        t           j
        j                  }|                     t          j        d          gt           |||                               t          j        d          }t          j        d          }|                     t           |||                    d         t          j	        d                     t          j        d          }|                     t           |||                    t          j	        d          t          j	        d          g           t          j        d          }t          j        d          }|                     t           |||                    d         t          j	        d                     t          j        d          }|                     t           |||                    t          j	        d          t          j	        d          g           |                     t
          t           |t          j        d          t          j        d                               |                     t          t           |t          j	        d          t          j	        d                               |                     t          t           |t          j	        d          t          j	        d                               |                     t          t           |t          j        d          t          j	        d                               d S )Nr  z	1.1.1.255c                   $    e Zd Zed             ZdS )3IpaddrUnitTest.testSummarizing.<locals>.IPv7Addressc                     dS )N   r0   r
   s    r   rc  z;IpaddrUnitTest.testSummarizing.<locals>.IPv7Address.versionV  s    qr   N)r*   r+   r,   r-   rc  r0   r   r   IPv7Addressr  U  s-          X  r   r  r  r  r   r  z1.1.1.8z
1.1.1.0/29r  r  z$1:ffff:ffff:ffff:ffff:ffff:ffff:ffffz1::/16z2::z2::/128z	1::%scopez*1:ffff:ffff:ffff:ffff:ffff:ffff:ffff%scopez	2::%scopez1.1.0.0r{   )r   summarize_address_ranger  r   r@   r  rP  rA   r%   r  r   	_ALL_ONESr  )r   	summarizerS  rT  r  ip_invalid1ip_invalid2s          r   testSummarizingzIpaddrUnitTest.testSummarizingM  s    5	"9--";//	 	 	 	 	)/ 	 	 	 "k%((!k%((*d#)K==	? 	? 	? 	)T#)C)>u)E)EFF	H 	H 	H)T#)C)>{)K)KLL	N 	N 	N 	iiS112215"-l;;	= 	= 	= "9--iiS1122#.|<<#.y99;	< 	< 	< #A&&#I$9$CDD)/<<=iiS1122	4 	4 	4 "5))"#IJJiiS112215"-h77	9 	9 	9 "5))iiS1122#.x88#.y99;	< 	< 	< ";//"#OPPiiS112215"-h77	9 	9 	9 ";//iiS1122#.x88#.y99;	< 	< 	<
 	*d#)I$8$C$C$-$8$C$CE E	F 	F 	F 	)T#)I$8$C$C$-$8$C$CE E	F 	F 	F 	)T#)I$8$C$C$-$8$C$CE E	F 	F 	F 	)T#)I$8$>$>$-$8$C$CE E	F 	F 	F 	F 	Fr   c                    |                      t          j        d          t          j        d          k               |                      t          j        d          t          j        d          k               |                      t          j        d          t          j        d          k               |                      t          j        d          t          j        d          k               |                      t          j        d          t          j        d          k               |                      t          j        d          t          j        d          k               d S )Nrt  r  r  ::2r  r  )r   r   r  r
   s    r   testAddressComparisonz$IpaddrUnitTest.testAddressComparison  sP   	,Y77!,Y778 	9 	9 	9	,Y77!,Y778 	9 	9 	9	,U33!,U334 	5 	5 	5	,U33!,U334 	5 	5 	5	,[99!,[99: 	; 	; 	;	,[99!,[99: 	; 	; 	; 	; 	;r   c                    |                      t          j        d          t          j        d          k               |                      t          j        d          t          j        d          k                |                      t          j        d          t          j        d          k                |                      t          j        d          t          j        d          k                |                      t          j        d          t          j        d          k               |                      t          j        d          t          j        d          k               |                      t          j        d          t          j        d          k               |                      t          j        d          t          j        d          k               |                      t          j        d          t          j        d          k                |                      t          j        d          t          j        d          k                |                      t          j        d          t          j        d          k                |                      t          j        d          t          j        d          k               |                      t          j        d          t          j        d          k               |                      t          j        d          t          j        d          k               |                      t          j        d	          t          j        d	          k               |                      t          j        d	          t          j        d
          k                |                      t          j        d	          t          j        d          k                |                      t          j        d          t          j        d	          k                |                      t          j        d
          t          j        d	          k               |                      t          j        d          t          j        d	          k               |                      t          j        d	          t          j        d          k               |                     t          j        d	          t          j        d          k               |                      t          j        d	          t          j        d          k                |                      t          j        d	          t          j        d          k                |                      t          j        d          t          j        d          k                |                      t          j        d
          t          j        d          k               |                      t          j        d          t          j        d          k               |                      t          j        d	          t          j        d          k               |                     t          j        d          t          j        d	          k               |                      t          j        d          t          j        d
          k                |                      t          j        d          t          j        d          k                |                      t          j        d          t          j        d	          k                |                      t          j        d          t          j        d	          k               |                      t          j        d          t          j        d	          k               |                      t          j        d          t          j        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/48z::1%scope/64z::1%scope/80z::2%scope/64z::2%scope/48)r   r   r  r  r
   s    r   testInterfaceComparisonz&IpaddrUnitTest.testInterfaceComparison  s   	.|<<!.|<<= 	> 	> 	>	.|<<!.|<<= 	> 	> 	>	.|<<!.|<<= 	> 	> 	>	.|<<!.|<<= 	> 	> 	>	.|<<!.|<<= 	> 	> 	>	.|<<!.|<<= 	> 	> 	>	.|<<!.|<<= 	> 	> 	> 		.x88!.x889 	: 	: 	:	.x88!.x889 	: 	: 	:	.x88!.x889 	: 	: 	:	.x88!.x889 	: 	: 	:	.x88!.x889 	: 	: 	:	.x88!.x889 	: 	: 	:	.x88!.x889 	: 	: 	: 		.~>>!.~>>? 	@ 	@ 	@	.~>>!.~>>? 	@ 	@ 	@	.~>>!.~>>? 	@ 	@ 	@	.~>>!.~>>? 	@ 	@ 	@	.~>>!.~>>? 	@ 	@ 	@	.~>>!.~>>? 	@ 	@ 	@	.~>>!.~>>? 	@ 	@ 	@ 	/??!.x889 	: 	: 	:	.~>>!.x889 	: 	: 	:	.~>>!.x889 	: 	: 	:	.~>>!.x889 	: 	: 	:	.~>>!.x889 	: 	: 	:	.~>>!.x889 	: 	: 	:	.~>>!.x889 	: 	: 	: 	/99!.~>>? 	@ 	@ 	@	.x88!.~>>? 	@ 	@ 	@	.x88!.~>>? 	@ 	@ 	@	.x88!.~>>? 	@ 	@ 	@	.x88!.~>>? 	@ 	@ 	@	.x88!.~>>? 	@ 	@ 	@	.x88!.~>>? 	@ 	@ 	@ 	@ 	@r   c                     t          j        d          }t          j        d          }t          j        d          }|                     ||k                |                     ||k               |                     |                    |          d           |                     |                    |          d           |                     |                    |          d           |                     |                    |          d           |                     |                    |          d           |                     |                                |                                k                t          j        d          }t          j        d          }t          j        d	          }|                     ||k                |                     ||k               |                     |                    |          d           |                     |                                |                                k                |                     t          | j	        j        | j
                   t          j        d
          }t          j        d          }|                     t          |j        |           |                     t          |j        |           |                     t          |j        |           |                     t          |j        |           t          j        d          }|                     ||k                |                     ||k               t          j        d          }|                     ||k                |                     ||k                |                     ||k               |                     ||k               t          j        d          }|                     ||k                |                     ||k                |                     ||k               |                     ||k               t          j        d          }t          j        d          }t          j        d          }t          j        d          }||||g}||||g}|                                 |                     ||           ||||g}|                                 |                     ||           |                     |                    t          j        d                    t(                     |                     |                    t          j        d                    t(                     |                     t          j        d          t          j        d          k               |                     t          j        d          t          j        d          k               |                     t          j        d          t          j        d          k               |                     t          j        d          t          j        d          k               |                     t          j        d          t          j        d          k               |                     t          j        d          t          j        d          k               d S )Nr  z
1.1.1.0/32r  r   rf   r?   z2001:2000::/96z2001:2001::/96z2001:ffff:2000::/96::/0r  z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.2rt  r  r  r  )r   r  r   r%   compare_networks_get_networks_keyr  r@   rA   r*  r-  r  r  r  r  r  r  sortassertIsr  r  )	r   rS  rT  rU  re  rd  r  r  unsorteds	            r   testNetworkComparisonz$IpaddrUnitTest.testNetworkComparison  s0   #L11#L11#L11c	"""c	"""--c22A666 	--c22B777--c22A666--c22B777--c22A666--//#2G2G2I2IIJJJ#$455#$455#$9::c	"""c	"""--c22B777--//#2G2G2I2IIJJJ 	)+<+	- 	- 	- &v..&{33)T[$777)T[$777)T[$777)T[$777 "?33s###s###"=11c	"""s###s###c	""""=11c	"""s###s###c	""" "?33"<00"?33"<00sC%c3'***c3'***cjj!5l!C!CDD$	& 	& 	&cjj!5l!C!CDD$	& 	& 	& 		,Y77!,Y778 	9 	9 	9	,Y77!,Y778 	9 	9 	9-i88!,Y778 	9 	9 	9 		,U33!,U334 	5 	5 	5	,U33!,U334 	5 	5 	5-e44"-e445 	6 	6 	6 	6 	6r   c                     |                      t          t          j        d           |                      t          t          j        d           |                      t          t          j        d           d S )Nz192.168.1.1/24z::1/120z::1%scope/120)r@   r  r   r  r
   s    r   testStrictNetworksz!IpaddrUnitTest.testStrictNetworksH  sZ    *i&:<LMMM*i&:IFFF*i&:OLLLLLr   c                    t          j        d          }t          j        d          }t          j        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*  overlapsr  )r   r  other2other3s       r   testOverlapszIpaddrUnitTest.testOverlapsM  s    %l33&|44&}55)22599:::*33F;;<<<//00000r   c                    d}t          j        |          }t          j        d|z            }|                     t	          |j                  t	          |j                             t          j        d|z            }|                     |j        |j                   |                     t           j        t           j        d           d S )Nr]   z::%sz	::ffff:%sz2001:1.1.1.1:1.1.1.1)	r   r  r  r%   r[  r9  r  r@   r   )r   ipv4_stringrd  v4compat_ipv6v4mapped_ipv6s        r   testEmbeddedIpv4zIpaddrUnitTest.testEmbeddedIpv4U  s    #&{33!/0DEE]-..DG===!/k0IJJM,dg666)5y7N0	2 	2 	2 	2 	2r   c                    |                      t          j        d          t          j        d                     |                      t          j        d          t          j        d                     |                      t          j        d          t          j        d                     |                      t          j        d          t          j        d                     |                     t          j        d          t          j        d                     |                     t          j        d          t          j        d                     |                     t          j        d          t          j        d                     |                     t          j        d          t          j        d                     d S )	Nz::FFFF:192.0.2.1z::FFFF:c000:201zFFFF::192.0.2.1zFFFF::c000:201z::FFFF:192.0.2.1%scopez::FFFF:c000:201%scopezFFFF::192.0.2.1%scopezFFFF::c000:201%scope)r%   r   r  r  r
   s    r   testIPv6AddressTooLargez&IpaddrUnitTest.testIPv6AddressTooLarge`  s   -.@AA#./@AA	C 	C 	C 	-.?@@#./?@@	B 	B 	B 	-.FGG#./FGG	I 	I 	I-.EFF#./EFF	H 	H 	HI01IJJ%01BCC	E 	E 	EI01HII%01ABB	D 	D 	DI01CDD#./FGG	I 	I 	II01BCC#./EFF	H 	H 	H 	H 	Hr   c                     |                      | j        j        d           |                      | j        j        d           |                      | j        j        d           d S )Nr`  ra  )r%   r(  rc  r+  r.  r
   s    r   testIPVersionzIpaddrUnitTest.testIPVersionu  s\    *2A666*2A666191=====r   c                     |                      | j        j        d           |                      | j        j        d           |                      | j        j        d           d S )Nrd  r   )r%   r)  max_prefixlenr,  r/  r
   s    r   testMaxPrefixLengthz"IpaddrUnitTest.testMaxPrefixLengthz  s\    ,:B???,:C@@@3A3GGGGGr   c                    |                      | j        j        d           |                      t          j        d          j        d           |                      | j        j        d           |                      t          j        d          j        d           |                      t          j        d          j        d           |                      | j        j        d           |                      t          j        d	          j        d           |                      t          j        d
          j        d           d S )NrB  rj  rk  rl  rm  rn  z::1:0:0:0:0s                  zffff:2:3:4:ffff::%scopez::1:0:0:0:0%scope)r%   r(  packedr   r  r+  r  r.  r
   s    r   
testPackedzIpaddrUnitTest.testPacked  sh   *1,	. 	. 	.01BCCJ,	. 	. 	.*1=	> 	> 	> 	01DEEL*	+ 	+ 	+ 	0??F@	B 	B 	B18=	> 	> 	> 	01JKKR*	+ 	+ 	+ 	01DEEL@	B 	B 	B 	B 	Br   c                    t          j        d          }t          j        d          }t          j        d          }t          j        d          }|                     t           j        t          |                     |                     t           j        t          |                     |                     t           j        t          |                     |                     t           j        t          |                     d S )Nr-  rX  )	r   r  r  r%   r  r  r   r  r   )r   ipv4netipv4addripv6netipv6addrs        r   
testIpTypezIpaddrUnitTest.testIpType  s    &y11'	22&{33'44.W>>>.X???.W>>>.X?????r   c                    |                      dt          j        d          j                   |                      dt          j        d          j                   |                      dt          j        d          j                   |                      dt          j        d          j                   |                      dt          j        d          j                   |                      dt          j        d          j                   |                      dt          j        d          j                   |                      dt          j        d          j                   |                      dt          j        d	          j                   |                      dt          j        d
          j                   |                      dt          j        d          j                   |                      dt          j        d          j                   |                      dt          j        d          j                   |                      dt          j        d          j                   |                      dt          j        d          j                   |                      dt          j        d          j                   |                      dt          j        d          j                   |                      dt          j        d          j	                   |                      dt          j        d          j                   |                      dt          j        d          j	                   |                      dt          j
        d          j                   |                      dt          j
        d          j                   |                      dt          j
        d          j                   |                      dt          j
        d          j                   |                      dt          j
        d          j                   |                      dt          j
        d          j                   |                      dt          j
        d          j                   |                      dt          j
        d          j                   |                      dt          j
        d          j                   |                      dt          j
        d	          j                   |                      dt          j
        d
          j                   |                      dt          j
        d          j                   |                      dt          j
        d          j                   |                     t          j
        d          j	                   |                     t          j
        d          j	                   |                      dt          j
        d          j                   |                      dt          j
        d          j                   |                      dt          j
        d          j                   |                      dt          j        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/24r[   z	224.1.1.1z	240.0.0.1z239.255.255.255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
   s    r   testReservedIpv4zIpaddrUnitTest.testReservedIpv4  s\   y5      ,	. 	. 	.	 4[ A A NOOOy3K@@LMMMy5  "  "",	. 	. 	.	 4] C C NOOOy3  "  "",	. 	. 	.	 4Z @ @ KLLL	 4Z @ @ LMMMy3  "  "",	. 	. 	.	 4\ B B MNNN"-.>??M	O 	O 	O 	#024 44A	C 	C 	C 	#024 44A	C 	C 	C 	#.24 44?	A 	A 	A 	y3 !  !!,	. 	. 	.	 4[ A A MNNN"-o>>I	K 	K 	K	 4_ E E OPPP"-.>??J	L 	L 	L"-n==G	I 	I 	I 	y3I>>MNNNy3K@@MNNN	 4[ A A NOOOy3K@@LMMM"-.?@@L	N 	N 	N 	y3MBBMNNN	 4] C C NOOOy3  "  "",	. 	. 	.	 4Z @ @ KLLLy3  "  "",	. 	. 	.	 4\ B B MNNN"-.?@@N	P 	P 	P"-.?@@N	P 	P 	P 		,[99CDDD-m<<FGGG#./@AAM	O 	O 	Oy3LAAMNNN	 4[ A A MNNNy3I>>MNNNNNr   c                 	   |                      dt          j        d          j                   |                      dt          j        d          j                   |                      dt          j        d          j                   |                      dt          j        d          j                   |                      dt          j        d          j                   |                      dt          j        d          j                   |                      dt          j        d	          j                   |                      dt          j        d
          j                   |                      dt          j        d          j                   |                      dt          j        d          j                   |                      dt          j        d          j                   |                      dt          j        d          j                   |                      dt          j        d          j                   |                      dt          j        d          j                   |                      dt          j        d          j                   |                      dt          j        d          j                   |                      dt          j        d          j                   |                      dt          j        d          j                   |                      dt          j        d          j                   |                      dt          j        d          j                   |                      dt          j        d          j                   |                      dt          j        d          j                   |                      dt          j        d          j                   |                      dt          j        d          j                   |                      dt          j        d          j                   |                      dt          j        d          j                   |                      dt          j        d          j                   |                      dt          j        d          j                   d S )NFr  z	1.0.0.0/8Tz	0.0.0.0/8z
10.0.0.0/8z127.0.0.0/8z169.254.0.0/16z172.16.0.0/12z192.0.0.0/29z192.0.0.170/31r_  z192.168.0.0/16z198.18.0.0/15z198.51.100.0/24z203.0.113.0/24z240.0.0.0/4z255.255.255.255/32r"  z::ff/128r  ::/128z::ffff:0:0/96z100::/64z	2001::/23z2001:2::/48r  z2001:10::/28zfc00::/7z	fe80::/10)r%   r   r  rI  r
   s    r   testPrivateNetworksz"IpaddrUnitTest.testPrivateNetworks  s   	 4[ A A LMMM	 4[ A A LMMMy3K@@KLLLy3LAALMMMy3MBBMNNNy34DEEPQQQy3ODDOPPPy3NCCNOOOy34DEEPQQQy3NCCNOOOy34DEEPQQQy3ODDOPPPy34EFFQRRRy34DEEPQQQy3MBBMNNNy34HIITUUU	 4V < < GHHH	 4Z @ @ KLLLy3I>>IJJJy3H==HIIIy3ODDOPPPy3J??JKKKy3K@@KLLLy3MBBMNNNy3ODDOPPPy3NCCNOOOy3J??JKKKy3K@@KLLLLLr   c                    |                      dt          j        d          j                   |                      dt          j        ddz  dz
            j                   |                      dt          j        d          j                   |                      dt          j        d          j                   |                      dt          j        d	          j                   |                      dt          j        d
          j                   |                      dt          j        d          j                   |                      dt          j        d          j                   |                      dt          j        d          j                   |                      dt          j        d          j                   |                      dt          j        d          j                   |                      dt          j        d          j                   |                      dt          j        d          j                   |                      dt          j        d          j                   |                      dt          j        d          j                   |                      dt          j        d          j                   |                      dt          j        d          j                   |                      dt          j        d          j                   |                      dt          j        d          j                   |                      dt          j        d          j                   |                      dt          j        d          j	                   |                      dt          j        d          j	                   |                      dt          j        d          j	                   |                      dt          j        d          j                   |                      dt          j        d          j
                   |                      dt          j        d          j                   |                      dt          j        ddz  dz
            j                   |                      dt          j        d          j                   |                      dt          j        d          j                   |                      dt          j        d	          j                   |                      dt          j        d
          j                   |                      dt          j        d          j                   |                      dt          j        d          j                   |                      dt          j        d          j                   |                      dt          j        d          j                   |                      dt          j        d          j                   |                      dt          j        d          j                   |                      dt          j        d          j                   |                      dt          j        d          j                   |                      dt          j        d          j                   |                      dt          j        d          j                   |                      dt          j        d          j                   |                      dt          j        d          j                   |                      dt          j        d          j                   |                      dt          j        d          j	                   |                      dt          j        d          j	                   |                      dt          j        d          j                   |                      dt          j        d          j                   d S )NTzffff::r   r   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/127r{   r  z0::0r  z::/127z2001::1/128z
200::1/128z100::z4000::1/128)r%   r   r  rG  is_site_localrI  rJ  r  rK  rM  rL  r  rH  r
   s    r   testReservedIpv6zIpaddrUnitTest.testReservedIpv6		  s^   y3H==JKKKy3AsFQJ??LMMMy3H==JKKK	 4X > > KLLLy3H==KLLLy3' )  ))6	8 	8 	8	 4! !+	- 	- 	-	 4X > > LMMMy3H==HIIIy3' )  ))3	5 	5 	5	 4] C C NOOO	 4X > > IJJJy3H==KLLLy3   ,	. 	. 	.	 4! !,	. 	. 	.	 4X > > LMMMy5kBBNOOO	 6y A A MNNN	 4T : : FGGG	 4U ; ; GHHHy3F;;JKKK	 4U ; ; JKKK	 4X > > MNNN"-m<<G	I 	I 	I"-l;;E	G 	G 	G 	y3H==JKKKy3AsFQJ??LMMMy3H==JKKK	 4X > > KLLLy3H==KLLLy3' )  ))6	8 	8 	8	 4! !+	- 	- 	-	 4X > > LMMMy3H==HIIIy3' )  ))3	5 	5 	5	 4] C C NOOO	 4X > > IJJJy3H==KLLLy3   ,	. 	. 	.	 4! !,	. 	. 	.	 4X > > LMMMy3K@@LMMMy3E::FGGG	 4U ; ; GHHHy3F;;JKKK	 4U ; ; JKKK 	y3G<<HIIIy3MBBNOOOOOr   c                 \   |                      t          j        d          j        t          j        d                     |                      t          j        d          j        d            |                      t          j        d          j        t          j        d                     d S )N::ffff:192.168.1.1rF  z
::c0a8:101z::ffff:c0a8:101)r%   r   r  ipv4_mappedr
   s    r   testIpv4MappedzIpaddrUnitTest.testIpv4MappedV	  s    $%9::F$]33	5 	5 	5 	-l;;GNNN-.?@@L"-m<<	> 	> 	> 	> 	>r   c                     |                      dt          j        d          j                   |                      dt          j        d          j                   d S )NTrV  Fz::ffff:172.32.0.0)r%   r   r  rI  r
   s    r   testIpv4MappedPrivateCheckz)IpaddrUnitTest.testIpv4MappedPrivateCheck^	  sl    i*+?@@K	M 	M 	My+,?@@K	M 	M 	M 	M 	Mr   c                 "   t          j        d          }t          j        d          }t          j        d          }t          j        d          }t          j        d          }t          j        d          }|                     t	          t          |                    |                              t          j        d          t          j        d          g           |                     t          t
          |                    |                     |                     t          t
          |                    |                     |                     t          t
          |                    |                     |                     t          |                    |                    g            |                     t	          t          |                    |                              t          j        d	          t          j        d
          t          j        d          t          j        d          t          j        d          t          j        d          t          j        d          t          j        d          g           d S )N10.1.1.0/24z10.1.1.0/26z10.2.1.0/24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  rP  address_excluder@   r  rA   r   r  addr2addr3addr4addr5addr6s          r   testAddrExcludezIpaddrUnitTest.testAddrExcluded	  s   $]33$]33$]33$Z00$%566$]33U%:%:5%A%A B BCC#.~>>#.??A	B 	B 	B 	*dE,A,A%,H,HIII)T5+@+@+G+GHHH)T5+@+@+G+GHHHe33E::;;R@@@U%:%:5%A%A B BCC#.}==#.}==#.}==#.}==#.~>>#.~>>#.~>>#.??A	B 	B 	B 	B 	Br   c                    |                      t          t          j        d                    t          t          j        d                               |                      t          t          j        d                    t          t          j        d                               |                      t          t          j        d                    t          t          j        d                               |                      t          t          j        d                    t          t          j        t          t          j        d          j                                                 t          j        d          }t          j        d          }i }d || j        <   d || j	        <   d ||<   d ||<   | 
                    | j        |           | 
                    ||           d S )Nr\  r]  r-  r  )r%   hashr   r  r  r  r[  rb  r(  r+  r  )r   rS  rT  dummys       r   testHashzIpaddrUnitTest.testHash|	  s   i4]CCDDi4]CCDD	F 	F 	Fi2=AABBi2=AABB	D 	D 	Di2:>>??i2:>>??	A 	A 	A 	i29==>>i2	,Y77;<<> > ? ?	@ 	@ 	@ ":.."5))#'d #'d c
c
d'///c5!!!!!r   c                     | j         }|                     d|j                   | j        }|                     t
          |j        ddz  dz              d S )Nr$  r   r   r?   )r*  r%   
compressedr-  r@   r  _string_from_ip_intr  s     r   testIPBaseszIpaddrUnitTest.testIPBases	  sS    s~666*c&=q#vzJJJJJr   c                     | j         }|                     d|j                   |                     d|j                   |                     d|j                   |                     dt          |                     d S )Nr&  z)2001:658:22a:cafe::/ffff:ffff:ffff:ffff::z)2001:658:22a:cafe::/::ffff:ffff:ffff:ffff)r-  r%   with_prefixlenwith_netmaskwith_hostmaskrF  r  s     r   testIPv6NetworkHelpersz%IpaddrUnitTest.testIPv6NetworkHelpers	  s    133EFFFD)	+ 	+ 	+D*	, 	, 	,13s88<<<<<r   c                     | j         }|                     d|j                   |                     d|j                   |                     d|j                   |                     dt          |                     d S )Nr$  z1.2.3.0/255.255.255.0z1.2.3.0/0.0.0.255)r*  r%   ro  rp  rq  rF  r  s     r   testIPv4NetworkHelpersz%IpaddrUnitTest.testIPv4NetworkHelpers	  sy    s'9:::0#2BCCC,c.?@@@s3xx00000r   c                    t          j        d          }t          j        |          }t          j        d          }t          j        |          }t          j        d          }t          j        d          }|                     ||           |                     ||           |                     |t          j        |                     |                     |t          j        |                     d S )Nr\  r  rt  rq  )r   r  r  r   r   r%   r_  s          r   testCopyConstructorz"IpaddrUnitTest.testCopyConstructor	  s    $]33$U++&'DEE&u--%i00%&@AA&&&&&&	 5e < <===	 5e < <=====r   c           	      0   i 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d d!d"d#d$i}t          |                                          D ]:\  }}|                     |t          t	          j        |                               ;d S )%Nz1:2:3:4:5:6:7:8z1:2:3:4:5:6:7:8/128z2001:0:0:4:0:0:0:8z2001:0:0:4::8/128z2001:0:0:4:5:6:7:8z2001::4:5:6:7:8/128z2001:0:3:4:5:6:7:8z2001:0:3:4:5:6:7:8/128z0:0:3:0:0:0:0:ffffz0:0:3::ffff/128z0:0:0:4:0:0:0:ffffz::4:0:0:0:ffff/128z0:0:0:0:5:0:0:ffffz::5:0:0:ffff/128z1:0:0:4:0:0:7:8z1::4:0:0:7:8/128z0:0:0:0:0:0:0:0rP  z0:0:0:0:0:0:0:0/0r"  z0:0:0:0:0:0:0:1r  z*2001:0658:022a:cafe:0000:0000:0000:0000/66r  rX  z::102:304/128z1:2:3:4:5:ffff:1.2.3.4z1:2:3:4:5:ffff:102:304/128z::7:6:5:4:3:2:1z0:7:6:5:4:3:2:1/128z::7:6:5:4:3:2:0z0:7:6:5:4:3:2:0/128z7:6:5:4:3:2:1::z7:6:5:4:3:2:1:0/128z0:6:5:4:3:2:1::z0:6:5:4:3:2:1:0/128)rP  itemsr%   rF  r   r  )r   test_addressesuncompressedrk  s       r   testCompressIPv6Addressz&IpaddrUnitTest.testCompressIPv6Address	  sa   4 "5 !"7 !":	
 !"3 !"6 !"4 1 x   y 9$  %&B  4!" 4#$ 4%& 4' * )-^-A-A-C-C(D(D 	  	 $L*ZY-D. . * *        	  	 r   c                    t          j        d          }t          j        d          }t          j        d          }t          j        d          }|                     d|j                   |                     dt          j        d          j                   |                     d|j                   |                     d	|j                   |                     d|j                   d S )
Nz2001::12001:0:5ef5:79fd:0:59d:a0e5:ba1r  z192.168.178.1z+2001:0000:0000:0000:0000:0000:0000:0001/128z+0000:0000:0000:0000:0000:0000:0000:0001/128r  z'2001:0000:5ef5:79fd:0000:059d:a0e5:0ba1z*2001:0000:0000:0000:0000:0000:0000:0000/96)r   r  r   r  r   r%   exploded)r   r  r`  ra  rb  s        r   testExplodeShortHandIpStrz(IpaddrUnitTest.testExplodeShortHandIpStr	  s    '	22%&GHH%k22%o66F	) 	) 	)F"0;;D	F 	F 	F 	B	) 	) 	)E	) 	) 	)%.99999r   c                     t          j        d          }t          j        d          }|                     d|j                   |                     d|j                   d S )Nz	127.0.0.1r@  z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   r   r   r%   reverse_pointer)r   r  r`  s      r   testReversePointerz!IpaddrUnitTest.testReversePointer	  si    %k22%m44153HIII 2.	0 	0 	0 	0 	0r   c                     |                      dt          | j                             |                      dt          | j                             d S )NrA  r_  )r%   r[  r(  r+  r
   s    r   testIntRepresentationz$IpaddrUnitTest.testIntRepresentation	  sV    3t'8#9#9:::?T.//	1 	1 	1 	1 	1r   c                     |                      t          j        d          j        d           |                      t          j        d          j        d           d S )Nr?   r`  ra  )r%   r   r  rc  r  r
   s    r   testForceVersionzIpaddrUnitTest.testForceVersion	  sP    -a008!<<<.q1191=====r   c                    |                      | j        j        d           |                      | j        j        d           |                      | j        j        d           |                      | j        j        d           |                      | j        j        d           |                      | j        j        d           d S )Nr#  z1.2.3.4/255.255.255.0z1.2.3.4/0.0.0.255r  z.2001:658:22a:cafe:200::1/ffff:ffff:ffff:ffff::z.2001:658:22a:cafe:200::1/::ffff:ffff:ffff:ffff)r%   r)  ro  rp  rq  r,  r
   s    r   testWithStarzIpaddrUnitTest.testWithStar	  s    ,;\JJJ,90	2 	2 	2,:,	. 	. 	. 	,;6	8 	8 	8,9I	K 	K 	K 	,:I	K 	K 	K 	K 	Kr   c                    |                      d| j        j                   |                      d| j        j                   |                     | j        j        t          j        d                     |                     | j        j        t          j        d                     |                     d| j        j                   |                     d| j        j                   |                      d| j	        j                   |                      d| j	        j                   |                     | j	        j
        t          j        d                     |                     | j        j        j
        t          j        d                     |                     | j	        j        t          j        d                     |                     | j	        j        t          j        d                     |                     | j        j        j        t          j        d                     |                     | j        j        j        t          j        d                     |                     d| j	        j                   |                     d| j	        j                   |                     d| j        j        j                   |                     d| j        j        j                   d S )Nr  rH  r  z	0.0.0.255rY  r  rZ  )r  r*  __dict__r%   r  r   r   rH  r  r-  r\  r   r,  r  r
   s    r   testNetworkElementCachingz(IpaddrUnitTest.testNetworkElementCaching	  s   ,d.?.HIIIT%6%?@@@ 	*<".{;;	= 	= 	=*3".{;;	= 	= 	= 	)4+<+EFFFj$"3"<=== 	,d.?.HIIIT%6%?@@@ 	*:"./DEE	G 	G 	G,4D"./DEE	G 	G 	G 	/!"IJJ	L 	L 	L 	*3"./FGG	I 	I 	I'9!"IJJ	L 	L 	L 	,4="./FGG	I 	I 	I 	)4+<+EFFFj$"3"<===)4+>+F+OPPPj$"5"="FGGGGGr   c                    t          j        d          }t          j        d          }d}|                     ||ft          j        |          j                   d}|                     t          j        |          j                   d}|                     t          j        |          j                   t          j        d          }|                     t          j        d          t          j        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:fdd2r}  z94.245.121.253z95.26.244.94)r   r   r%   r  teredor  r   )r   serverclientteredo_addrbad_addrs        r   
testTeredozIpaddrUnitTest.testTeredo)
  s   &77&|44?&&)"-k::A	C 	C 	C8-h77>???<-h77>???  +,MNN)/0@AA#/??A$+	- 	- 	- 	- 	-r   c                     t          j        d          }t          j        d          }|                     t          j        d          |j                   |                     |j                   d S )Nz2002:ac1d:2d64::1z2000:ac1d:2d64::1z172.29.45.100)r   r  r%   r   	sixtofourr  )r   sixtofouraddrr  s      r   testsixtofourzIpaddrUnitTest.testsixtofour;
  sl    !,-@AA'(;<<.??&0	2 	2 	2+,,,,,r   c                     t          j        d          }t          j        d          }|                     |                                |                                           d S )Nr-  z2.3.4.5)r   r  r  __hash__)r   ipv4_address1ipv4_address2s      r   testV4HashIsNotConstantz&IpaddrUnitTest.testV4HashIsNotConstantC
  sV    !/	::!/	::M2244m6L6L6N6NOOOOOr   c                     t          j        d          }t          j        d          }|                     |                                |                                           d S )Nr%  z2001:658:22a:cafe:200:0:0:2)r   r  r  r  )r   ipv6_address1ipv6_address2s      r   testV6HashIsNotConstantz&IpaddrUnitTest.testV6HashIsNotConstantI
  sX    !/0MNN!/0MNNM2244m6L6L6N6NOOOOOr   N)Mr*   r+   r,   r1  r3  r:  rD  rH  rN  rV  r]  rh  ro  rr  rv  rz  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/  r4  r6  r8  r;  r>  rD  rN  rQ  rT  rX  rZ  re  ri  rm  rr  rt  rv  r{  r  r  r  r  r  r  r  r  r  r  r0   r   r   r!  r!    s       Y Y Y E E EDE DE DEN@C @C @CF@ @ @5 5 5O O O2 2 2"  00 0 0 5 5 5" " "A A AV V V, , ,B B BK K K
0 0 0"
0 
0 
0K K K*4G 4G 4GlK K K.
T 
T 
T- - -- - -- - -, , ,(@ @ @K K K@ @ @/ / /"6 6 6	U 	U 	U	2 	2 	2#: #: #:J57 57 57n? ? ?3 3 3' ' '`* `* `*DGF GF GFR; ; ;K@ K@ K@ZU6 U6 U6nM M M
1 1 12 2 2H H H*> > >
H H H
B B B,@ @ @GO GO GORM M MBKP KP KPZ> > >M M MB B B0" " "*K K K= = =1 1 1> > >     4: : : 0 0 01 1 1
> > >K K K (H (H (HT- - -$- - -P P PP P P P Pr   r!  __main__)r  unittestr9   r.   rB   rJ   r   r   test.supportr   r   TestCaser   r2   rT   ry   r   r   r>  r  r  r  r  r  r  r  r!  r*   mainr0   r   r   <module>r     sv   % $  				            * * * * * * * *3? 3? 3? 3? 3?8$ 3? 3? 3?l' ' ' ' ' ' ' '2. . . . . . . .b/" /" /" /" /" /" /" /"bm/ m/ m/ m/ m/'9 m/ m/ m/`r6 r6 r6 r6 r6'9 r6 r6 r6jV& V& V& V& V&, V& V& V&r& & & & &<)< & & &36 36 36 36 36': 36 36 36lf1 f1 f1 f1 f1, f1 f1 f1R& & & & &<)< & & &,0 ,0 ,0 ,0 ,0': ,0 ,0 ,0^A A A A AL A A A&rA rA rA rA rAh' rA rA rAjnP nP nP nP nPX& nP nP nPb1 zHMOOOOO r   