U .Ѫ_ @sdZddlZddlZddlmZmZejdkZ dZ Z dZ Z dZZGdd d eZGd d d eZGd d d eZzdZeddZWnek rddZYnXGdddeZGdddeZGdddeZGdddeZdS)z6Common code shared between various netaddr sub modulesN) _callable_iter_dict_keysbigc@seZdZdZdS)AddrFormatErrorzO An Exception indicating a network address is not correctly formatted. N__name__ __module__ __qualname____doc__rr3/Users/cjl/code/aws-vpc-ipam/lambda/netaddr/core.pyrsrc@seZdZdZdS)AddrConversionErrorz^ An Exception indicating a failure to convert between address types or notations. Nr rrrrr#src@seZdZdZdS)NotRegisteredErrorz\ An Exception indicating that an OUI or IAB was not found in the IEEE Registry. Nr rrrrr+sr*cCs|S) :param int_val: an unsigned integer. :return: the minimum number of bits needed to represent value provided. ) bit_length)int_valrrrnum_bits7srcCsd}|r|d7}|dL}q|S)rrrr)rZnumbitsrrrr@s  c@seZdZdZddZdS) SubscriberzK An abstract class defining the interface expected by a Publisher. cCs tddS) 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!N)NotImplementedErrorselfdatarrrupdateRszSubscriber.updateN)r r r r rrrrrrMsrc@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)rrr rrr__init__es zPrettyPrinter.__init__cCs(|jt||jr$|jddS)r N)rwrite_pprintpformatr rrrrrsszPrettyPrinter.updateN)r r r r _sysstdoutr!rrrrrr\src@s0eZdZdZddZddZddZdd 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)Z ConstructorN) subscribersrrrrr!szPublisher.__init__cCs>t|dr.ttdr.||jkr:|j|n td|dS)z Add a new subscriber. :param subscriber: a new object that implements the Subscriber object interface. rzsubscriber.updatez'%r does not support required interface!N)hasattrrevalr)append TypeErrorr subscriberrrrattachs zPublisher.attachcCs*z|j|Wntk r$YnXdS)z Remove an existing subscriber. :param subscriber: a new object that implements the Subscriber object interface. N)r)remove ValueErrorr/rrrdetachszPublisher.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)rrr0rrrnotifys zPublisher.notifyN)r r r r r!r1r4r5rrrrr(s   r(c@s0eZdZdZddZddZddZdd Zd 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/ cCs|D]}t||tr*t|||j|<qt||ttfr~g}||D](}t|trf|t|qH||qH||j|<q|||j|<qdSN) isinstancedictr6__dict__listtupler-)rdklvrrrr!s    zDictDotLookup.__init__cCs||jkr|j|SdSr7)r:)rnamerrr __getitem__s zDictDotLookup.__getitem__cCs t|jSr7)rr:r*rrr__iter__szDictDotLookup.__iter__cCs t|jSr7)r$r%r:r*rrr__repr__szDictDotLookup.__repr__N)r r r r r!rBrCrDrrrrr6s  r6)r sysr&Zpprintr$Znetaddr.compatrr byteorderZBIG_ENDIAN_PLATFORMP INET_PTONZZEROFILLNNOHOST ExceptionrrrarrAttributeErrorobjectrrr(r6rrrrs(   #.