def set(self, ip, netmask=None):
if isinstance(ip, str) and netmask is None:<EOL><INDENT>ipnm = ip.split('<STR_LIT:/>')<EOL>if len(ipnm) != <NUM_LIT:2>:<EOL><INDENT>raise ValueError('<STR_LIT>' % ip)<EOL><DEDENT>ip = ipnm[<NUM_LIT:0>]<EOL>netmask = ipnm[<NUM_LIT:1>]<EOL><DEDENT>if isinstance(ip, IPv4Address):<EOL><INDENT>self._ip = ip<EOL><DEDENT>else:<EOL><INDENT>self._ip = IPv4Address(ip)<EOL><DEDENT>if isinstance(netmask, IPv4NetMask):<EOL><INDENT>self._nm = netmask<EOL><DEDENT>else:<EOL><INDENT>self._nm = IPv4NetMask(netmask)<EOL><DEDENT>ipl = int(self._ip)<EOL>nml = int(self._nm)<EOL>base_add = ipl & nml<EOL>self._ip_num = <NUM_LIT> - <NUM_LIT:1> - nml<EOL>if self._ip_num in (-<NUM_LIT:1>, <NUM_LIT:0>):<EOL><INDENT>if self._ip_num == -<NUM_LIT:1>:<EOL><INDENT>self._ip_num = <NUM_LIT:1><EOL><DEDENT>else:<EOL><INDENT>self._ip_num = <NUM_LIT:2><EOL><DEDENT>self._net_ip = None<EOL>self._bc_ip = None<EOL>self._first_ip_dec = base_add<EOL>self._first_ip = IPv4Address(self._first_ip_dec, notation=IP_DEC)<EOL>if self._ip_num == <NUM_LIT:1>:<EOL><INDENT>last_ip_dec = self._first_ip_dec<EOL><DEDENT>else:<EOL><INDENT>last_ip_dec = self._first_ip_dec + <NUM_LIT:1><EOL><DEDENT>self._last_ip = IPv4Address(last_ip_dec, notation=IP_DEC)<EOL>return<EOL><DEDENT>self._net_ip = IPv4Address(base_add, notation=IP_DEC)<EOL>self._bc_ip = IPv4Address(base_add + self._ip_num + <NUM_LIT:1>, notation=IP_DEC)<EOL>self._first_ip_dec = base_add + <NUM_LIT:1><EOL>self._first_ip = IPv4Address(self._first_ip_dec, notation=IP_DEC)<EOL>self._last_ip = IPv4Address(base_add + self._ip_num, notation=IP_DEC)<EOL>
Set the IP address and the netmask.