<s> from django . core . exceptions import ValidationError <EOL> from mozdns . validation import validate_ip_type <EOL> import ipaddr <EOL> def ip_to_dns_form ( ip , uppercase = False ) : <EOL> """<STR_LIT>""" <EOL> if not isinstance ( ip , basestring ) : <EOL> raise ValidationError ( "<STR_LIT>" ) <EOL> if ip . find ( '<STR_LIT::>' ) > - <NUM_LIT:1> : <EOL> octets = nibbilize ( ip ) . split ( '<STR_LIT:.>' ) <EOL> name = '<STR_LIT>' <EOL> else : <EOL> octets = ip . split ( '<STR_LIT:.>' ) <EOL> name = '<STR_LIT>' <EOL> if uppercase : <EOL> name = name . uppercase <EOL> name = '<STR_LIT:.>' . join ( list ( reversed ( octets ) ) ) + name + "<STR_LIT:.>" <EOL> return name <EOL> def ip_to_domain_name ( ip , ip_type = '<STR_LIT:4>' , uppercase = False ) : <EOL> """<STR_LIT>""" <EOL> if not isinstance ( ip , basestring ) : <EOL> raise ValidationError ( "<STR_LIT>" ) <EOL> validate_ip_type ( ip_type ) <EOL> octets = ip . split ( '<STR_LIT:.>' ) <EOL> if ip_type == '<STR_LIT:4>' : <EOL> name = '<STR_LIT>' <EOL> if ip_type == '<STR_LIT>' : <EOL> name = '<STR_LIT>' <EOL> if uppercase : <EOL> name = name . uppercase <EOL> name = '<STR_LIT:.>' . join ( list ( reversed ( octets ) ) ) + name <EOL> return name <EOL> """<STR_LIT>""" <EOL> def nibbilize ( addr ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> ip_str = ipaddr . IPv6Address ( str ( addr ) ) . exploded <EOL> except ipaddr . AddressValueError : <EOL> raise ValidationError ( "<STR_LIT>" . format ( addr ) ) <EOL> return '<STR_LIT:.>' . join ( list ( ip_str . replace ( '<STR_LIT::>' , '<STR_LIT>' ) ) ) <EOL> def i64_to_i128 ( upper_int , lower_int ) : <EOL> return upper_int << <NUM_LIT:64> + lower_int <EOL> def i128_to_i64 ( bigint ) : <EOL> ip_upper = bigint >> <NUM_LIT:64> <EOL> ip_lower = bigint & ( <NUM_LIT:1> << <NUM_LIT:64> ) - <NUM_LIT:1> <EOL> return ip_upper , ip_lower </s>
