
    $g                        d Z ddlZdZ	 ddlZej        s ed          ej         ej	         ddlmZ
mZm	Z	 dZn# e$ r ddlmZ
mZm	Z	 Y nw xY wddlmZ ddlmZmZmZmZmZmZmZmZ m!Z" d	Z#d
Z$dZ%e	Z&dZ'dZ(d
Z)de#z  dz
  Z*e#e$z  Z+de$z  dz
  Z, e-d  e.de#dz             D                       Z/ e-d  e.de#dz             D                       Z0 e-d  e.de#dz             D                       Z1 e-d  e.de#dz             D                       Z2 G d de3          Z4 G d de4          Z5 G d de4          Z6d)dZ7d)dZ8d*dZ9d Z:d Z;d Z<d  Zd+d!Zd" Zd# Zd$ Zd*d%Zd& Zd' Zd( Z!dS ),z
IPv6 address logic.
    NFzIPv6 disabled)	inet_pton	inet_ntopAF_INET6T)AddrFormatError)	valid_wordsint_to_wordswords_to_int
valid_bitsbits_to_intint_to_bits	valid_bin
int_to_bin
bin_to_int      :IPv6         c                 B    g | ]}|t           d t          |z
  z  dz
  z  fS r   r   max_intwidth.0is     U/var/www/html/netbox-4.1.3/venv/lib/python3.11/site-packages/netaddr/strategy/ipv6.py
<listcomp>r    H   s0    ]]]A1guqy)9A)=>?]]]    c                 B    g | ]}t           d t          |z
  z  dz
  z  |fS r   r   r   s     r   r    r    K   s0    ]]]A7aEAI&6&:;Q?]]]r!   c                 2    g | ]}|d t           |z
  z  dz
  fS r   r   r   s     r   r    r    N   s+    TTT1Aeai 01 46TTTr!   c                 2    g | ]}d t           |z
  z  dz
  |fS r   r$   r   s     r   r    r    Q   s+    TTT1Q519-1A6TTTr!   c                       e Zd ZdZdZdZdS )ipv6_compactz%An IPv6 dialect class - compact form.z%xTN__name__
__module____qualname____doc__word_fmtcompact r!   r   r'   r'   X   s"        // H GGGr!   r'   c                       e Zd ZdZdZdS )	ipv6_fullz*An IPv6 dialect class - 'all zeroes' form.FN)r)   r*   r+   r,   r.   r/   r!   r   r1   r1   b   s        44 GGGr!   r1   c                       e Zd ZdZdZdZdS )ipv6_verbosez5An IPv6 dialect class - extra wide 'all zeroes' form.z%.4xFNr(   r/   r!   r   r3   r3   i   s"        ?? H GGGr!   r3   c                     t          | t                    st          dt          |           z            	 t	          t
          |            n# t          $ r Y dS w xY wdS )a  
    :param addr: An IPv6 address in presentation (string) format.

    :param flags: decides which rules are applied to the interpretation of the
        addr value. Future use - currently has no effect.

    :return: ``True`` if IPv6 address is valid, ``False`` otherwise.

    .. versionchanged:: 1.0.0
        Returns ``False`` instead of raising :exc:`AddrFormatError` for empty strings.
    zInvalid type: %sFT)
