
    ^
                     @   d Z ddlZddlZddlmZmZ ej                  dk(  Z	dxZ
ZdxZZdxZZ G d d	e      Z G d
 de      Z G d de      Z	 dZej+                          d Z G d de      Z G d de      Z G d de      Z G d de      Zy# e$ r d ZY 7w xY w)z6Common code shared between various netaddr sub modules    N)	_callable_iter_dict_keysbig         c                       e Zd ZdZy)AddrFormatErrorzO
    An Exception indicating a network address is not correctly formatted.
    N__name__
__module____qualname____doc__     ./usr/lib/python3/dist-packages/netaddr/core.pyr
   r
      s     	r   r
   c                       e Zd ZdZy)AddrConversionErrorz^
    An Exception indicating a failure to convert between address types or
    notations.
    Nr   r   r   r   r   r   #        	r   r   c                       e Zd ZdZy)NotRegisteredErrorz\
    An Exception indicating that an OUI or IAB was not found in the IEEE
    Registry.
    Nr   r   r   r   r   r   +   r   r   r   *   c                 "    | j                         S )
        :param int_val: an unsigned integer.

        :return: the minimum number of bits needed to represent value provided.
        )
bit_length)int_vals    r   num_bitsr   7   s     !!##r   c                 (    d}| r|dz  }| dz  } | r|S )r   r   r   r   )r   numbitss     r   r   r   @   s*     qLGMG  r   c                       e Zd ZdZd Zy)
SubscriberzK
    An abstract class defining the interface expected by a Publisher.
    c                     t        d      )
        A callback method used by a Publisher to notify this Subscriber about
        updates.

        :param data: a Python object containing data provided by Publisher.
        zcannot invoke virtual method!)NotImplementedErrorselfdatas     r   updatezSubscriber.updateR   s     ""ABBr   N)r   r   r   r   r(   r   r   r   r!   r!   M   s    Cr   r!   c                   6    e Zd ZdZej
                  dfdZd Zy)PrettyPrinterz
    A concrete Subscriber that employs the pprint in the standard library to
    format all data from updates received, writing them to a file-like
    object.

    Useful as a debugging aid.
    Tc                      || _         || _        y)z
        Constructor.

        :param fh: a file-like object to write updates to.
            Default: sys.stdout.


        :param write_eol: if ``True`` this object will write newlines to
            output, if ``False`` it will not.
        N)fh	write_eol)r&   r,   r-   s      r   __init__zPrettyPrinter.__init__e   s     "r   c                     | j                   j                  t        j                  |             | j                  r| j                   j                  d       yy)r#   
N)r,   write_pprintpformatr-   r%   s     r   r(   zPrettyPrinter.updates   s9     	good+,>>GGMM$ r   N)r   r   r   r   _sysstdoutr.   r(   r   r   r   r*   r*   \   s     ++ #	 r   r*   c                   (    e Zd ZdZd Zd Zd Zd Zy)	Publisherz
    A 'push' Publisher that maintains a list of Subscriber objects notifying
    them of state changes by passing them update data when it encounter events
    of interest.
    c                     g | _         y)ConstructorN)subscribersr&   s    r   r.   zPublisher.__init__   s
    r   c                     t        |d      r?t        t        d            r+|| j                  vr| j                  j	                  |       yyt        d|z        )z
        Add a new subscriber.

        :param subscriber: a new object that implements the Subscriber object
            interface.
        r(   zsubscriber.updatez'%r does not support required interface!N)hasattrr   evalr:   append	TypeErrorr&   
subscribers     r   attachzPublisher.attach   sU     :x(Yt<O7P-Q!1!11  ''
3 2 E
RSSr   c                 Z    	 | j                   j                  |       y# t        $ r Y yw xY w)z
        Remove an existing subscriber.

        :param subscriber: a new object that implements the Subscriber object
            interface.
        N)r:   remove
ValueErrorrA   s     r   detachzPublisher.detach   s-    	##J/ 		s    	**c                 H    | j                   D ]  }|j                  |        y)z
        Send update data to to all registered Subscribers.

        :param data: the data to be passed to each registered Subscriber.
        N)r:   r(   )r&   r'   rB   s      r   notifyzPublisher.notify   s'     ** 	$Jd#	$r   N)r   r   r   r   r.   rC   rG   rI   r   r   r   r7   r7      s    T
$r   r7   c                   (    e Zd ZdZd Zd Zd Zd Zy)DictDotLookupa  
    Creates objects that behave much like a dictionaries, but allow nested
    key access using object '.' (dot) lookups.

    Recipe 576586: Dot-style nested lookups over dictionary based data
    structures - http://code.activestate.com/recipes/576586/

    c                 v   |D ]  }t        ||   t              rt        ||         | j                  |<   2t        ||   t        t
        f      rXg }||   D ]>  }t        |t              r|j                  t        |             .|j                  |       @ || j                  |<   ||   | j                  |<    y N)
isinstancedictrK   __dict__listtupler?   )r&   dklvs        r   r.   zDictDotLookup.__init__   s     	(A!A$%#01#6a AaD4-01 $A!!T*q!12	$
 $%a #$Q4a 	(r   c                 >    || j                   v r| j                   |   S y rM   )rP   )r&   names     r   __getitem__zDictDotLookup.__getitem__   s"    4== ==&& !r   c                 ,    t        | j                        S rM   )r   rP   r;   s    r   __iter__zDictDotLookup.__iter__   s    t}}--r   c                 @    t        j                  | j                        S rM   )r2   r3   rP   r;   s    r   __repr__zDictDotLookup.__repr__   s    t}}--r   N)r   r   r   r   r.   rY   r[   r]   r   r   r   rK   rK      s    ('..r   rK   )r   sysr4   pprintr2   netaddr.compatr   r   	byteorderBIG_ENDIAN_PLATFORMP	INET_PTONZZEROFILLNNOHOST	Exceptionr
   r   r   ar   r   AttributeErrorobjectr!   r*   r7   rK   r   r   r   <module>rm      s    =   5 nn-   I  H F
	i 		) 		 	
ALLN$,C C  J   F+$ +$\!.F !._  
s   B BB