<s> """<STR_LIT>""" <EOL> from netaddr . core import AddrFormatError <EOL> from netaddr . ip import IPAddress <EOL> from netaddr . compat import _zip <EOL> def chr_range ( low , high ) : <EOL> """<STR_LIT>""" <EOL> return [ chr ( i ) for i in range ( ord ( low ) , ord ( high ) + <NUM_LIT:1> ) ] <EOL> BASE_85 = ( <EOL> chr_range ( '<STR_LIT:0>' , '<STR_LIT>' ) + chr_range ( '<STR_LIT:A>' , '<STR_LIT>' ) + <EOL> chr_range ( '<STR_LIT:a>' , '<STR_LIT:z>' ) + <EOL> [ '<STR_LIT:!>' , '<STR_LIT:#>' , '<STR_LIT:$>' , '<STR_LIT:%>' , '<STR_LIT:&>' , '<STR_LIT:(>' , '<STR_LIT:)>' , '<STR_LIT:*>' , '<STR_LIT:+>' , '<STR_LIT:->' , '<STR_LIT:;>' , '<STR_LIT:<>' , '<STR_LIT:=>' , '<STR_LIT:>>' , <EOL> '<STR_LIT:?>' , '<STR_LIT:@>' , '<STR_LIT>' , '<STR_LIT:_>' , '<STR_LIT>' , '<STR_LIT:{>' , '<STR_LIT:|>' , '<STR_LIT:}>' , '<STR_LIT>' ] <EOL> ) <EOL> BASE_85_DICT = dict ( _zip ( BASE_85 , range ( <NUM_LIT:0> , <NUM_LIT> ) ) ) <EOL> def ipv6_to_base85 ( addr ) : <EOL> """<STR_LIT>""" <EOL> ip = IPAddress ( addr ) <EOL> int_val = int ( ip ) <EOL> remainder = [ ] <EOL> while int_val > <NUM_LIT:0> : <EOL> remainder . append ( int_val % <NUM_LIT> ) <EOL> int_val //= <NUM_LIT> <EOL> encoded = '<STR_LIT>' . join ( [ BASE_85 [ w ] for w in reversed ( remainder ) ] ) <EOL> leading_zeroes = ( <NUM_LIT:20> - len ( encoded ) ) * "<STR_LIT:0>" <EOL> return leading_zeroes + encoded <EOL> def base85_to_ipv6 ( addr ) : <EOL> """<STR_LIT>""" <EOL> tokens = list ( addr ) <EOL> if len ( tokens ) != <NUM_LIT:20> : <EOL> raise AddrFormatError ( '<STR_LIT>' % addr ) <EOL> result = <NUM_LIT:0> <EOL> for i , num in enumerate ( reversed ( tokens ) ) : <EOL> num = BASE_85_DICT [ num ] <EOL> result += ( num * <NUM_LIT> ** i ) <EOL> ip = IPAddress ( result , <NUM_LIT:6> ) <EOL> return str ( ip ) </s>
