
    1                         d Z ddlZddlZddlZddlmZ ej                  Z	 ej                  Zd Z
d Zd Zd	 Zy# e	$ r dZY w xY w)
z*Generic Internet address helper functions.    N   )	maybe_ordi'  c                     | t         k(  rt        j                  j                  |      S | t        k(  rt        j
                  j                  |      S t        )a   Convert the textual form of a network address into its binary form.

    *family* is an ``int``, the address family.

    *text* is a ``text``, the textual address.

    Raises ``NotImplementedError`` if the address family specified is not
    implemented.

    Returns a ``binary``.
    )AF_INETdnsipv4	inet_atonAF_INET6ipv6NotImplementedError)familytexts     lib/third_party/dns/inet.py	inet_ptonr   )   sD     xx!!$''	8	xx!!$''!!    c                     | t         k(  rt        j                  j                  |      S | t        k(  rt        j
                  j                  |      S t        )a2  Convert the binary form of a network address into its textual form.

    *family* is an ``int``, the address family.

    *address* is a ``binary``, the network address in binary form.

    Raises ``NotImplementedError`` if the address family specified is not
    implemented.

    Returns a ``text``.
    )r   r   r   	inet_ntoar
   r   r   )r   addresss     r   	inet_ntopr   >   sD     xx!!'**	8	xx!!'**!!r   c                     	 t         j                  j                  |        t        S # t        $ r4 	 t         j
                  j                  |        t        cY S #  t        xY ww xY w)zDetermine the address family of a textual-form network address.

    *text*, a ``text``, the textual address.

    Raises ``ValueError`` if the address family cannot be determined
    from the input.

    Returns an ``int``.
    )r   r   r	   r   	Exceptionr   r
   
ValueError)r   s    r   af_for_addressr   S   sV    4  	HHt$O	s    $' 	A$$AA$A  A$c                    	 t        t        j                  j                  |       d         }|dk\  xr |dk  S # t        $ rG 	 t        t        j
                  j                  |       d         }|dk(  cY S # t        $ r t        w xY ww xY w)zIs the textual-form network address a multicast address?

    *text*, a ``text``, the textual address.

    Raises ``ValueError`` if the address family cannot be determined
    from the input.

    Returns a ``bool``.
    r            )r   r   r   r	   r   r   r   )r   firsts     r   is_multicastr   i   s    #((,,T2156|,, 	chh006q9:EC< 			s!   69 	B	/A52B	5BB	)__doc__socketdns.ipv4r   dns.ipv6_compatr   r   r
   AttributeErrorr   r   r   r    r   r   <module>r'      sZ   $ 1     ..H
"*"*,I  Hs   ; AA