3
[_ð]Û  ã               @   s\   d Z ddlZddlZddlZddlZddlmZ ejj	dƒZ
ejj	dƒZdd„ Zdd	„ ZdS )
zDNS Reverse Map Names.é    N)ÚPY3zin-addr.arpa.z	ip6.arpa.c             C   sÆ   ytt jj| ƒ}t jj|ƒrRtr6dd„ |dd… D ƒ}ndd„ |dd… D ƒ}t}n dd„ ttj|ƒj	ƒ ƒD ƒ}t
}W n2 tk
r¦   dd„ tt jj| ƒƒD ƒ}t}Y nX |jƒ  t jjdj|ƒ|d	�S )
aT  Convert an IPv4 or IPv6 address in textual form into a Name object whose
    value is the reverse-map domain name of the address.

    *text*, a ``text``, is an IPv4 or IPv6 address in textual form
    (e.g. '127.0.0.1', '::1')

    Raises ``dns.exception.SyntaxError`` if the address is badly formed.

    Returns a ``dns.name.Name``.
    c             S   s   g | ]}d | ‘qS )z%d© )Ú.0Úbyter   r   ú4/tmp/pip-build-yz_zf6az/dnspython/dns/reversename.pyú
<listcomp>0   s    z from_address.<locals>.<listcomp>é   Nc             S   s   g | ]}d t |ƒ ‘qS )z%d)Úord)r   r   r   r   r   r   2   s    c             S   s   g | ]}|‘qS r   r   )r   Úxr   r   r   r   5   s    c             S   s   g | ]}d | ‘qS )z%dr   )r   r   r   r   r   r   8   s   Ú.)Úorigin)ÚdnsÚipv6Ú	inet_atonZ	is_mappedr   Úipv4_reverse_domainÚstrÚbinasciiÚhexlifyÚdecodeÚipv6_reverse_domainÚ	ExceptionÚ	bytearrayÚipv4ÚreverseÚnameÚ	from_textÚjoin)ÚtextZv6Úpartsr   r   r   r   Úfrom_address    s    
r   c             C   sÚ   | j tƒrD| jtƒ} t| jƒ}|jƒ  dj|ƒ}tjj	tjj
|ƒƒS | j tƒrÊ| jtƒ} t| jƒ}|jƒ  g }d}t|ƒ}x0||k rª|jdj|||d … ƒƒ |d7 }q|W dj|ƒ}tjj	tjj
|ƒƒS tjjdƒ‚dS )a  Convert a reverse map domain name into textual address form.

    *name*, a ``dns.name.Name``, an IPv4 or IPv6 address in reverse-map name
    form.

    Raises ``dns.exception.SyntaxError`` if the name does not have a
    reverse-map form.

    Returns a ``text``.
    ó   .r   ó    é   ó   :z"unknown reverse-map address familyN)Zis_subdomainr   Z
relativizeÚlistÚlabelsr   r   r   r   Ú	inet_ntoar   r   ÚlenÚappendr   Ú	exceptionÚSyntaxError)r   r%   r   r   ÚiÚlr   r   r   Ú
to_address?   s&    








r-   )Ú__doc__r   Zdns.namer   Zdns.ipv6Zdns.ipv4Zdns._compatr   r   r   r   r   r   r-   r   r   r   r   Ú<module>   s   