<s> """<STR_LIT>""" <EOL> import socket <EOL> import dns . ipv4 <EOL> import dns . ipv6 <EOL> AF_INET = socket . AF_INET <EOL> try : <EOL> AF_INET6 = socket . AF_INET6 <EOL> except AttributeError : <EOL> AF_INET6 = <NUM_LIT> <EOL> def inet_pton ( family , text ) : <EOL> """<STR_LIT>""" <EOL> if family == AF_INET : <EOL> return dns . ipv4 . inet_aton ( text ) <EOL> elif family == AF_INET6 : <EOL> return dns . ipv6 . inet_aton ( text ) <EOL> else : <EOL> raise NotImplementedError <EOL> def inet_ntop ( family , address ) : <EOL> """<STR_LIT>""" <EOL> if family == AF_INET : <EOL> return dns . ipv4 . inet_ntoa ( address ) <EOL> elif family == AF_INET6 : <EOL> return dns . ipv6 . inet_ntoa ( address ) <EOL> else : <EOL> raise NotImplementedError <EOL> def af_for_address ( text ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> junk = dns . ipv4 . inet_aton ( text ) <EOL> return AF_INET <EOL> except : <EOL> try : <EOL> junk = dns . ipv6 . inet_aton ( text ) <EOL> return AF_INET6 <EOL> except : <EOL> raise ValueError <EOL> def is_multicast ( text ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> first = ord ( dns . ipv4 . inet_aton ( text ) [ <NUM_LIT:0> ] ) <EOL> return ( first >= <NUM_LIT> and first <= <NUM_LIT> ) <EOL> except : <EOL> try : <EOL> first = ord ( dns . ipv6 . inet_aton ( text ) [ <NUM_LIT:0> ] ) <EOL> return ( first == <NUM_LIT:255> ) <EOL> except : <EOL> raise ValueError </s>
