관리-도구
편집 파일: ipv6.cpython-38.pyc
U /?�f� � @ s� d Z ddlZddlZddlmZmZ ddlZddlZe� d�Z eed�dd�Z e� d�Ze� d �Ze� d �Zdeeef eed�d d�ZdZeed�dd�Zeeef ed�dd�ZdS )zIPv6 helper functions.� N)�List�Unionz 0+([0-9a-f]+))�address�returnc C s� t | �dkrtd��t�| �}g }d}t |�}||k rz|||d � �� }t�|�}|dk rf|�d�}|�|� |d7 }q.d}d}d} d} t d �D ]B}|| d kr�| r�|}|| }||kr�| }|}d} q�| s�|} d} q�| r�d }|| }||kr�| }|}|dk�r�|dk�rZ|dk�s,|d k�rZ|d dk�rZ|dk�r<d} nd} | t j�| dd� � }n,d� |d|� �d d� ||| d� � }n d� |�}|S )z�Convert an IPv6 address in binary form to text form. *address*, a ``bytes``, the IPv6 address in binary form. Raises ``ValueError`` if the address isn't 16 bytes long. Returns a ``str``. � z IPv6 addresses are 16 bytes longr � N� ���F� �0T� � Zffffz::z::ffff:� �:)�len� ValueError�binascii�hexlify�decode� _leading_zero�match�group�append�range�dns�ipv4� inet_ntoa�join)r �hex�chunks�i�l�chunk�mZ best_startZbest_len�startZ last_was_zero�endZcurrent_len�prefixZthex� r'