Ñò î¡ßNc@s›dZddkZddkZddklZddkl Z l Z l Z l Z l Z ddklZlZlZlZd„Zdefd„ƒYZdS( s2Set based operations for IP addresses and subnets.iÿÿÿÿN(tIntSet(t IPNetworkt IPAddresst cidr_merget cidr_excludetiprange_to_cidrs(t_zipt _sys_maxintt _dict_keyst _int_typecCs•t|dƒptdƒ‚ng}g}x\|D]T}t|dƒptdƒ‚n|idjo|i|ƒq3|i|ƒq3W||fS(sÿ Takes a sequence of IP addresses and networks splitting them into two separate sequences by IP version. @param iterable: a sequence or iterator contain IP addresses and networks. @return: a two element tuple (ipv4_list, ipv6_list). t__iter__s#A sequence or iterator is expected!tversions IPAddress or IPNetwork expected!i(thasattrt ValueErrort TypeErrorR tappend(titerabletipv4tipv6tip((s3/usr/lib/python2.6/site-packages/netaddr/ip/sets.pyt partition_ipss tIPSetcBsOeZdZdZd dd„Zd„Zd„Zd„Zd„Z d„Z d „Z d „Z dd „Z dd „Zd „Zd„Zd„Zdd„Zd„Zd„Zd„Zd„Zd„ZeZd„Zd„ZeZd„ZeZd„ZeZd„Z e Z!d„Z"e"Z#d„Z$e%d„ƒZ&d„Z'e'Z(RS(!s[ Represents an unordered collection (set) of unique IP addresses and subnets. t_cidrsicCsŒh|_|dj org}xA|D]9}t|tƒot|d|ƒ}n|i|ƒq#Wx%t|ƒD]}t|i|tt|iƒƒ}tt|tgt|ƒƒƒ|_dS(sS Compact internal list of L{IPNetwork} objects using a CIDR merge. N(RtlistRtdictRRtlen(Rtcidrs((s3/usr/lib/python2.6/site-packages/netaddr/ip/sets.pytcompactkscCstdƒ‚dS(sÁ B{Please Note}: IPSet objects are not hashable and cannot be used as dictionary keys or as members of other sets. Raises C{TypeError} if this method is called. sIP sets are unhashable!N(R(R((s3/usr/lib/python2.6/site-packages/netaddr/ip/sets.pyt__hash__rscCs6t|ƒ}x#|iD]}||jotSqWtS(sƒ @param ip: An IP address or subnet. @return: C{True} if IP address or subnet is a member of this IP set. (RRRtFalse(RRR((s3/usr/lib/python2.6/site-packages/netaddr/ip/sets.pyt __contains__zs     cCstit|iƒŒS(sP @return: an iterator over the IP addresses within this IP set. (t _itertoolstchaintsortedR(R((s3/usr/lib/python2.6/site-packages/netaddr/ip/sets.pyR †scCs t|iƒS(sU @return: an iterator over individual IP subnets within this IP set. (R7R(R((s3/usr/lib/python2.6/site-packages/netaddr/ip/sets.pyt iter_cidrsŒscCsMt|tƒot|d|ƒ}n t|ƒ}t|i|<|iƒdS(sï Adds an IP address or subnet to this IP set. Has no effect if it is already present. Note that where possible the IP address or subnet is merged with other members of the set to form more concise CIDR blocks. @param addr: An IP address or subnet. @param flags: decides which rules are applied to the interpretation of the addr value. See the netaddr.core namespace documentation for supported constant values. RN(RR RRRRR1(RRR((s3/usr/lib/python2.6/site-packages/netaddr/ip/sets.pytadd’s   cCsÍt|tƒot|d|ƒ}n t|ƒ}|i|ƒd}d}x8|iD]-}||jot||ƒ}|}PqUqUW|dj o6|i|=x|D]}t|i|x¶tt|iƒt|iƒƒD]}t|i|s3333cCs;t|dƒptSt|ƒt|ƒjo |i|ƒS(s˜ @param other: an IP set. @return: C{True} if this IP set is greater than the C{other} IP set, C{False} otherwise. R(R RIR/t issuperset(RR@((s3/usr/lib/python2.6/site-packages/netaddr/ip/sets.pyt__gt__Xsc Cs4t|dƒptSt|iƒ\}}t|iƒ\}}tg}|D]}||i|ifqM~Œ}tg} |D]}| |i|ifq€~ Œ} tg} |D]}| |i|ifq³~ Œ} tg} |D]}| |i|ifqæ~ Œ}|i| ƒ}| i|ƒ}|o|S(s™ @param other: an IP set. @return: C{True} if every IP address and subnet in other IP set is found within this one. R(R RIRRRNRORPR](RR@RQRRRSRTR"RURVRWRXRYRZR[R\RR((s3/usr/lib/python2.6/site-packages/netaddr/ip/sets.pyR]ds3333cCs'|iƒ}|i|ƒ|iƒ|S(s± @param other: an IP set. @return: the union of this IP set and another as a new IP set (combines IP addresses and subnets from both sets). (RFRDR1(RR@tip_set((s3/usr/lib/python2.6/site-packages/netaddr/ip/sets.pytunion~s   cCs¾g}t|iƒ\}}t|iƒ\}}tg}|D]}||i|ifq>~Œ} tg} |D]}| |i|ifqq~ Œ} | | @} xOt| iƒD]>\} }tt| dƒt|ddƒƒ}|i |ƒq°Wtg}|D]}||i|ifq~Œ}tg}|D]}||i|ifq3~Œ}||@}xOt|iƒD]>\} }tt| dƒt|ddƒƒ}|i |ƒqrWt |ƒS(sµ @param other: an IP set. @return: the intersection of this IP set and another as a new IP set. (IP addresses and subnets common to both sets). iii( RRRNRORPR-t_rangesRRtextendR(RR@t cidr_listRQRRRSRTR"RURVRWRXt ipv4_resulttstarttendR0RYRZR[R\t ipv6_result((s3/usr/lib/python2.6/site-packages/netaddr/ip/sets.pyR?Œs$33  %33  %cCs¾g}t|iƒ\}}t|iƒ\}}tg}|D]}||i|ifq>~Œ} tg} |D]}| |i|ifqq~ Œ} | | A} xOt| iƒD]>\} }tt| dƒt|ddƒƒ}|i |ƒq°Wtg}|D]}||i|ifq~Œ}tg}|D]}||i|ifq3~Œ}||A}xOt|iƒD]>\} }tt| dƒt|ddƒƒ}|i |ƒqrWt |ƒS(sÜ @param other: an IP set. @return: the symmetric difference of this IP set and another as a new IP set (all IP addresses and subnets that are in exactly one of the sets). iii( RRRNRORPR-RaRRRbR(RR@RcRQRRRSRTR"RURVRWRXRdReRfR0RYRZR[R\Rg((s3/usr/lib/python2.6/site-packages/netaddr/ip/sets.pytsymmetric_difference±s$33  %33  %cCs¾g}t|iƒ\}}t|iƒ\}}tg}|D]}||i|ifq>~Œ} tg} |D]}| |i|ifqq~ Œ} | | } xOt| iƒD]>\} }tt| dƒt|ddƒƒ}|i |ƒq°Wtg}|D]}||i|ifq~Œ}tg}|D]}||i|ifq3~Œ}||}xOt|iƒD]>\} }tt| dƒt|ddƒƒ}|i |ƒqrWt |ƒS(sæ @param other: an IP set. @return: the difference between this IP set and another as a new IP set (all IP addresses and subnets that are in this IP set but not found in the other.) iii( RRRNRORPR-RaRRRbR(RR@RcRQRRRSRTR"RURVRWRXRdReRfR0RYRZR[R\Rg((s3/usr/lib/python2.6/site-packages/netaddr/ip/sets.pyt difference×s$33  %33  %cCs1|i}|tijotdtƒ‚n|S(så @return: the cardinality of this IP set (i.e. sum of individual IP addresses). Raises C{IndexError} if size > maxint (a Python limitation). Use the .size property for subnets of any size. sUrange contains greater than %d (maxint) IP addresses! Use the .size property instead.(tsizet_systmaxintt IndexErrorR(RRj((s3/usr/lib/python2.6/site-packages/netaddr/ip/sets.pyt__len__ýs  cCs+tg}|iD]}||iq~ƒS(s˜ The cardinality of this IP set (based on the number of individual IP addresses including those implicitly defined in subnets). (tsumRRj(RR"R((s3/usr/lib/python2.6/site-packages/netaddr/ip/sets.pyRj scCs2dg}t|iƒD]}|t|ƒq~S(s8@return: Python statement to create an equivalent objects IPSet(%r)(R7RR%(RR"RU((s3/usr/lib/python2.6/site-packages/netaddr/ip/sets.pyt__repr__s(s_cidrsN()t__name__t __module__t__doc__t __slots__RRR!R,R1R2R4R R8R9R<R>RBRFRDRGRJRKRMRLt__le__R^R]t__ge__R`t__or__R?t__and__Rht__xor__Rit__sub__RntpropertyRjRpt__str__(((s3/usr/lib/python2.6/site-packages/netaddr/ip/sets.pyR/sJ        1  !     # $ $  (RstsysRkt itertoolsR5tnetaddr.ip.intsetRRNt netaddr.ipRRRRRtnetaddr.compatRRRR RtobjectR(((s3/usr/lib/python2.6/site-packages/netaddr/ip/sets.pyts  ("