o inhV@sdZddlZddlZddlmZmZejdkZ dZ Z dZ Z dZZdZGd d d eZGd d d eZGd ddeZz dZe[ddZWn eyWddZYnwGdddeZGdddeZGdddeZGdddeZdS)z6Common code shared between various netaddr sub modulesN) _callable_iter_dict_keysbigc@eZdZdZdS)AddrFormatErrorzO An Exception indicating a network address is not correctly formatted. N__name__ __module__ __qualname____doc__rr7/usr/local/lib/python3.10/dist-packages/netaddr/core.pyr sr c@r )AddrConversionErrorz^ An Exception indicating a failure to convert between address types or notations. Nr rrrrr&rc@r )NotRegisteredErrorz\ An Exception indicating that an OUI or IAB was not found in the IEEE Registry. Nr rrrrr.rr*cCs|S) :param int_val: an unsigned integer. :return: the minimum number of bits needed to represent value provided. ) bit_length)int_valrrrnum_bits;srcCs d}|r|d7}|dL}|s|S)rrrr)rnumbitsrrrrDs c@seZdZdZddZdS) SubscriberzK An abstract class defining the interface expected by a Publisher. cCstd) A callback method used by a Publisher to notify this Subscriber about updates. :param data: a Python object containing data provided by Publisher. zcannot invoke virtual method!)NotImplementedErrorselfdatarrrupdateVszSubscriber.updateN)r r rrr!rrrrrQs rc@s(eZdZdZejdfddZddZdS) 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. TcCs||_||_dS)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)rr#r$rrr__init__is zPrettyPrinter.__init__cCs,|jt||jr|jddSdS)r N)r#write_pprintpformatr$rrrrr!wszPrettyPrinter.updateN)r r rr_sysstdoutr%r!rrrrr"`s r"c@0eZdZdZddZddZddZdd Zd 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. cCs g|_dS) ConstructorN) subscribersrrrrr%s zPublisher.__init__cCs>t|drt|jr||jvr|j|dSdStd|)z Add a new subscriber. :param subscriber: a new object that implements the Subscriber object interface. r!z'%r does not support required interface!N)hasattrrr!r/append TypeErrorr subscriberrrrattachs   zPublisher.attachcCs(z |j|WdStyYdSw)z Remove an existing subscriber. :param subscriber: a new object that implements the Subscriber object interface. N)r/remove ValueErrorr4rrrdetachs  zPublisher.detachcCs|jD]}||qdS)z Send update data to to all registered Subscribers. :param data: the data to be passed to each registered Subscriber. N)r/r!)rr r5rrrnotifys  zPublisher.notifyN)r r rrr%r6r9r:rrrrr-s  r-c@r,) 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/ cCs|D]D}t||trt|||j|<qt||ttfr?g}||D]}t|tr3|t|q$||q$||j|<q|||j|<qdSN) isinstancedictr;__dict__listtupler2)rdklvrrrr%s    zDictDotLookup.__init__cCs||jvr |j|SdSr<)r?)rnamerrr __getitem__s  zDictDotLookup.__getitem__cCs t|jSr<)rr?r0rrr__iter__s zDictDotLookup.__iter__cCs t|jSr<)r(r)r?r0rrr__repr__s zDictDotLookup.__repr__N)r r rrr%rGrHrIrrrrr;s   r;)rsysr*pprintr(netaddr.compatrr byteorderBIG_ENDIAN_PLATFORMP INET_PTONZZEROFILLNNOHOST INET_ATON Exceptionr rrarrAttributeErrorobjectrr"r-r;rrrrs0    #.