def _get_afi(self, ip):
parts = unicode(ip).split("<STR_LIT:/>")<EOL>if len(parts) == <NUM_LIT:1>:<EOL><INDENT>if self._is_ipv4(ip):<EOL><INDENT>return <NUM_LIT:4><EOL><DEDENT>elif self._is_ipv6(ip):<EOL><INDENT>return <NUM_LIT:6><EOL><DEDENT>else:<EOL><INDENT>return None<EOL><DEDENT><DEDENT>elif len(parts) == <NUM_LIT:2>:<EOL><INDENT>try:<EOL><INDENT>pl = int(parts[<NUM_LIT:1>])<EOL><DEDENT>except ValueError:<EOL><INDENT>return None<EOL><DEDENT>if self._is_ipv4(parts[<NUM_LIT:0>]):<EOL><INDENT>if pl >= <NUM_LIT:0> and pl <= <NUM_LIT:32>:<EOL><INDENT>return <NUM_LIT:4><EOL><DEDENT>return None<EOL><DEDENT>elif self._is_ipv6(parts[<NUM_LIT:0>]):<EOL><INDENT>if pl >= <NUM_LIT:0> and pl <= <NUM_LIT>:<EOL><INDENT>return <NUM_LIT:6><EOL><DEDENT>return None<EOL><DEDENT>else:<EOL><INDENT>return None<EOL><DEDENT><DEDENT>else:<EOL><INDENT>return None<EOL><DEDENT>
Return address-family (4 or 6) for IP or None if invalid address