Ñò C…#Wc@s,dZddkZdefd„ƒYZdS(s! Class representing IP Addresses iÿÿÿÿNt IPAddresscBs­eZdZdZdZd d d„Zd„Zed„ƒZ e i d„ƒZ ed„ƒZ e i d„ƒZ e e d „ƒZe d „ƒZd „Ze d „ƒZRS(s¤Simple class to represent IP addresses This implementation represents purely the IP. Netmask, if needed, should be represented by a second IPAddress. s0.0.0.0sNo leading zeroscCs(d|_d|_||_||_dS(N(tNonet_addresst_netmasktaddresstnetmask(tselfRR((s ../ip_util.pyt__init__.s   cCs|iS(N(R(R((s ../ip_util.pyt__str__4scCsŠg}|idjo ti}n7x$|iD]}|it|ƒƒq-Wdi|ƒ}|iodt|iƒƒ}||S|SdS(s#Returns this IP address as a stringt.t/N( RRRtDEFAULTtappendtstrtjoinRtnetmask_prefix(RtsegmentsRtsegmentR((s ../ip_util.pyR7s    cCs-|dj oti|ƒ}n||_dS(sSets the addressN(RRtconvert_addressR(RR((s ../ip_util.pyRGs cCs|iS(N(R(R((s ../ip_util.pyRNscCs?|dj o%t|ƒ}ti|dtƒ}n||_dS(Nt check_netmask(RR RRtTrueR(Rtnew_mask((s ../ip_util.pyRRs  cCsvti|ƒ}t|ƒdjotdƒ‚n|o9ti|ƒ}d|idƒjotdƒ‚qrn|S(s Convert a string into an array of ints. Also serves as a validation function - strings not of the correct form will raise a ValueError is Bad lengtht1sNot a valid netmask(Rtincremental_checktlent ValueErrortas_binary_stringtlstrip(RRRtbin_rep((s ../ip_util.pyRZscCs1dig}|D]}|di|ƒq~ƒS(s¾Convert a set of 4 octets into its binary string representation For example, 255.255.255.0 becomes: 11111111 11111111 11111111 00000000 (without the spaces) ts{0:08b}(Rtformat(Rt_[1]tx((s ../ip_util.pyRjscCsti|iƒ}|idƒS(sÂConvert a long form netmask into a short form (CIDR). e.g. 255.255.255.0 -> /24 The returned value is undefined for IPAddress's not representing valid netmasks. R(RRRtcount(Rt binary_rep((s ../ip_util.pyRtscCsJ|pgS|idƒotdƒ‚n|idƒotdƒ‚n|idƒ}g}t|ƒdjotdƒ‚nx¿|D]·}|pq‹nt|ƒdjo$|dd jottiƒ‚ntid |ƒdjotd ƒ‚nt |ƒ}|djp |d jotd ƒ‚q‹|i |ƒq‹W|S(sÚIncrementally check an IP Address. Useful for checking a partial address, e.g., one that is partly typed into the UI Returns a list of valid segments parsed Raises ValueError if invalid R s*An IP address may not begin with a period.s..s%Periods must be separated by numbers.isToo many octetsiit0s^[0-9]*$s)Only numbers and '.' (period) are allowediÿs"Values should be between 0 and 255N( t startswithRtendswithtsplitRRtMSG_NO_LEADING_ZEROStretsearchRtintR (RtipRRtint_seg((s ../ip_util.pyR~s.$ N(t__name__t __module__t__doc__R R'RRRtpropertyRtsetterRt staticmethodtFalseRRRR(((s ../ip_util.pyR#s  (R/R(tobjectR(((s ../ip_util.pyts