isinstancestr	TypeErrortype
_inet_ptonr   OSError)addrflagss     r   	valid_strr=   s   so     dC   9*T$ZZ78888T""""   uu4s   A 
AAc                     	 t          t          |           }n # t          $ r t          | d          w xY wt	          |          S )a  
    :param addr: An IPv6 address in string form.

    :param flags: decides which rules are applied to the interpretation of the
        addr value. Future use - currently has no effect.

    :return: The equivalent unsigned integer for a given IPv6 address.
    z$ is not a valid IPv6 address string!)r9   r   r:   r   packed_to_int)r;   r<   
packed_ints      r   
str_to_intrA      s[    R$//

 R R R$$$PQQQR$$$s    5c                 N   t           d}	 t          |           }j        rt          t          |          }nJt          t          j        d|                    }fd|D             }t          	                    |          }n # t          $ r t          | d          w xY w|S )z
    :param int_val: An unsigned integer.

    :param dialect: (optional) a Python class defining formatting options.

    :return: The IPv6 presentation (string) format address equivalent to the
        unsigned integer provided.
    Nz>8Hc                 $    g | ]}j         |z  S r/   )r-   )r   worddialects     r   r    zint_to_str.<locals>.<listcomp>   s!    @@@$g&-@@@r!   z) is not a valid 128-bit unsigned integer!)r'   int_to_packedr.   
_inet_ntopr   list_structunpackword_sepjoin	Exception
ValueError)int_valrE   r;   r@   wordstokenss    `    r   
int_to_strrR      s     DU"7++
? 	)h
33DD z::;;E@@@@%@@@F==((D U U U'''STTTU Ks   A6B B"c                     t          | t                    }t          |                    dd                    }|                                 |g dz   }d                    |          S )z
    :param int_val: An unsigned integer.

    :return: The reverse DNS lookup for an IPv6 address in network byte
        order integer form.
    r    )ip6arparT   .)rR   r3   rH   replacereverserL   )rO   r;   rQ   s      r   int_to_arparZ      sa     g|,,D$,,sB''((F
NN))))F88Fr!   c                 H    t          | dd          }t          j        dg|R  S )z
    :param int_val: the integer to be packed.

    :return: a packed string that is equivalent to value represented by an
    unsigned integer.
           >4I)r   rI   pack)rO   rP   s     r   rF   rF      s-     !R((E<&&&&&r!   c                     t          t          j        d|                     }d}t          t	          |                    D ]\  }}|}|d|z  z  }||z  }|S )a  
    :param packed_int: a packed string containing an unsigned integer.
        It is assumed that string is packed in network byte order.

    :return: An unsigned integer equivalent to value of network address
        represented by packed binary string.
    r^   r   r]   )rH   rI   rJ   	enumeratereversed)r@   rP   rO   r   numrD   s         r   r?   r?      se     z2233EGHUOO,, ! !3rAv~D.Nr!   c                 8    t          | t          t                    S N)_valid_words	word_size	num_wordsrP   s    r   r   r      s    y)444r!   c                 |    |t                      d         }|t                      d         }t          | ||          S )Nrh   rg   )globals_int_to_words)rO   rh   rg   s      r   r   r      s<    IIk*	IIk*	)Y777r!   c                 8    t          | t          t                    S re   )_words_to_intrg   rh   ri   s    r   r	   r	      s    	9555r!   c                 8    t          | t          t                    S re   )_valid_bitsr   rK   bitss    r   r
   r
      s    tUH---r!   c                 8    t          | t          t                    S re   )_bits_to_intr   rK   rq   s    r   r   r      s    eX...r!   c                 f    |t                      d         }t          | t          t          |          S )NrK   )rk   _int_to_bitsrg   rh   )rO   rK   s     r   r   r      s*    99Z(Ix@@@r!   c                 ,    t          | t                    S re   )
_valid_binr   bin_vals    r   r   r     s    gu%%%r!   c                 ,    t          | t                    S re   )_int_to_binr   )rO   s    r   r   r         w&&&r!   c                 ,    t          | t                    S re   )_bin_to_intr   ry   s    r   r   r   	  r}   r!   )r   re   )NN)=r,   structrI   OPT_IMPORTSsocket_sockethas_ipv6rM   r   r   r9   r   rG   netaddr.fbsocketnetaddr.corer   netaddr.strategyr   rf   r   rl   r	   rn   r
   rp   r   rt   r   rv   r   rx   r   r|   r   r   r   rg   rK   familyfamily_nameversion	word_baser   rh   max_worddictrangeprefix_to_netmasknetmask_to_prefixprefix_to_hostmaskhostmask_to_prefixobjectr'   r1   r3   r=   rA   rR   rZ   rF   r?   r/   r!   r   <module>r      s       \  )i(((RRRRRRRRRRKK \ \ \[[[[[[[[[[[[\ ) ( ( ( ( (
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 	 	  
   	 U(Q, Y	 i<! D]]qRWZ[R[I\I\]]]^^  D]]qRWZ[R[I\I\]]]^^  TTTaQR@S@STTTUU  TTTaQR@S@STTTUU     6              <      *% % % %    <  ' ' '  &5 5 58 8 8 86 6 6. . ./ / /A A A A& & &' ' '' ' ' ' 's   0; AA