Uc@sdZddlZddlmZmZmZmZmZm Z m Z m Z m Z m Z ddlmZmZddlmZmZmZmZmZdefdYZdefd YZd efd YZed d ZdeefdYZdeefdYZ dZ!dZ"dZ#dZ$dZ%dZ&ddZ'dZ(dZ)dZ*dZ+edZ,eded ed!ed"e d#d$fZ-ed%Z.ed&Z/ed'Z0ed(ed)e d*d+e d,d-fZ1ed.Z2ed/ed0fZ3ed1Z4ed2Z5ed3ed4ed5ed6ed7ed8ed9ed:ed;ed<ed=ed>ed?ed@edAedBfZ6dS(Cs9Routines for IPv4 and IPv6 addresses, subnets and ranges.iN( tAddrFormatErrortAddrConversionErrortnum_bitst DictDotLookuptNOHOSTtNt INET_PTONtPtZEROFILLtZ(tipv4tipv6(t _sys_maxintt _iter_ranget_is_strt _int_typet _str_typetBaseIPcBseZdZdZdZdZededdZdZd Z d Z d Z d Z d Z dZdZdZdZdZdZdZdZdZdZdZedZedZRS(si An abstract base class for common operations shared between various IP related subclasses. t_valuet_modulecCsd|_d|_dS(s Constructor.N(tNoneRR(tself((s7/usr/lib/python2.7/site-packages/netaddr/ip/__init__.pyt__init__s cCspt|ts(tdt|nd|koE|jjknsctd|jjn||_dS(Nsint argument expected, not %sis&value out of bounds for an %s address!( t isinstanceRt TypeErrorttypeRtmax_intRt family_nameR(Rtvalue((s7/usr/lib/python2.7/site-packages/netaddr/ip/__init__.pyt _set_value s "cCs|jS(N(R(R((s7/usr/lib/python2.7/site-packages/netaddr/ip/__init__.pyt(stdocs?a positive integer representing the value of IP address/subnet.cCstS(sP :return: a key tuple that uniquely identifies this IP address. (tNotImplemented(R((s7/usr/lib/python2.7/site-packages/netaddr/ip/__init__.pytkey+scCstS(sg :return: A key tuple used to compare and sort this `IPAddress` correctly. (R (R((s7/usr/lib/python2.7/site-packages/netaddr/ip/__init__.pytsort_key1scCst|jS(sM :return: A hash value uniquely indentifying this IP object. (thashR!(R((s7/usr/lib/python2.7/site-packages/netaddr/ip/__init__.pyt__hash__8scCs9y|j|jkSWnttfk r4tSXdS(s :param other: an `IPAddress` or `IPNetwork` object. :return: ``True`` if this `IPAddress` or `IPNetwork` object is equivalent to ``other``, ``False`` otherwise. N(R!tAttributeErrorRR (Rtother((s7/usr/lib/python2.7/site-packages/netaddr/ip/__init__.pyt__eq__>scCs9y|j|jkSWnttfk r4tSXdS(s :param other: an `IPAddress` or `IPNetwork` object. :return: ``True`` if this `IPAddress` or `IPNetwork` object is not equivalent to ``other``, ``False`` otherwise. N(R!R%RR (RR&((s7/usr/lib/python2.7/site-packages/netaddr/ip/__init__.pyt__ne__JscCs9y|j|jkSWnttfk r4tSXdS(s :param other: an `IPAddress` or `IPNetwork` object. :return: ``True`` if this `IPAddress` or `IPNetwork` object is less than ``other``, ``False`` otherwise. N(R"R%RR (RR&((s7/usr/lib/python2.7/site-packages/netaddr/ip/__init__.pyt__lt__VscCs9y|j|jkSWnttfk r4tSXdS(s :param other: an `IPAddress` or `IPNetwork` object. :return: ``True`` if this `IPAddress` or `IPNetwork` object is less than or equal to ``other``, ``False`` otherwise. N(R"R%RR (RR&((s7/usr/lib/python2.7/site-packages/netaddr/ip/__init__.pyt__le__bscCs9y|j|jkSWnttfk r4tSXdS(s :param other: an `IPAddress` or `IPNetwork` object. :return: ``True`` if this `IPAddress` or `IPNetwork` object is greater than ``other``, ``False`` otherwise. N(R"R%RR (RR&((s7/usr/lib/python2.7/site-packages/netaddr/ip/__init__.pyt__gt__nscCs9y|j|jkSWnttfk r4tSXdS(s :param other: an `IPAddress` or `IPNetwork` object. :return: ``True`` if this `IPAddress` or `IPNetwork` object is greater than or equal to ``other``, ``False`` otherwise. N(R"R%RR (RR&((s7/usr/lib/python2.7/site-packages/netaddr/ip/__init__.pyt__ge__zscCs |j S(s<:return: ``True`` if this IP is unicast, ``False`` otherwise(t is_multicast(R((s7/usr/lib/python2.7/site-packages/netaddr/ip/__init__.pyt is_unicastscCs6|jtkr|tkS|jtkr2|tkSdS(s>:return: ``True`` if this IP is multicast, ``False`` otherwiseN(Rt_ipv4tIPV4_MULTICASTt_ipv6tIPV6_MULTICAST(R((s7/usr/lib/python2.7/site-packages/netaddr/ip/__init__.pyR-s cCs<|jjdkr|tkS|jjdkr8|tkSdS(s :return: ``True`` if this IP is loopback address (not for network transmission), ``False`` otherwise. References: RFC 3330 and 4291. iiN(Rtversiont IPV4_LOOPBACKt IPV6_LOOPBACK(R((s7/usr/lib/python2.7/site-packages/netaddr/ip/__init__.pyt is_loopbacks cCs|jjdkr6xWtD]}||krtSqWn6|jjdkrlx!tD]}||krOtSqOWn|jr|tStS(s :return: ``True`` if this IP is for internal/private use only (i.e. non-public), ``False`` otherwise. Reference: RFCs 1918, 3330, 4193, 3879 and 2365. ii(RR3t IPV4_PRIVATEtTruet IPV6_PRIVATEt is_link_localtFalse(Rtcidr((s7/usr/lib/python2.7/site-packages/netaddr/ip/__init__.pyt is_privates       cCs<|jjdkr|tkS|jjdkr8|tkSdS(s :return: ``True`` if this IP is link-local address ``False`` otherwise. Reference: RFCs 3927 and 4291. iiN(RR3tIPV4_LINK_LOCALtIPV6_LINK_LOCAL(R((s7/usr/lib/python2.7/site-packages/netaddr/ip/__init__.pyR:s cCsp|jjdkr6xWtD]}||krtSqWn6|jjdkrlx!tD]}||krOtSqOWntS(s :return: ``True`` if this IP is in IANA reserved range, ``False`` otherwise. Reference: RFCs 3330 and 3171. ii(RR3t IPV4_RESERVEDR8t IPV6_RESERVEDR;(RR<((s7/usr/lib/python2.7/site-packages/netaddr/ip/__init__.pyt is_reserveds      cCs#|jjdko"|jd?dkS(sp :return: ``True`` if this IP is IPv4-compatible IPv6 address, ``False`` otherwise. ii i(RR3R(R((s7/usr/lib/python2.7/site-packages/netaddr/ip/__init__.pytis_ipv4_mappedscCs#|jjdko"|jd?dkS(sl :return: ``True`` if this IP is IPv4-mapped IPv6 address, ``False`` otherwise. ii i(RR3R(R((s7/usr/lib/python2.7/site-packages/netaddr/ip/__init__.pytis_ipv4_compatscCs ddlm}t||S(s~ A record dict containing IANA registration details for this IP address if available, None otherwise. i(tquery(tnetaddr.ip.ianaRER(RRE((s7/usr/lib/python2.7/site-packages/netaddr/ip/__init__.pytinfoscCs |jjS(s6the IP protocol version represented by this IP object.(RR3(R((s7/usr/lib/python2.7/site-packages/netaddr/ip/__init__.pyR3s(s_values_module(t__name__t __module__t__doc__t __slots__RRtpropertyRR!R"R$R'R(R)R*R+R,R.R-R6R=R:RBRCRDRGR3(((s7/usr/lib/python2.7/site-packages/netaddr/ip/__init__.pyRs2             t IPAddresscBsyeZdZd$Zd%ddZdZdZdZdZ dZ dZ d Z d Z e Zd Zd Zd ZdZdZdZdZdZdZd%dZedZedZedZedZdZedZ d%dZ!dZ"dZ#dZ$dZ%d Z&d!Z'e'Z(d"Z)d#Z*RS(&s An individual IPv4 or IPv6 address without a net mask or subnet prefix. To support these and other network based operations, see `IPNetwork`. icCstt|jt|trj|d k rO||jjkrOtdn|j |_ |j|_nM|d k r|dkrt |_q|dkrt |_qtd|nt |rd|krtd|j jn|jd krt|trydt|ko+t jknrKt||_ t |_nCt jt|kont jknrt||_ t |_nWqtk rqXnGxDt t fD]6}y|j|||_ Wn qqX||_PqW|jd krtd|qnt |rmy|jj|||_ Wqtk ritd ||jjfqXnJdt|ko|jjknrt||_ ntd |d S( s Constructor. :param addr: an IPv4 or IPv6 address which may be represented in an accepted string format, as an unsigned integer or as another IPAddress object (copy construction). :param version: (optional) optimizes version detection if specified and distinguishes between IPv4 and IPv6 for addresses with an equivalent integer value. :param flags: (optional) decides which rules are applied to the interpretation of the addr value. Supported constants are INET_PTON and ZEROFILL. See the netaddr.core docs for further details. s1cannot switch IP versions using copy constructor!iis%r is an invalid IP version!t/sQ%s() does not support netmasks or subnet prefixes! See documentation for details.is+failed to detect a valid IP address from %rsbase address %r is not IPv%dsbad address format: %rN(tsuperRMRRRRRR3t ValueErrorRR/R1Rt __class__RHRtintRt str_to_intR(RtaddrR3tflagstmodule((s7/usr/lib/python2.7/site-packages/netaddr/ip/__init__.pyRsZ      % (    (cCs|j|jjfS(s1:returns: Pickled state of an `IPAddress` object.(RRR3(R((s7/usr/lib/python2.7/site-packages/netaddr/ip/__init__.pyt __getstate__BscCs_|\}}||_|dkr-t|_n.|dkrEt|_ntdt|dS(sT :param state: data used to unpickle a pickled `IPAddress` object. iis&unpickling failed for object state: %sN(RR/RR1RPtstr(RtstateRR3((s7/usr/lib/python2.7/site-packages/netaddr/ip/__init__.pyt __setstate__Fs      cCs|js|jjS|j}d}x8|dkr_|d@dkrHPn|d7}|dL}q(W|jj|}d|ko|jjknstd|n|S(s @return: If this IP is a valid netmask, the number of non-zero bits are returned, otherwise it returns the width in bits for the IP address version. iis+Unexpected mask length %d for address type!(t is_netmaskRtwidthRRP(Rti_valtnumbitst mask_length((s7/usr/lib/python2.7/site-packages/netaddr/ip/__init__.pyt netmask_bitsWs    " cCs|jd}||d@dkS(sV :return: ``True`` if this IP address host mask, ``False`` otherwise. ii(R(Rtint_val((s7/usr/lib/python2.7/site-packages/netaddr/ip/__init__.pyt is_hostmaskqs cCs)|j|jjAd}||d@dkS(sY :return: ``True`` if this IP address network mask, ``False`` otherwise. ii(RRR(RRa((s7/usr/lib/python2.7/site-packages/netaddr/ip/__init__.pyR[xscCsRt|j|}d|ko0|jjknrB||_|StddS(s Increases the numerical value of this IPAddress by num. An IndexError is raised if result exceeds maximum IP address value or is less than zero. :param num: size of IP address increment. is)result outside valid IP address boundary!N(RRRRRt IndexError(Rtnumt new_value((s7/usr/lib/python2.7/site-packages/netaddr/ip/__init__.pyt__iadd__s " cCsRt|j|}d|ko0|jjknrB||_|StddS(s Decreases the numerical value of this IPAddress by num. An IndexError is raised if result is less than zero or exceeds maximum IP address value. :param num: size of IP address decrement. is)result outside valid IP address boundary!N(RRRRRRc(RRdRe((s7/usr/lib/python2.7/site-packages/netaddr/ip/__init__.pyt__isub__s " cCs[t|j|}d|ko0|jjknrK|j||jjStddS(s Add the numerical value of this IP address to num and provide the result as a new IPAddress object. :param num: size of IP address increase. :return: a new IPAddress object with its numerical value increased by num. is)result outside valid IP address boundary!N(RRRRRRQR3Rc(RRdRe((s7/usr/lib/python2.7/site-packages/netaddr/ip/__init__.pyt__add__s "cCs[t|j|}d|ko0|jjknrK|j||jjStddS(s Subtract the numerical value of this IP address from num providing the result as a new IPAddress object. :param num: size of IP address decrease. :return: a new IPAddress object with its numerical value decreased by num. is)result outside valid IP address boundary!N(RRRRRRQR3Rc(RRdRe((s7/usr/lib/python2.7/site-packages/netaddr/ip/__init__.pyt__sub__s "cCs[t||j}d|ko0|jjknrK|j||jjStddS(s Subtract num (lvalue) from the numerical value of this IP address (rvalue) providing the result as a new IPAddress object. :param num: size of IP address decrease. :return: a new IPAddress object with its numerical value decreased by num. is)result outside valid IP address boundary!N(RRRRRRQR3Rc(RRdRe((s7/usr/lib/python2.7/site-packages/netaddr/ip/__init__.pyt__rsub__s "cCs|jj|jfS(sP :return: a key tuple that uniquely identifies this IP address. (RR3R(R((s7/usr/lib/python2.7/site-packages/netaddr/ip/__init__.pyR!scCs|jj|j|jjfS(sI:return: A key tuple used to compare and sort this `IPAddress` correctly.(RR3RR\(R((s7/usr/lib/python2.7/site-packages/netaddr/ip/__init__.pyR"scCs|jS(s<:return: the value of this IP address as an unsigned integer(R(R((s7/usr/lib/python2.7/site-packages/netaddr/ip/__init__.pyt__int__scCs|jS(s<:return: the value of this IP address as an unsigned integer(R(R((s7/usr/lib/python2.7/site-packages/netaddr/ip/__init__.pyt__long__scCs|jdkrdSd|jS(s;:return: an octal string representation of this IP address.it0s0%o(R(R((s7/usr/lib/python2.7/site-packages/netaddr/ip/__init__.pyt__oct__scCs d|jS(s@:return: a hexadecimal string representation of this IP address.s0x%x(R(R((s7/usr/lib/python2.7/site-packages/netaddr/ip/__init__.pyt__hex__scCs|jS(sx :return: return the integer value of this IP address when called by hex(), oct() or bin(). (R(R((s7/usr/lib/python2.7/site-packages/netaddr/ip/__init__.pyt __index__scCs|jj|j|S(s :param word_sep: (optional) the separator to insert between words. Default: None - use default separator for address type. :return: the value of this IP address as a binary digit string.(Rt int_to_bitsR(Rtword_sep((s7/usr/lib/python2.7/site-packages/netaddr/ip/__init__.pytbitsscCs|jj|jS(s7The value of this IP address as a packed binary string.(Rt int_to_packedR(R((s7/usr/lib/python2.7/site-packages/netaddr/ip/__init__.pytpackedscCs|jj|jS(sx A list of unsigned integer words (octets for IPv4, hextets for IPv6) found in this IP address. (Rt int_to_wordsR(R((s7/usr/lib/python2.7/site-packages/netaddr/ip/__init__.pytwordsscCs|jj|jS(s The value of this IP adddress in standard Python binary representational form (0bxxx). A back port of the format provided by the builtin bin() function found in Python 2.6.x and higher. (Rt int_to_binR(R((s7/usr/lib/python2.7/site-packages/netaddr/ip/__init__.pytbinscCs|jj|jS(s1The reverse DNS lookup record for this IP address(Rt int_to_arpaR(R((s7/usr/lib/python2.7/site-packages/netaddr/ip/__init__.pyt reverse_dnsscCsd}|j}|jjdkr6||jd}n|jjdkrd|jkoetjknr||jd}qtj|jkodknr||jdd}qtd|n|S(s Raises an `AddrConversionError` if IPv6 address cannot be converted to IPv4. :return: A numerically equivalent version 4 `IPAddress` object. iiiIIs2IPv6 address %s unsuitable for conversion to IPv4!N(RRQRR3RR/RR(Rtiptklass((s7/usr/lib/python2.7/site-packages/netaddr/ip/__init__.pyR s "" cCsd}|j}|jjdkrt|r_d|jkoAdknr_||jdd}q||jd}nF|jjdkr||jd}|s|d|jd}qn|S(s .. note:: The IPv4-mapped IPv6 address format is now considered deprecated. See RFC 4291 or later for details. :param ipv4_compatible: If ``True`` returns an IPv4-mapped address (::ffff:x.x.x.x), an IPv4-compatible (::x.x.x.x) address otherwise. Default: False (IPv4-mapped). :return: A numerically equivalent version 6 `IPAddress` object. iIIiN(RRQRR3R(Rtipv4_compatibleR|R}((s7/usr/lib/python2.7/site-packages/netaddr/ip/__init__.pyR +s  cCsF|dk r-t|ds-tdq-n|jj|jd|S(s Only relevant for IPv6 addresses. Has no effect for IPv4. :param dialect: An ipv6_* dialect class. :return: an alternate string representation for this IP address. tword_fmts-custom dialects should subclass ipv6_verbose!tdialectN(RthasattrRRt int_to_strR(RR((s7/usr/lib/python2.7/site-packages/netaddr/ip/__init__.pytformatHs  cCs#|j|jt|B|jjS(s :param other: An `IPAddress` object (or other int-like object). :return: bitwise OR (x | y) between the integer value of this IP address and ``other``. (RQRRRRR3(RR&((s7/usr/lib/python2.7/site-packages/netaddr/ip/__init__.pyt__or__VscCs#|j|jt|@|jjS(s :param other: An `IPAddress` object (or other int-like object). :return: bitwise AND (x & y) between the integer value of this IP address and ``other``. (RQRRRRR3(RR&((s7/usr/lib/python2.7/site-packages/netaddr/ip/__init__.pyt__and___scCs#|j|jt|A|jjS(s :param other: An `IPAddress` object (or other int-like object). :return: bitwise exclusive OR (x ^ y) between the integer value of this IP address and ``other``. (RQRRRRR3(RR&((s7/usr/lib/python2.7/site-packages/netaddr/ip/__init__.pyt__xor__hscCs|j|j|>|jjS(s :param numbits: size of bitwise shift. :return: an `IPAddress` object based on this one with its integer value left shifted by ``numbits``. (RQRRR3(RR^((s7/usr/lib/python2.7/site-packages/netaddr/ip/__init__.pyt __lshift__qscCs|j|j|?|jjS(s :param numbits: size of bitwise shift. :return: an `IPAddress` object based on this one with its integer value right shifted by ``numbits``. (RQRRR3(RR^((s7/usr/lib/python2.7/site-packages/netaddr/ip/__init__.pyt __rshift__zscCs t|jS(si:return: ``True`` if the numerical value of this IP address is not zero, ``False`` otherwise.(tboolR(R((s7/usr/lib/python2.7/site-packages/netaddr/ip/__init__.pyt __nonzero__scCs|jj|jS(s,:return: IP address in presentational format(RRR(R((s7/usr/lib/python2.7/site-packages/netaddr/ip/__init__.pyt__str__scCsd|jj|fS(s8:return: Python statement to create an equivalent objects%s('%s')(RQRH(R((s7/usr/lib/python2.7/site-packages/netaddr/ip/__init__.pyt__repr__s(N(+RHRIRJRKRRRWRZR`RbR[RfRgRht__radd__RiRjR!R"RkRlRnRoRpRsRLRuRwRyR{R R;R RRRRRRRt__bool__RR(((s7/usr/lib/python2.7/site-packages/netaddr/ip/__init__.pyRMsLQ                       t IPListMixincBsPeZdZdZedZdZdZdZdZ e Z RS(su A mixin class providing shared list-like functionality to classes representing groups of IP addresses. cCs=t|j|jj}t|j|jj}t||S(s :return: An iterator providing access to all `IPAddress` objects within range represented by this ranged IP object. (RMtfirstRR3tlastt iter_iprange(Rtstart_iptend_ip((s7/usr/lib/python2.7/site-packages/netaddr/ip/__init__.pyt__iter__scCst|j|jdS(sP The total number of IP addresses within this ranged IP object. i(RRRR(R((s7/usr/lib/python2.7/site-packages/netaddr/ip/__init__.pytsizescCs,|j}|tkr(tdtn|S(s :return: the number of IP addresses in this ranged IP object. Raises an `IndexError` if size > system max int (a Python 2.x limitation). Use the .size property for subnets of any size. sVrange contains more than %d (sys.maxint) IP addresses! Use the .size property instead.(RR Rc(RR((s7/usr/lib/python2.7/site-packages/netaddr/ip/__init__.pyt__len__s    cCsd}t|dr|jjdkr6tdn|j|j\}}}||dksm||krtt|j |jjg}qt|j ||jj}t|j |||jj}t |||}nyt |}|j |ko dknr4t|j |d|jj}nNd|koR|jdknrvt|j ||jj}n t dWn!tk rtd|nX|S( s :return: The IP address(es) in this `IPNetwork` object referenced by index or slice. As slicing can produce large sequences of objects an iterator is returned instead of the more usual `list`. tindicesisIPv6 slices are not supported!iis'index out range for address range size!sunsupported index type %r!N(RRRR3RRRtiterRMRRRRRRcRP(RtindextitemtstarttstoptstepRR((s7/usr/lib/python2.7/site-packages/netaddr/ip/__init__.pyt __getitem__s($   ## cCst|tr~|jj|jjkr+tSt|tr\|j|jko[|j|jkS|j|jko}|j|jkSt||kS(s :param other: an `IPAddress` or ranged IP object. :return: ``True`` if other falls within the boundary of this one, ``False`` otherwise. ( RRRR3R;RMRRR(RR&((s7/usr/lib/python2.7/site-packages/netaddr/ip/__init__.pyt __contains__s""cCstS(s Ranged IP objects always represent a sequence of at least one IP address and are therefore always True in the boolean context. (R8(R((s7/usr/lib/python2.7/site-packages/netaddr/ip/__init__.pyRs( RHRIRJRRLRRRRRR(((s7/usr/lib/python2.7/site-packages/netaddr/ip/__init__.pyRs  %  ic Cst|trt|dkr7td|jn|\}}d|ko]|jknsxtd|jnd|ko|jknstd|jqnt|trs|rt|}nd|kr|j dd\}}n |}d}yt ||j dt }WnZtk r|j d krltj|} t | |j dt }qtd |nX|j}yt|}Wntk r|dkr;|j}q;nwtk r:t ||j dt } | jr|j| j}q;| jr'|j| j}q;td |nXd|koU|jknstd |jqntd t||t@r|j|} || @}n||fS(Nisinvalid %s tuple!is#invalid address value for %s tuple!sinvalid prefix for %s tuple!RNiRUisinvalid IPNetwork address %s!s!addr %r is not a valid IPNetwork!sinvalid prefix for %s address!sunexpected type %s for addr arg(RttupletlenRRRR\Rtcidr_abbrev_to_verbosetsplitRRMR3RR/texpand_partial_addressRRRRRPR[tnetmask_to_prefixRbthostmask_to_prefixRRtprefix_to_netmask( RVRTtimplicit_prefixRURt prefixlentval1tval2R|t expanded_addrtmasktnetmask((s7/usr/lib/python2.7/site-packages/netaddr/ip/__init__.pytparse_ip_networks\            t IPNetworkcBseZdZd#Zed$ddZdZdZdZ e de dd Z e d Z e d Z e d Ze d Ze dZe dZe dZe dZe dZe dZdZdZdZdZdZdZedZddZddZddZd$d$dZ d Z!d!Z"d"Z#RS(%sf An IPv4 or IPv6 network or subnet. A combination of an IP address and a network mask. Accepts CIDR and several related variants : a) Standard CIDR:: x.x.x.x/y -> 192.0.2.0/24 x::/y -> fe80::/10 b) Hybrid CIDR format (netmask address instead of prefix), where 'y' address represent a valid netmask:: x.x.x.x/y.y.y.y -> 192.0.2.0/255.255.255.0 x::/y:: -> fe80::/ffc0:: c) ACL hybrid CIDR format (hostmask address instead of prefix like Cisco's ACL bitmasks), where 'y' address represent a valid netmask:: x.x.x.x/y.y.y.y -> 192.0.2.0/0.0.0.255 x::/y:: -> fe80::/3f:ffff:ffff:ffff:ffff:ffff:ffff:ffff d) Abbreviated CIDR format (as of netaddr 0.7.x this requires the optional constructor argument ``implicit_prefix=True``):: x -> 192 x/y -> 10/8 x.x/y -> 192.168/16 x.x.x/y -> 192.168.0/24 which are equivalent to:: x.0.0.0/y -> 192.0.0.0/24 x.0.0.0/y -> 10.0.0.0/8 x.x.0.0/y -> 192.168.0.0/16 x.x.x.0/y -> 192.168.0.0/24 t _prefixlenicCstt|jd \}}}t|drO|j}|j}|j}nIt|dr||j}|j}|j}n|dkrt t |d|d|\}}t }n|dkrt t |d|d|\}}t }n|d k rt d|ny%t }t ||||\}}Wnit k ry%t }t ||||\}}Wnt k rtnX|d krt d|qnX||_||_||_d S( s Constructor. :param addr: an IPv4 or IPv6 address with optional CIDR prefix, netmask or hostmask. May be an IP address in presentation (string) format, an tuple containing and integer address and a network prefix, or another IPAddress/IPNetwork object (copy construction). :param implicit_prefix: (optional) if True, the constructor uses classful IPv4 rules to select a default prefix when one is not provided. If False it uses the length of the IP address version. (default: False) :param version: (optional) optimizes version detection if specified and distinguishes between IPv4 and IPv6 for addresses with an equivalent integer value. :param flags: (optional) decides which rules are applied to the interpretation of the addr value. Currently only supports the NOHOST option. See the netaddr.core docs for further details. RRiRRUis%r is an invalid IP version!sinvalid IPNetwork %sN(NNN(RORRRRRRRR\RR/R1RPR(RRTRR3RURRRV((s7/usr/lib/python2.7/site-packages/netaddr/ip/__init__.pyRgsH                    cCs|j|j|jjfS(s0:return: Pickled state of an `IPNetwork` object.(RRRR3(R((s7/usr/lib/python2.7/site-packages/netaddr/ip/__init__.pyRWscCs|\}}}||_|dkr0t|_n.|dkrHt|_ntdt|d|ko{|jjknr||_ntdt|dS(sT :param state: data used to unpickle a pickled `IPNetwork` object. iis%unpickling failed for object state %siN(RR/RR1RPRXR\R(RRYRRR3((s7/usr/lib/python2.7/site-packages/netaddr/ip/__init__.pyRZs     " cCspt|ts(tdt|nd|koE|jjknsctd|jjn||_dS(Nsint argument expected, not %sis!invalid prefix for an %s address!( RRRRRR\RRR(RR((s7/usr/lib/python2.7/site-packages/netaddr/ip/__init__.pyt_set_prefixlens "cCs|jS(N(R(R((s7/usr/lib/python2.7/site-packages/netaddr/ip/__init__.pyRsRsCsize of the bitmask used to separate the network from the host bitscCst|j|jjS(s The IP address of this `IPNetwork` object. This is may or may not be the same as the network IP address which varies according to the value of the CIDR subnet prefix. (RMRRR3(R((s7/usr/lib/python2.7/site-packages/netaddr/ip/__init__.pyR|scCst|j|j@|jjS(s/The network address of this `IPNetwork` object.(RMRt _netmask_intRR3(R((s7/usr/lib/python2.7/site-packages/netaddr/ip/__init__.pytnetworkscCst|j|jB|jjS(s0The broadcast address of this `IPNetwork` object(RMRt _hostmask_intRR3(R((s7/usr/lib/python2.7/site-packages/netaddr/ip/__init__.pyt broadcastscCs|j|jj|jA@S(se The integer value of first IP address found within this `IPNetwork` object. (RRRR(R((s7/usr/lib/python2.7/site-packages/netaddr/ip/__init__.pyRscCs&d|jj|j>d}|j|BS(sd The integer value of last IP address found within this `IPNetwork` object. i(RR\RR(Rthostmask((s7/usr/lib/python2.7/site-packages/netaddr/ip/__init__.pyRscCs&|jj|jA}t||jjS(s+The subnet mask of this `IPNetwork` object.(RRRRMR3(RR((s7/usr/lib/python2.7/site-packages/netaddr/ip/__init__.pyRscCs|jj|jAS(s+Same as self.netmask, but in integer format(RRR(R((s7/usr/lib/python2.7/site-packages/netaddr/ip/__init__.pyRscCs.d|jj|j>d}t||jjS(s)The host mask of this `IPNetwork` object.i(RR\RRMR3(RR((s7/usr/lib/python2.7/site-packages/netaddr/ip/__init__.pyRscCsd|jj|j>dS(s,Same as self.hostmask, but in integer formati(RR\R(R((s7/usr/lib/python2.7/site-packages/netaddr/ip/__init__.pyRscCs)t|j|j@|jfd|jjS(s The true CIDR address for this `IPNetwork` object which omits any host bits to the right of the CIDR subnet prefix. R3(RRRRRR3(R((s7/usr/lib/python2.7/site-packages/netaddr/ip/__init__.pyR< scCsnt|j|j|}||jd|jjkrFtdn|dkratdn||_|S(sP Increases the value of this `IPNetwork` object by the current size multiplied by ``num``. An `IndexError` is raised if result exceeds maximum IP address value or is less than zero. :param num: (optional) number of `IPNetwork` blocks to increment this IPNetwork's value by. is#increment exceeds address boundary!isincrement is less than zero!(RRRRRRRcR(RRdRe((s7/usr/lib/python2.7/site-packages/netaddr/ip/__init__.pyRfs   cCsnt|j|j|}|dkr5tdn||jd|jjkratdn||_|S(sP Decreases the value of this `IPNetwork` object by the current size multiplied by ``num``. An `IndexError` is raised if result is less than zero or exceeds maximum IP address value. :param num: (optional) number of `IPNetwork` blocks to decrement this IPNetwork's value by. isdecrement is less than zero!is#decrement exceeds address boundary!(RRRRRcRRR(RRdRe((s7/usr/lib/python2.7/site-packages/netaddr/ip/__init__.pyRg*s   cCst|tr|jj|jjkr+tS|jj|j}|j|?}t|tr||>|j jko|d|>|j jkS|j|?}t|t r||kSt|t r||ko|j|jkSnt ||kS(s :param other: an `IPAddress` or ranged IP object. :return: ``True`` if other falls within the boundary of this one, ``False`` otherwise. i( RRRR3R;R\RRtIPRanget_startt_endRMR(RR&t shiftwidthtself_nett other_net((s7/usr/lib/python2.7/site-packages/netaddr/ip/__init__.pyR?s   cCs|jj|j|jfS(sR :return: A key tuple used to uniquely identify this `IPNetwork`. (RR3RR(R((s7/usr/lib/python2.7/site-packages/netaddr/ip/__init__.pyR!]scCsJ|jd}|j|jj|jA@}|j|}|jj|||fS(s[ :return: A key tuple used to compare and sort this `IPNetwork` correctly. i(RRRRRR3(Rt net_size_bitsRt host_bits((s7/usr/lib/python2.7/site-packages/netaddr/ip/__init__.pyR"cs  cCsd }|j}|jjdkr@|d|j|jf}n|jjdkrd|jkootjknrtj |j}|d||jdf}qtj|jkodknrtj |jd}|d||jdf}qt d|n|S( s :return: A numerically equivalent version 4 `IPNetwork` object. Raises an `AddrConversionError` if IPv6 address cannot be converted to IPv4. is%s/%diii`IIs2IPv6 address %s unsuitable for conversion to IPv4!N( RRQRR3R|RRR/RRR(RR|R}RT((s7/usr/lib/python2.7/site-packages/netaddr/ip/__init__.pyR ls " "  cCsd}|j}|jjdkr|rkd|jkoAdknrk||jd|jfdd}q||j|jfdd}nf|jjdkr|r||j|jdfdd}q|d|j|jdfdd}n|S(s .. note:: the IPv4-mapped IPv6 address format is now considered deprecated. See RFC 4291 or later for details. :param ipv4_compatible: If ``True`` returns an IPv4-mapped address (::ffff:x.x.x.x), an IPv4-compatible (::x.x.x.x) address otherwise. Default: False (IPv4-mapped). :return: A numerically equivalent version 6 `IPNetwork` object. iIIR3ii`N(RRQRR3RR(RR~R|R}((s7/usr/lib/python2.7/site-packages/netaddr/ip/__init__.pyR s   !% icCs6|jd|j|jf|jj}||8}|S(s :param step: the number of IP subnets between this `IPNetwork` object and the expected subnet. Default: 1 (the previous IP subnet). :return: The adjacent subnet preceding this `IPNetwork` object. s%s/%d(RQRRRR3(RRtip_copy((s7/usr/lib/python2.7/site-packages/netaddr/ip/__init__.pytpreviouss cCs6|jd|j|jf|jj}||7}|S(s :param step: the number of IP subnets between this `IPNetwork` object and the expected subnet. Default: 1 (the next IP subnet). :return: The adjacent subnet succeeding this `IPNetwork` object. s%s/%d(RQRRRR3(RRR((s7/usr/lib/python2.7/site-packages/netaddr/ip/__init__.pytnexts cCsd|ko|jjknsAtd||jjfng}|j}||_x5|j|jkr|j|j|jd7_q\W|S(sb Provides a list of supernets for this `IPNetwork` object between the size of the current prefix and (if specified) an endpoint prefix. :param prefixlen: (optional) a CIDR prefix for the maximum supernet. Default: 0 - returns all possible supernets. :return: a tuple of supernet `IPNetwork` objects. is"CIDR prefix /%d invalid for IPv%d!i(RR\RPR3R<Rtappend(RRt supernetstsupernet((s7/usr/lib/python2.7/site-packages/netaddr/ip/__init__.pyRs "  c csGd|jko |jjknsDtd||jjfn|j|ks\tn|jj}d||jd||}|dkr|}nd|ko|knstdn|jj|j}d}x`||krB|j d||f|jj}|j |j |7_ ||_|d7}|VqWdS(s A generator that divides up this IPNetwork's subnet into smaller subnets based on a specified CIDR prefix. :param prefixlen: a CIDR prefix indicating size of subnets to be returned. :param count: (optional) number of consecutive IP subnets to be returned. :return: an iterator containing IPNetwork subnet objects. is"CIDR prefix /%d invalid for IPv%d!iis,count outside of current IP subnet boundary!s%s/%dN( RRR\RPR3t StopIterationRRRRQRR( RRtcounttfmtR\t max_subnetst base_subnettitsubnet((s7/usr/lib/python2.7/site-packages/netaddr/ip/__init__.pyRs( %      cCstg}|jjdkrn|jdkrtt|jd|jjt|jd|jj}qnI|jdkrtt|jd|jjt|j|jj}n|S(s An generator that provides all the IP addresses that can be assigned to hosts within the range of this IP object's subnet. - for IPv4, the network and broadcast addresses are always excluded. Any subnet that contains less than 4 IP addresses yields an empty list. - for IPv6, only the unspecified address '::' or Subnet-Router anycast address (first address in the network) is excluded. :return: an IPAddress iterator iii(RRR3RRRMRR(Rtit_hosts((s7/usr/lib/python2.7/site-packages/netaddr/ip/__init__.pyt iter_hostss %cCs&|jj|j}d||jfS(s&:return: this IPNetwork in CIDR formats%s/%s(RRRR(RRT((s7/usr/lib/python2.7/site-packages/netaddr/ip/__init__.pyRscCsd|jj|fS(s8:return: Python statement to create an equivalent objects%s('%s')(RQRH(R((s7/usr/lib/python2.7/site-packages/netaddr/ip/__init__.pyR s(s _prefixlenN($RHRIRJRKR;RRRWRZRRLRR|RRRRRRRRR<RfRgRR!R"R R RRRRRRR(((s7/usr/lib/python2.7/site-packages/netaddr/ip/__init__.pyR<s@(D            ) RcBseZdZdZddZdZdZdZedZ ed Z d Z d Z d Z d ZdZRS(s An arbitrary IPv4 or IPv6 address range. Formed from a lower and upper bound IP address. The upper bound IP cannot be numerically smaller than the lower bound and the IP version of both must match. RRicCsst|d||_|jj|_t||jjd||_t|jt|jkrotdndS(s Constructor. :param start: an IPv4 or IPv6 address that forms the lower boundary of this IP range. :param end: an IPv4 or IPv6 address that forms the upper boundary of this IP range. :param flags: (optional) decides which rules are applied to the interpretation of the start and end values. Supported constants are INET_PTON and ZEROFILL. See the netaddr.core docs for further details. RUs(lower bound IP greater than upper bound!N(RMRRR3RRRR(RRtendRU((s7/usr/lib/python2.7/site-packages/netaddr/ip/__init__.pyR0s cCs|jj|jj|jjfS(s.:return: Pickled state of an `IPRange` object.(RRRRR3(R((s7/usr/lib/python2.7/site-packages/netaddr/ip/__init__.pyRWFscCsF|\}}}t|||_|jj|_t|||_dS(sQ :param state: data used to unpickle a pickled `IPRange` object. N(RMRRR(RRYRRR3((s7/usr/lib/python2.7/site-packages/netaddr/ip/__init__.pyRZJscCst|tr|jj|jjkr+tSt|trb|jj|jkoa|jj|jkSt|t r|jj|jjko|jj|jjkSt|t r|jj |j }|j|?|>}|d|>}|jj|ko|jj|kSnt||kS(Ni( RRRR3R;RMRRRRRR\R(RR&Rt other_starttother_next_start((s7/usr/lib/python2.7/site-packages/netaddr/ip/__init__.pyRTs cCs t|jS(s?The integer value of first IP address in this `IPRange` object.(RRR(R((s7/usr/lib/python2.7/site-packages/netaddr/ip/__init__.pyRjscCs t|jS(s>The integer value of last IP address in this `IPRange` object.(RRR(R((s7/usr/lib/python2.7/site-packages/netaddr/ip/__init__.pyRoscCs|jj|j|jfS(sP :return: A key tuple used to uniquely identify this `IPRange`. (RR3RR(R((s7/usr/lib/python2.7/site-packages/netaddr/ip/__init__.pyR!tscCs2|jjt|j}|jj|jj|fS(sY :return: A key tuple used to compare and sort this `IPRange` correctly. (RR\RRR3RR(Rtskey((s7/usr/lib/python2.7/site-packages/netaddr/ip/__init__.pyR"zscCst|j|jS(sx The list of CIDR addresses found within the lower and upper bound addresses of this `IPRange`. (tiprange_to_cidrsRR(R((s7/usr/lib/python2.7/site-packages/netaddr/ip/__init__.pytcidrsscCsd|j|jfS(s<:return: this `IPRange` in a common representational format.s%s-%s(RR(R((s7/usr/lib/python2.7/site-packages/netaddr/ip/__init__.pyRscCsd|jj|j|jfS(s8:return: Python statement to create an equivalent objects%s('%s', '%s')(RQRHRR(R((s7/usr/lib/python2.7/site-packages/netaddr/ip/__init__.pyRs (s_starts_end(RHRIRJRKRRWRZRRLRRR!R"RRR(((s7/usr/lib/python2.7/site-packages/netaddr/ip/__init__.pyR%s       cgs1x*t|D]}x|D] }|VqWq WdS(s :param args: A list of IP addresses and subnets passed in as arguments. :return: A generator that flattens out IP subnets, yielding unique individual IP addresses (no duplicates). N(t cidr_merge(targsR<R|((s7/usr/lib/python2.7/site-packages/netaddr/ip/__init__.pytiter_unique_ipss cCsd}t|r4d|ks-|dkr4|Sny$t|}d|||fSWnHtk rd|kr|jdd\}}y9dt|kodknstd |nWqtk r|SXn |}d}|jd }t|d kr|Sx+td t|D]}|jd q%W|dkrty||d}Wqttk rp|SXnd d j||fSt t fk r|SXdS(s A function that converts abbreviated IPv4 CIDRs to their more verbose equivalent. :param abbrev_cidr: an abbreviated CIDR. Uses the old-style classful IP address rules to decide on a default subnet prefix if one is not explicitly provided. Only supports IPv4 addresses. Examples :: 10 - 10.0.0.0/8 10/16 - 10.0.0.0/16 128 - 128.0.0.0/16 128/8 - 128.0.0.0/8 192.168 - 192.168.0.0/16 :return: A verbose CIDR from an abbreviated CIDR or old-style classful network address. The original value if it was not recognised as a supported abbreviation. cSst|}d|ko#dkns;td|nd|koRdknr[dSd|kordknr{dSd |kod knrd Sd |kod knrdSdS(NiisInvalid octet: %r!iiiiiiiiiiii (RRRc(toctet((s7/usr/lib/python2.7/site-packages/netaddr/ip/__init__.pytclassful_prefixs t:ts %s.0.0.0/%sRNiii s.prefixlen in address %r out of range for IPv4!t.iRms%s/%sN( RRRRPRRRtrangeRtjoinRRc(t abbrev_cidrRRt part_addrtprefixttokens((s7/usr/lib/python2.7/site-packages/netaddr/ip/__init__.pyRs>     "   c Cst|dstdng}x<|D]4}t|}|j|j|j|j|fq+W|jd}x|t|kr+||d||ddkr||dd||ddkr||d||ddt ||dd||df||d<||=qv|d7}qvWg}x|D]x}t|dkre|j|dq9|d}t |dd|}t |dd|} |j t || q9W|S( s A function that accepts an iterable sequence of IP addresses and subnets merging them into the smallest possible list of CIDRs. It merges adjacent subnets where possible, those contained within others and also removes any duplicates. :param ip_addrs: an iterable sequence of IP addresses and subnets. :return: a summarized list of `IPNetwork` objects. Rs#A sequence or iterator is expected!iiiiiR3( RRPRRR3RRtsortRtmaxRMtextendR( tip_addrstrangesR|R<Rtmergedt range_tupleR3t range_startt range_stop((s7/usr/lib/python2.7/site-packages/netaddr/ip/__init__.pyRs,  & DH   cCs t||\}}}||S(s Removes an exclude IP address or subnet from target IP subnet. :param target: the target IP address or subnet to be divided up. :param exclude: the IP address or subnet to be removed from target. :return: list of `IPNetwork` objects remaining after exclusion. (tcidr_partition(ttargettexcludetleftt_tright((s7/usr/lib/python2.7/site-packages/netaddr/ip/__init__.pyt cidr_exclude s c Cst|}t|}|j|jkr=gg|jgfS|j|jkrb|jgggfS|j|jkrg|ggfSg}g}|jd}|jj}|j}|j}|}|d||} x|j|krv|j| kr|jt||fd|| } n%|jt| |fd||} |d7}||kr[Pn| }| d||} qW||g|dddfS(sc Partitions a target IP subnet on an exclude IP address. :param target: the target IP address or subnet to be divided up. :param exclude: the IP address or subnet to partition on :return: list of `IPNetwork` objects before, the partition and after, sorted. Adding the three lists returns the equivalent of the original subnet. iiR3Ni( RRRR<RRR\R3R( RRRRt new_prefixlenttarget_module_widtht target_firstR3ti_lowerti_uppertmatched((s7/usr/lib/python2.7/site-packages/netaddr/ip/__init__.pyR.s8         c Cstg|D]}t|^q }t|dksFtdn|d}|d}|j|jkr{tdn|j}|j}|j}|j j }x9|dkr||kr|d8}|d||> M}qWt||fd|jS(sO Function that accepts a sequence of IP addresses and subnets returning a single `IPNetwork` subnet that is large enough to span the lower and upper bound IP addresses with a possible overlap on either end. :param ip_addrs: sequence of IP addresses and subnets. :return: a single spanning `IPNetwork` subnet. is-IP sequence must contain at least 2 elements!iis.IP sequence cannot contain both IPv4 and IPv6!R3( tsortedRRRPR3RRRRRR\( RR|t sorted_ipst lowest_ipt highest_iptipnumRt lowest_ipnumR\((s7/usr/lib/python2.7/site-packages/netaddr/ip/__init__.pyt spanning_cidrjs "       iccst|}t|}|j|jkr9tdn|j}t|}|dkritdnt|}t|}t}|dkrt}n||}xKtr||7}|r||ksPqn||ksPnt||VqWdS(s A generator that produces IPAddress objects between an arbitrary start and stop IP address with intervals of step between them. Sequences produce are inclusive of boundary IPs. :param start: start IP address. :param end: end IP address. :param step: (optional) size of step between IP addresses. Default: 1 :return: an iterator of one or more `IPAddress` objects. s(start and stop IP versions do not match!isstep argument cannot be zeroN(RMR3RRRRPR;R8(RRRR3Rt negative_stepR((s7/usr/lib/python2.7/site-packages/netaddr/ip/__init__.pyRs,              cCsg}t|}t|}|j|jg}t||g}|jj}|j|dkrt|dd|fd|j}t||d}|j}n|j|dkrt|dd|fd|j}|t||d7}n |j ||S(s` A function that accepts an arbitrary start and end IP address or subnet and returns a list of CIDR subnets that fit exactly between the boundaries of the two with no overlap. :param start: the start IP address or subnet. :param end: the end IP address or subnet. :return: a list of one or more IP addresses and subnets. iiR3i( RRRRRR\R3RtpopR(RRt cidr_listtipranget cidr_spanR\R((s7/usr/lib/python2.7/site-packages/netaddr/ip/__init__.pyRs    ## cCsd}t|ds(td|nt|}xatg|D]}t|^qAD]:}||kru|}qZ|dk rZ|j|krZPqZqZW|S(sb Matches an IP address or subnet against a given sequence of IP addresses and subnets. :param ip: a single IP address or subnet. :param cidrs: a sequence of IP addresses and/or subnets. :return: the smallest (most specific) matching IPAddress or IPNetwork object from the provided sequence, None if there was no match. Rs,IP address/subnet sequence expected, not %r!N(RRRRMRRR(R|RtmatchR<((s7/usr/lib/python2.7/site-packages/netaddr/ip/__init__.pytsmallest_matching_cidrs   ,  cCs~d}t|ds(td|nt|}xCtg|D]}t|^qAD]}||krZ|}PqZqZW|S(sb Matches an IP address or subnet against a given sequence of IP addresses and subnets. :param ip: a single IP address or subnet. :param cidrs: a sequence of IP addresses and/or subnets. :return: the largest (least specific) matching IPAddress or IPNetwork object from the provided sequence, None if there was no match. Rs,IP address/subnet sequence expected, not %r!N(RRRRMRR(R|RRR<((s7/usr/lib/python2.7/site-packages/netaddr/ip/__init__.pytlargest_matching_cidrs   , cCsg}t|ds(td|nt|}xftg|D]}t|^qAD]?}||kr||j|qZ|rZ|j|dkrZPqZqZW|S(sM Matches an IP address or subnet against a given sequence of IP addresses and subnets. :param ip: a single IP address. :param cidrs: a sequence of IP addresses and/or subnets. :return: all matching IPAddress and/or IPNetwork objects from the provided sequence, an empty list if there was no match. Rs,IP address/subnet sequence expected, not %r!i(RRRMRRRR(R|RtmatchesR<((s7/usr/lib/python2.7/site-packages/netaddr/ip/__init__.pytall_matching_cidrss   , s 127.0.0.0/8s 10.0.0.0/8s 172.16.0.0/12s 192.0.2.0/24s192.168.0.0/16s 239.0.0.0s239.255.255.255s169.254.0.0/16s 224.0.0.0/4s192.88.99.0/24s 192.0.0.0/24s 240.0.0.0/4s 234.0.0.0s238.255.255.255s 225.0.0.0s231.255.255.255s::1sfc00::/7s fec0::/10s fe80::/10sff00::/8s ff00::/12s::/8s0100::/8s0200::/7s0400::/6s0800::/5s1000::/4s4000::/3s6000::/3s8000::/3sA000::/3sC000::/3sE000::/4sF000::/5sF800::/6sFE00::/9(7RJtsyst_syst netaddr.coreRRRRRRRRRR tnetaddr.strategyR R/R R1tnetaddr.compatR R RRRtobjectRRMRR;RRRRRRRRRRRRRR R4R7R>R0t IPV4_6TO4R@R5R9R?R2RA(((s7/usr/lib/python2.7/site-packages/netaddr/ip/__init__.pytsb F(dDm T .  < " / $