ó u©¿Uc@s dZdefd„ƒYZdS(s! Class representing IP Addresses t IPAddresscBs§eZdZdZd d d„Zd„Zd„Zd„Ze eeƒZ e d„ƒZ e j d„ƒZ e ed„ƒ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.0cCs(d|_d|_||_||_dS(N(tNonet_addresst_netmasktaddresstnetmask(tselfRR((s ip_address.pyt__init__(s   cCs |jƒS(N(t get_address(R((s ip_address.pyt__str__/scCs†g}|jdkr!tj}n6x$|jD]}|jt|ƒƒq+Wdj|ƒ}|jr~dt|jƒƒ}||S|SdS(s#Returns this IP address as a stringt.t/N( RRRtDEFAULTtappendtstrtjoinRtshorthand_netmask(RtsegmentsRtsegmentR((s ip_address.pyR2s  cCs+|dk rtj|ƒ}n||_dS(sSets this IPAddress' addressN(RRtconvert_addressR(RR((s ip_address.pyt set_addressAs cCs|jS(s Get netmask(R(R((s ip_address.pyRIscCs=|dk r0t|ƒ}tj|dtƒ}n||_dS(s Set netmaskt check_netmaskN(RRRRtTrueR(Rtnew_mask((s ip_address.pyRNs  cCsptj|ƒ}t|ƒdkr0tdƒ‚n|rltj|ƒ}d|jdƒkrltdƒ‚qln|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_address.pyRWscCs*djg|D]}t|ƒd^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) ti(Rtbin(Rtx((s ip_address.pyRgscCstj|jƒ}|jdƒ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_address.pyRqscCs—|jdƒ}g}t|ƒdkr6tdƒ‚nxZ|D]R}|sOq=nt|ƒ}|dkss|dkr‚tdƒ‚q=|j|ƒ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 R isToo many octetsiiÿs"Values should be between 0 and 255(tsplitRRtintR (RtipRRtint_seg((s ip_address.pyR{s  N(t__name__t __module__t__doc__R RRR RRtpropertyRRtsettert staticmethodtFalseRRRR(((s ip_address.pyRs     N(R*tobjectR(((s ip_address.pyts