???<!-- GIF89;a -->
123123123123
.....................................................................................................................................???<!-- GIF89;a -->
123123123123
.....................................................................................................................................3
]
                 @   s   d Z ddlZddlZddlmZmZ ejdkZ	d Z
Zd ZZd ZZG dd	 d	eZG d
d deZG dd deZydZej  dd ZW n ek
r   dd ZY nX G dd deZG dd deZG dd deZG dd deZdS )z6Common code shared between various netaddr sub modules    N)	_callable_iter_dict_keysZbig         c               @   s   e Zd ZdZdS )AddrFormatErrorzO
    An Exception indicating a network address is not correctly formatted.
    N)__name__
__module____qualname____doc__ r   r   /usr/lib/python3.6/core.pyr      s   r   c               @   s   e Zd ZdZdS )AddrConversionErrorz^
    An Exception indicating a failure to convert between address types or
    notations.
    N)r   r	   r
   r   r   r   r   r   r   #   s   r   c               @   s   e Zd ZdZdS )NotRegisteredErrorz\
    An Exception indicating that an OUI or IAB was not found in the IEEE
    Registry.
    N)r   r	   r
   r   r   r   r   r   r   +   s   r   *   c             C   s   | j  S )z
        :param int_val: an unsigned integer.

        :return: the minimum number of bits needed to represent value provided.
        )
bit_length)int_valr   r   r   num_bits7   s    r   c             C   s"   d}x| r|d7 }| dL } qW |S )z
        :param int_val: an unsigned integer.

        :return: the minimum number of bits needed to represent value provided.
        r   r   r   )r   Znumbitsr   r   r   r   @   s
    c               @   s   e Zd ZdZdd ZdS )
SubscriberzK
    An abstract class defining the interface expected by a Publisher.
    c             C   s   t ddS )z
        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!N)NotImplementedError)selfdatar   r   r   updateR   s    zSubscriber.updateN)r   r	   r
   r   r   r   r   r   r   r   M   s   r   c               @   s(   e Zd ZdZejdfddZdd ZdS )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             C   s   || _ || _dS )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   r   r   r   __init__e   s    zPrettyPrinter.__init__c             C   s(   | j jtj| | jr$| j jd dS )z
        A callback method used by a Publisher to notify this Subscriber about
        updates.

        :param data: a Python object containing data provided by Publisher.
        
N)r   write_pprintpformatr   )r   r   r   r   r   r   s   s    zPrettyPrinter.updateN)r   r	   r
   r   _sysstdoutr   r   r   r   r   r   r   \   s   r   c               @   s0   e Zd ZdZdd Zdd Zdd Zdd	 Zd
S )	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             C   s
   g | _ dS )ZConstructorN)subscribers)r   r   r   r   r      s    zPublisher.__init__c             C   s>   t |dr.ttdr.|| jkr:| jj| ntd| dS )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   
subscriberr   r   r   attach   s    
zPublisher.attachc             C   s*   y| j j| W n tk
r$   Y nX dS )z
        Remove an existing subscriber.

        :param subscriber: a new object that implements the Subscriber object
            interface.
        N)r$   remove
ValueError)r   r)   r   r   r   detach   s    zPublisher.detachc             C   s   x| j D ]}|j| qW dS )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   r)   r   r   r   notify   s    zPublisher.notifyN)r   r	   r
   r   r   r*   r-   r.   r   r   r   r   r#      s
   r#   c               @   s0   e Zd ZdZdd Zdd Zdd Zdd	 Zd
S )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             C   s   x|D ]}t || tr,t|| | j|< qt || ttfrg }x4|| D ](}t |trj|jt| qL|j| qLW || j|< q|| | j|< qW d S )N)
isinstancedictr/   __dict__listtupler'   )r   dklvr   r   r   r      s    

zDictDotLookup.__init__c             C   s   || j kr| j | S d S )N)r2   )r   namer   r   r   __getitem__   s    
zDictDotLookup.__getitem__c             C   s
   t | jS )N)r   r2   )r   r   r   r   __iter__   s    zDictDotLookup.__iter__c             C   s   t j| jS )N)r   r    r2   )r   r   r   r   __repr__   s    zDictDotLookup.__repr__N)r   r	   r
   r   r   r:   r;   r<   r   r   r   r   r/      s
   r/   )r   sysr!   pprintr   Znetaddr.compatr   r   	byteorderZBIG_ENDIAN_PLATFORMPZ	INET_PTONZZZEROFILLNZNOHOST	Exceptionr   r   r   ar   r   AttributeErrorobjectr   r   r#   r/   r   r   r   r   <module>   s(   
#.