a �DOg*3�@s�dZddlZdZdZGdd�de�ZGdd�de�Zd d �Zd7}|d|j kr�q�q�dS)Nz1first and last must be IP addresses, not networks�%%s and %s are not of the same versionz*last IP address must be greater than firstr�zunknown IP versionr)) � isinstance� _BaseAddress� TypeError�versionrrr�_max_prefixlenr,r3r7r4� _ALL_ONES)r/r0r1�ip_bits� first_int�last_int�nbits�netr r r �summarize_address_range�s6 � �   � rEccs�t|�}i}|rV|��}|��}|�|�}|dur<|||<q ||kr ||=|�|�q d}t|���D]$}|dur�|j|jkr�qf|V|}qfdS�N)�list�pop�supernet�get�append�sorted�values�broadcast_address)r-�to_merge�subnetsrDrI�existingr0r r r �_collapse_addresses_internal�s$    rRc Cs.g}g}g}|D]�}t|t�rR|rF|dj|jkrFtd||df��|�|�q|j|jkr�|r�|dj|jkr�td||df��z|�|j�Wq�ty�|�|j �Yq�0q|r�|dj|jkr�td||df��|�|�qt t |��}|�r"t |�D]\}}|� t||���qt||�S)N�����r8)r:r;�_versionr<rK� _prefixlenr>r1�AttributeError�network_addressrL�setr2�extendrErR)r-�addrs�ips�netsr1r/r0r r r �collapse_addresses/s: �  � �  r]cCs(t|t�r|��St|t�r$|��StSrF)r:� _BaseNetwork�_get_networks_keyr;�_get_address_key�NotImplemented)�objr r r �get_mixed_type_keyes   rcc@s�eZdZdZedd��Zedd��Zedd��Zedd ��Zd d �Z d d �Z e dd��Z e dd��Z e dd��Ze dd��Ze dd��Ze dd��Zdd�ZdS)�_IPAddressBaser cCs|��SrF)�_explode_shorthand_ip_string��selfr r r �exploded�sz_IPAddressBase.explodedcCst|�SrF�r#rfr r r � compressed�sz_IPAddressBase.compressedcCs|��SrF)�_reverse_pointerrfr r r �reverse_pointer�s z_IPAddressBase.reverse_pointercCsdt|�f}t|��dS)Nz%200s has no version specified��type�NotImplementedError�rg�msgr r r r=�sz_IPAddressBase.versioncCsF|dkrd}t|||jf��||jkrBd}t|||j|jf��dS)Nrz-%d (< 0) is not permitted as an IPv%d addressz2%d (>= 2**%d) is not permitted as an IPv%d address)rrTr?r>)rgrrqr r r �_check_int_address�s  �z!_IPAddressBase._check_int_addresscCs.t|�}||kr*d}t|||||jf��dS)Nz6%r (len %d != %d) is not permitted as an IPv%d address)r%rrT)rgr� expected_len� address_lenrqr r r �_check_packed_address�s �z$_IPAddressBase._check_packed_addresscCs|j|j|?ASrF)r?)�cls� prefixlenr r r �_ip_int_from_prefix�s z"_IPAddressBase._ip_int_from_prefixc Cs\t||j�}|j|}||?}d|>d}||krX|jd}|�|d�}d}t||��|S)Nr)�rz&Netmask pattern %r mixes zeroes & ones)r7r>rr) rv�ip_int�trailing_zeroesrw� leading_ones�all_ones�byteslen�detailsrqr r r �_prefix_from_ip_int�s �     z"_IPAddressBase._prefix_from_ip_intcCsd|}t|�d�dS)Nz%r is not a valid netmask)r )rv� netmask_strrqr r r �_report_invalid_netmask�sz&_IPAddressBase._report_invalid_netmaskcCsj|��r|��s|�|�z t|�}WntyB|�|�Yn0d|krZ|jksfn|�|�|S�Nr)�isascii�isdigitr��intrr>)rv� prefixlen_strrwr r r �_prefix_from_prefix_string�s    z)_IPAddressBase._prefix_from_prefix_stringcCs�z|�|�}Wnty*|�|�Yn0z |�|�WStyJYn0||jN}z |�|�WSty~|�|�Yn0dSrF)�_ip_int_from_stringrr�r�rr?)rv�ip_strrzr r r �_prefix_from_ip_string�s      z%_IPAddressBase._prefix_from_ip_stringcCsHt|ttf�r||jfSt|t�s*t|�}t|�dkr:|S|d|jfS)Nr)r)r:�bytesr�r>�tupler'r%)rvrr r r �_split_addr_prefixs    z!_IPAddressBase._split_addr_prefixcCs|jt|�ffSrF)� __class__r#rfr r r � __reduce__,sz_IPAddressBase.__reduce__N)rrr� __slots__�propertyrhrjrlr=rrru� classmethodrxr�r�r�r�r�r�r r r r rd~s0          ! rdcspeZdZdZdd�Zdd�Zdd�Zdd �Zd d �Zd d �Z dd�Z dd�Z dd�Z dd�Z �fdd�Z�ZS)r;r cCs|jSrF)r,rfr r r �__int__=sz_BaseAddress.__int__cCs6z|j|jko|j|jkWSty0tYS0dSrF)r,rTrVra�rg�otherr r r �__eq__@s   � z_BaseAddress.__eq__cCsFt|t�stS|j|jkr*td||f��|j|jkrB|j|jkSdS�Nr8F)r:r;rarTr<r,r�r r r �__lt__Gs  �  z_BaseAddress.__lt__cCs t|t�stS|�t|�|�SrF�r:r�rar�r�r r r �__add__Ss z_BaseAddress.__add__cCs t|t�stS|�t|�|�SrFr�r�r r r �__sub__Xs z_BaseAddress.__sub__cCsd|jjt|�fS�Nz%s(%r)�r�rr#rfr r r �__repr__]sz_BaseAddress.__repr__cCst|�|j��SrF)r#�_string_from_ip_intr,rfr r r �__str__`sz_BaseAddress.__str__cCsttt|j���SrF)�hash�hexr�r,rfr r r �__hash__csz_BaseAddress.__hash__cCs |j|fSrF�rTrfr r r r`fsz_BaseAddress._get_address_keycCs|j|jffSrF)r�r,rfr r r r�isz_BaseAddress.__reduce__cs�|r|ddkrtt|�|�Stdur8ddl}|�d�at�|�}|sRt��|�S|��\}}}|dkr||j dkrxd}nd}|dkr�|j }n |j d}|r�||dd 7}|r�|d 7}tt |�|�d |�|�|���S) NrS�srz(#?)(_?)([xbnX])�nr�b�xr)r"�0) �formatr#�_address_fmt_re�re�compile� fullmatch�super� __format__�groupsrTr>r�)rg�fmtr��m� alternate�grouping�fmt_base�padlen�r�r r r�ls*     z_BaseAddress.__format__)rrrr�r�r�r�r�r�r�r�r�r`r�r�� __classcell__r r r�r r;2s  r;c@s\eZdZdd�Zdd�Zdd�Zdd�Zd d �Zd d �Zd d�Z dd�Z dd�Z dd�Z e jdd��Ze jdd��Zedd��Zedd��Zedd��Zedd ��Zed!d"��Zed#d$��Zd%d&�Zd'd(�Zd)d*�ZdEd-d.�ZdFd/d0�Zed1d2��Zed3d4��Zd5d6�Z d7d8�Z!ed9d:��Z"ed;d<��Z#ed=d>��Z$ed?d@��Z%edAdB��Z&edCdD��Z'd,S)Gr^cCsd|jjt|�fSr�r�rfr r r r��sz_BaseNetwork.__repr__cCsd|j|jfS�N�%s/%d)rWrwrfr r r r��sz_BaseNetwork.__str__ccs8t|j�}t|j�}t|d|�D]}|�|�Vq"dSr(�r�rWrN�range�_address_class�rg�network� broadcastr�r r r �hosts�s  z_BaseNetwork.hostsccs8t|j�}t|j�}t||d�D]}|�|�Vq"dSr(r�r�r r r �__iter__�s  z_BaseNetwork.__iter__cCslt|j�}t|j�}|dkr>|||kr0td��|�||�S|d7}|||krZtd��|�||�SdS)Nrzaddress out of ranger))r�rWrN� IndexErrorr�)rgr�r�r�r r r � __getitem__�s    z_BaseNetwork.__getitem__cCs^t|t�stS|j|jkr*td||f��|j|jkrB|j|jkS|j|jkrZ|j|jkSdSr�)r:r^rarTr<rW�netmaskr�r r r r��s  �    z_BaseNetwork.__lt__cCsJz.|j|jko,|j|jko,t|j�t|j�kWStyDtYS0dSrF)rTrWr�r�rVrar�r r r r��s  �� z_BaseNetwork.__eq__cCstt|j�t|j�A�SrF)r�r�rWr�rfr r r r��sz_BaseNetwork.__hash__cCs8|j|jkrdSt|t�rdS|j|jj@|jjkSdS�NF)rTr:r^r,r�rWr�r r r � __contains__�s   z_BaseNetwork.__contains__cCs(|j|vp&|j|vp&|j|vp&|j|vSrF)rWrNr�r r r �overlaps�s    �z_BaseNetwork.overlapscCs|�t|j�t|j�B�SrF)r�r�rW�hostmaskrfr r r rN�s �z_BaseNetwork.broadcast_addresscCs|�t|j�|jA�SrF)r�r�r�r?rfr r r r��sz_BaseNetwork.hostmaskcCsd|j|jfSr�)rWrUrfr r r �with_prefixlen�sz_BaseNetwork.with_prefixlencCsd|j|jfS�N�%s/%s)rWr�rfr r r � with_netmasksz_BaseNetwork.with_netmaskcCsd|j|jfSr�)rWr�rfr r r � with_hostmasksz_BaseNetwork.with_hostmaskcCst|j�t|j�dSr()r�rNrWrfr r r � num_addresses sz_BaseNetwork.num_addressescCsdt|�f}t|��dS)Nz%%200s has no associated address classrmrpr r r r�sz_BaseNetwork._address_classcCs|jSrF)rUrfr r r rwsz_BaseNetwork.prefixlenccs|j|jkstd||f��t|t�s2td|��|�|�sLtd||f��||krXdS|�d|j|jf�}|� �\}}||kr�||kr�|�|�r�|V|� �\}}qz|�|�r�|V|� �\}}qzt d|||f��qz||kr�|Vn"||kr�|Vnt d|||f��dS)Nr8z%s is not a network objectz%s not contained in %sr�z3Error performing exclusion: s1: %s s2: %s other: %s) rTr<r:r^� subnet_ofrr�rWrwrP�AssertionError)rgr��s1�s2r r r �address_excludes>$ �    �   ��z_BaseNetwork.address_excludecCs`|j|jkrtd||f��|j|jkr,dS|j|jkr 0z0prefix length diff %d is invalid for netblock %s) rUr>rr�rWrNr�r�r�) rg�prefixlen_diff� new_prefix� new_prefixlen�start�end�step�new_addr�currentr r r rP�s0     �� z_BaseNetwork.subnetscCs�|jdkr|S|durB||jkr(td��|dkr8td��|j|}|j|}|dkrftd|j|f��|�t|j�t|j�|>@|f�S)Nrznew prefix must be shorterr)r�z;current prefixlen is %d, cannot have a prefixlen_diff of %d)rUrrwr�r�rWr�)rgr�r�r�r r r rI�s&    ���z_BaseNetwork.supernetcCs|jjo|jjSrF)rW� is_multicastrNrfr r r r��s �z_BaseNetwork.is_multicastcCsfz:|j|jkr"t|�d|�d���|j|jko8|j|jkWSty`td|�d|����Yn0dS)Nz and z are not of the same versionz*Unable to test subnet containment between )rTr<rWrNrV)�ar�r r r � _is_subnet_of s   � ��z_BaseNetwork._is_subnet_ofcCs |�||�SrF�r�r�r r r r�sz_BaseNetwork.subnet_ofcCs |�||�SrFr�r�r r r � supernet_ofsz_BaseNetwork.supernet_ofcCs|jjo|jjSrF)rW� is_reservedrNrfr r r r�s �z_BaseNetwork.is_reservedcCs|jjo|jjSrF)rW� is_link_localrNrfr r r r�*s�z_BaseNetwork.is_link_localcCs|jjo|jjSrF)rW� is_privaterNrfr r r r�5s �z_BaseNetwork.is_privatecCs|j SrF)r�rfr r r � is_globalAs z_BaseNetwork.is_globalcCs|jjo|jjSrF)rW�is_unspecifiedrNrfr r r r�Ls �z_BaseNetwork.is_unspecifiedcCs|jjo|jjSrF)rW� is_loopbackrNrfr r r r�Xs �z_BaseNetwork.is_loopback)r)N)r)N)(rrrr�r�r�r�r�r�r�r�r�r�� functools�cached_propertyrNr�r�r�r�r�r�r�rwr�r�r_rPrIr�� staticmethodr�r�r�r�r�r�r�r�r�r r r r r^�sb            K0 5 )       r^c@s�eZdZdZdZdedZeZiZdd�Z e dd��Z e d d ��Z e d d ��Z e d d��Zdd�Zedd��Zedd��ZdS)�_BaseV4r rr"r)cCst|�SrFrirfr r r rewsz$_BaseV4._explode_shorthand_ip_stringcCs�||jvr�t|t�r<|}d|kr.|jkshn|�|�n,z|�|�}Wntyf|�|�}Yn0t|� |��}||f|j|<|j|Sr�) �_netmask_cacher:r�r>r�r�r r�r rx�rv�argrwr�r r r � _make_netmaskzs    z_BaseV4._make_netmaskc Cs�|s td��|�d�}t|�dkr.td|��zt�t|j|�d�WStyz}ztd||f�d�WYd}~n d}~00dS)N�Address cannot be empty�.rzExpected 4 octets in %rr�%s in %r)rr$r%r�� from_bytes�map� _parse_octetr)rvr��octets�excr r r r��s   z_BaseV4._ip_int_from_stringcCs�|s td��|��r|��s,d}t||��t|�dkrHd}t||��|dkrl|ddkrld}t||��t|d�}|d kr�td |��|S) NzEmpty octet not permittedz#Only decimal digits permitted in %r�z$At most 3 characters permitted in %rr�rz%Leading zeros are not permitted in %r� ��zOctet %d (> 255) not permitted)rr�r�r%r�)rv� octet_strrq� octet_intr r r r��s      z_BaseV4._parse_octetcCsd�tt|�dd���S)Nr�rr)�joinr�r#r)rvrzr r r r��s z_BaseV4._string_from_ip_intcCs&t|��d�ddd�}d�|�dS)Nr�rSz .in-addr.arpa)r#r$r)rg�reverse_octetsr r r rk�sz_BaseV4._reverse_pointercCs|jSrF�r>rfr r r � max_prefixlen�sz_BaseV4.max_prefixlencCs|jSrFr�rfr r r r=�sz_BaseV4.versionN)rrrr�rT� IPV4LENGTHr?r>r�rer�r�r�r�r�rkr�rr=r r r r r�ds&     #   r�c@s�eZdZdZdd�Zedd��Zedd��Zee� �dd ���Z ee� �d d ���Z ed d ��Z edd��Z edd��Zedd��ZdS)r )r,� __weakref__cCstt|t�r|�|�||_dSt|t�rF|�|d�t�|d�|_dSt|�}d|vrdtd|����|� |�|_dS)Nrrr!�Unexpected '/' in ) r:r�rrr,r�rur�r#rr��rgr�addr_strr r r �__init__�s    zIPv4Address.__init__cCs t|j�SrF)rr,rfr r r �packedszIPv4Address.packedcCs ||jjvSrF)� _constants�_reserved_networkrfr r r r�s zIPv4Address.is_reservedcs4t�fdd��jjD��o2t�fdd��jjD��S)Nc3s|]}�|vVqdSrFr ��.0rDrfr r � <�z)IPv4Address.is_private..c3s|]}�|vVqdSrFr rrfr r r=r)�anyr �_private_networks�all�_private_networks_exceptionsrfr rfr r�*s�zIPv4Address.is_privatecCs||jjvo|j SrF)r �_public_networkr�rfr r r r�@szIPv4Address.is_globalcCs ||jjvSrF)r �_multicast_networkrfr r r r�Rs zIPv4Address.is_multicastcCs ||jjkSrF)r �_unspecified_addressrfr r r r�]s zIPv4Address.is_unspecifiedcCs ||jjvSrF)r �_loopback_networkrfr r r r�hszIPv4Address.is_loopbackcCs ||jjvSrF)r �_linklocal_networkrfr r r r�rszIPv4Address.is_link_localN)rrrr�r r�r r�r�� lru_cacher�r�r�r�r�r�r r r r r �s(#       r c@sxeZdZdd�Zejdd��Zdd�Zdd�Zd d �Z d d �Z e j Z e d d��Ze dd��Ze dd��Ze dd��ZdS)rcCsD|�|�\}}t�||�t||fdd�|_|jj|_|jj|_dS�NF)r)r�r r rr�r�rU�rgrr&�maskr r r r s   zIPv4Interface.__init__cCs|jjSrF�r�r�rfr r r r��szIPv4Interface.hostmaskcCsd|�|j�|jfSr��r�r,rUrfr r r r��s �zIPv4Interface.__str__cCsDt�||�}|tus|s|Sz|j|jkWSty>YdS0dSr�)r r�rar�rV�rgr�� address_equalr r r r��s   zIPv4Interface.__eq__cCsPt�||�}|turtSz|j|jkp4|j|jko4|WStyJYdS0dSr�)r r�rar�rV�rgr�� address_lessr r r r��s  � zIPv4Interface.__lt__cCst|j|jt|jj�f�SrF�r�r,rUr�r�rWrfr r r r��szIPv4Interface.__hash__cCs t|j�SrF)r r,rfr r r r1�szIPv4Interface.ipcCsd|�|j�|jfSr�r rfr r r r��s �zIPv4Interface.with_prefixlencCsd|�|j�|jfSr��r�r,r�rfr r r r��s �zIPv4Interface.with_netmaskcCsd|�|j�|jfSr��r�r,r�rfr r r r��s �zIPv4Interface.with_hostmaskN)rrrr r�r�r�r�r�r�r�rdr�r�r1r�r�r�r r r r r}s       rc@s.eZdZeZddd�Zee��dd���Z dS)rTcs�|�|�\�}t��|_|�|�\|_|_t|j�}|t|j�@|krl|rXtd|��nt|t|j�@�|_|j|jdkr�|j |_ n|j|jkr��fdd�|_ dS)N�%s has host bits setr)cs t��gSrF)r r �r&r r �rz&IPv4Network.__init__..) r�r rWr�r�rUr�rr>r�r��rgrrrr r r)r r �s#  �  zIPv4Network.__init__cCs&|jtd�vo|jtd�v o$|j S)N� 100.64.0.0/10)rWrrNr�rfr r r r�s  ��zIPv4Network.is_globalN)T) rrrr r�r r�r�rr�r r r r r�s   4rc@s�eZdZed�Zed�Zed�Zed�Zed�ed�ed�ed�ed�ed�ed �ed �ed �ed �ed �ed�ed�ed�gZed�ed�gZ ed�Z e d�Z dS)�_IPv4Constantsz169.254.0.0/16z 127.0.0.0/8z 224.0.0.0/4r,z 0.0.0.0/8z 10.0.0.0/8z 172.16.0.0/12z 192.0.0.0/24z192.0.0.170/31z 192.0.2.0/24z192.168.0.0/16z 198.18.0.0/15z198.51.100.0/24z203.0.113.0/24z 240.0.0.0/4z255.255.255.255/32z 192.0.0.9/32z 192.0.0.10/32z0.0.0.0N) rrrrrrrrrrr r rr r r r r-s0��r-c@s�eZdZdZdZdedZdZed�Z eZ iZ e dd��Z e d d ��Ze d d ��Ze d d��Ze ddd��Zdd�Zdd�Zedd��Zedd��Zedd��ZdS)�_BaseV6r r9r"r)ry�0123456789ABCDEFabcdefcCsl||jvrbt|t�r<|}d|kr.|jksFn|�|�n |�|�}t|�|��}||f|j|<|j|Sr�)r�r:r�r>r�r�r rxr�r r r r�Os    z_BaseV6._make_netmaskc Cs�|s td��|�d�}d}t|�|kr:d||f}t|��d|dvr�zt|���j}Wn6ty�}ztd||f�d�WYd}~n d}~00|�d|d ?d @�|�d|d @�|jd }t|�|kr�d |d |f}t|��d}td t|�d �D]*} || s�|du�r"d |}t|��| }q�|du�r�|} t|�|d } |d�sn| d 8} | �rnd}t||��|d�s�| d 8} | �r�d}t||��|j| | } | d k�r4d}t||jd |f��njt|�|jk�r�d}t||j|f��|d�s d}t||��|d�s$d}t||��t|�} d} d} znd} t| �D] } | d K} | |� || �O} �qB| d | K} t| d�D] } | d K} | |� || �O} �q|| WSt �y�}ztd||f�d�WYd}~n d}~00dS)Nr��:r�z At least %d parts expected in %rr�rSr��%xr���r)z!At most %d colons permitted in %rz At most one '::' permitted in %rrz0Leading ':' only permitted as part of '::' in %rz1Trailing ':' only permitted as part of '::' in %rz/Expected at most %d other parts with '::' in %rz,Exactly %d parts expected without '::' in %r) rr$r%r rHr,rK� _HEXTET_COUNTr�� _parse_hextetr)rvr��parts� _min_partsrq�ipv4_intr�� _max_parts� skip_index�i�parts_hi�parts_lo� parts_skippedrzr r r r�cs�    (               z_BaseV6._ip_int_from_stringcCs>|j�|�std|��t|�dkr4d}t||��t|d�S)NzOnly hex digits permitted in %rrz$At most 4 characters permitted in %rr)� _HEX_DIGITS� issupersetrr%r�)rv� hextet_strrqr r r r4�s     z_BaseV6._parse_hextetc Cs�d}d}d}d}t|�D]>\}}|dkrN|d7}|dkr<|}||krV|}|}qd}d}q|dkr�||}|t|�kr~|dg7}dg|||�<|dkr�dg|}|S)NrSrr�r)�)� enumerater%) rv�hextets�best_doublecolon_start�best_doublecolon_len�doublecolon_start�doublecolon_len�index�hextet�best_doublecolon_endr r r �_compress_hextets�s0�   z_BaseV6._compress_hextetsNcsZ|durt|j�}||jkr$td��d|��fdd�tddd�D�}|�|�}d�|�S) NzIPv6 address is too large�%032xcs&g|]}dt�||d�d��qS)r1rr)r��rr���hex_strr r � *rz/_BaseV6._string_from_ip_int..rrrr0)r�r,r?rr�rKr)rvrzrCr rNr r�s   z_BaseV6._string_from_ip_intcs�t|t�rt|j�}nt|t�r,t|j�}nt|�}|�|�}d|��fdd�tddd�D�}t|ttf�r�dd� |�|j fSd� |�S) NrLcsg|]}�||d��qS)rr rMrNr r rP?rz8_BaseV6._explode_shorthand_ip_string..rrrr�r0) r:rr#rWrr1r�r�r^rrU)rgr�rzr5r rNr re/s     z$_BaseV6._explode_shorthand_ip_stringcCs&|jddd��dd�}d�|�dS)NrSr0rAr�z .ip6.arpa)rh�replacer)rg� reverse_charsr r r rkDsz_BaseV6._reverse_pointercCs:|�d�\}}}|sd}n|r&d|vr2td|��||fS)N�%zInvalid IPv6 address: "%r")� partitionr)r�r&�sep�scope_idr r r �_split_scope_idMs   z_BaseV6._split_scope_idcCs|jSrFrrfr r r rasz_BaseV6.max_prefixlencCs|jSrFr�rfr r r r=esz_BaseV6.version)N)rrrr�rT� IPV6LENGTHr?r3� frozensetr>r>r�r�r�r�r4rKr�rerkr�rWr�rr=r r r r r.;s2    g  /    r.cs�eZdZdZdd�Z�fdd�Zdd�Z�fdd �Zed d ��Z ed d ��Z edd��Z edd��Z edd��Z edd��Zee��dd���Zedd��Zedd��Zedd��Zedd��Zed d!��Zed"d#��Z�ZS)$r )r,� _scope_idrcCs�t|t�r$|�|�||_d|_dSt|t�rR|�|d�t�|d�|_d|_dSt|�}d|vrpt d|����|� |�\}|_|� |�|_dS)Nrrr!r) r:r�rrr,rZr�rur�r#rrWr�rr r r r ps    zIPv6Address.__init__cs"t���}|jr|d|jS|S)NrS)r�r�rZ)rgr�r�r r r��s zIPv6Address.__str__cCst|j|jf�SrF)r�r,rZrfr r r r��szIPv6Address.__hash__cs2t��|�}|turtS|s dS|jt|dd�kS)NFrZ)r�r�rarZ�getattrr!r�r r r��s  zIPv6Address.__eq__cCs|jSrF)rZrfr r r rV�s zIPv6Address.scope_idcCs t|j�SrF)r r,rfr r r r �szIPv6Address.packedcCs |j}|dur|jS||jjvSrF)� ipv4_mappedr�r r�rgr\r r r r��s zIPv6Address.is_multicastcs.�j}|dur|jSt�fdd��jjD��S)Nc3s|]}�|vVqdSrFr rMrfr r r�rz*IPv6Address.is_reserved..)r\r�rr �_reserved_networksr]r rfr r��s zIPv6Address.is_reservedcCs |j}|dur|jS||jjvSrF)r\r�r rr]r r r r��szIPv6Address.is_link_localcCs ||jjvSrF)r �_sitelocal_networkrfr r r � is_site_local�s zIPv6Address.is_site_localcsH�j}|dur|jSt�fdd��jjD��oFt�fdd��jjD��S)Nc3s|]}�|vVqdSrFr rrfr r rrz)IPv6Address.is_private..c3s|]}�|vVqdSrFr rrfr r rr)r\r�rr rrrr]r rfr r��s �zIPv6Address.is_privatecCs|j}|dur|jS|j SrF)r\r�r�r]r r r r�szIPv6Address.is_globalcCs|j}|dur|jS|jdkSr�)r\r�r,r]r r r r�s zIPv6Address.is_unspecifiedcCs|j}|dur|jS|jdkSr()r\r�r,r]r r r r�*s zIPv6Address.is_loopbackcCs |jd?dkrdSt|jd@�S)Nrr2����r,r rfr r r r\8s zIPv6Address.ipv4_mappedcCs4|jd?dkrdSt|jd?d@�t|jd@�fS)N�`i �@rarbrfr r r �teredoEs �zIPv6Address.teredocCs$|jd?dkrdSt|jd?d@�S)N�pi �Prarbrfr r r � sixtofourTs zIPv6Address.sixtofour)rrrr�r r�r�r�r�rVr r�r�r�r`r�rr�r�r�r�r\rerhr�r r r�r r js@(              r cs�eZdZdd�Zejdd��Z�fdd�Zdd�Zd d �Z d d �Z e j Z e d d��Ze dd��Ze dd��Ze dd��Ze dd��Ze �fdd��Z�ZS)rcCsD|�|�\}}t�||�t||fdd�|_|jj|_|jj|_dSr)r�r r rr�r�rUrr r r r ds   zIPv6Interface.__init__cCs|jjSrFrrfr r r r�lszIPv6Interface.hostmaskcsdt���|jfSr�)r�r�rUrfr�r r r�ps �zIPv6Interface.__str__cCsDt�||�}|tus|s|Sz|j|jkWSty>YdS0dSr�)r r�rar�rVr!r r r r�ts   zIPv6Interface.__eq__cCsPt�||�}|tur|Sz|j|jkp4|j|jko4|WStyJYdS0dSr�)r r�rar�rVr#r r r r��s  � zIPv6Interface.__lt__cCst|j|jt|jj�f�SrFr%rfr r r r��szIPv6Interface.__hash__cCs t|j�SrF)r r,rfr r r r1�szIPv6Interface.ipcCsd|�|j�|jfSr�r rfr r r r��s �zIPv6Interface.with_prefixlencCsd|�|j�|jfSr�r&rfr r r r��s �zIPv6Interface.with_netmaskcCsd|�|j�|jfSr�r'rfr r r r��s �zIPv6Interface.with_hostmaskcCs|jdko|jjSr�)r,r�r�rfr r r r��szIPv6Interface.is_unspecifiedcst�jo|jjSrF)r�r�r�rfr�r r r��szIPv6Interface.is_loopback)rrrr r�r�r�r�r�r�r�rdr�r�r1r�r�r�r�r�r�r r r�r rbs(         rc@s.eZdZeZd dd�Zdd�Zedd��ZdS) rTcs�|�|�\�}t��|_|�|�\|_|_t|j�}|t|j�@|krl|rXtd|��nt|t|j�@�|_|j|jdkr�|j |_ n|j|jkr��fdd�|_ dS)Nr(r)cs t��gSrF)r r r)r r r*�rz&IPv6Network.__init__..) r�r rWr�r�rUr�rr>r�r�r+r r)r r �s  �  zIPv6Network.__init__ccs<t|j�}t|j�}t|d|d�D]}|�|�Vq&dSr(r�r�r r r r��s  zIPv6Network.hostscCs|jjo|jjSrF)rWr`rNrfr r r r`�s �zIPv6Network.is_site_localN)T) rrrr r�r r�r�r`r r r r r�s  0 rc@s�eZdZed�Zed�Zed�ed�ed�ed�ed�ed�ed �ed �ed �ed �ed�g Zed �ed�ed�ed�ed�ed�gZed�ed�ed�ed�ed�ed�ed�ed�ed�ed�ed�ed�ed�ed �ed!�gZed"�Z d#S)$�_IPv6Constantsz fe80::/10zff00::/8z::1/128z::/128z ::ffff:0:0/96z64:ff9b:1::/48z100::/64z 2001::/23z 2001:db8::/32z 2002::/16z 3fff::/20zfc00::/7z 2001:1::1/128z 2001:1::2/128z 2001:3::/32z2001:4:112::/48z 2001:20::/28z 2001:30::/28z::/8z100::/8z200::/7z400::/6z800::/5z1000::/4z4000::/3z6000::/3z8000::/3zA000::/3zC000::/3zE000::/4zF000::/5zF800::/6zFE00::/9z fec0::/10N) rrrrrrrrr^r_r r r r ri s>��       � ri)T)#� __version__r�rrXrrr rrrrr r'r2r7rErRr]rcrdr��total_orderingr;r^r�r rrr-r r.r rrrir r r r � sX "7163kH CR&1yK\/