<s> import re <EOL> def int_to_dotted_ip ( intip ) : <EOL> octet = '<STR_LIT>' <EOL> for exp in [ <NUM_LIT:3> , <NUM_LIT:2> , <NUM_LIT:1> , <NUM_LIT:0> ] : <EOL> octet = octet + str ( intip / ( <NUM_LIT> ** exp ) ) + "<STR_LIT:.>" <EOL> intip = intip % ( <NUM_LIT> ** exp ) <EOL> return ( octet . rstrip ( '<STR_LIT:.>' ) ) <EOL> def dotted_ip_to_int ( dotted_ip ) : <EOL> exp = <NUM_LIT:3> <EOL> intip = <NUM_LIT:0> <EOL> for quad in dotted_ip . split ( '<STR_LIT:.>' ) : <EOL> intip = intip + ( int ( quad ) * ( <NUM_LIT> ** exp ) ) <EOL> exp = exp - <NUM_LIT:1> <EOL> return ( intip ) <EOL> def ip_range_to_string ( intip1 , intip2 ) : <EOL> frm = int_to_dotted_ip ( intip1 ) + "<STR_LIT:->" <EOL> total = frm + int_to_dotted_ip ( intip2 ) <EOL> return total <EOL> def mac_to_int ( mac ) : <EOL> assert ( re . match ( "<STR_LIT>" , mac ) ) <EOL> parts = mac . split ( "<STR_LIT::>" ) <EOL> return int ( "<STR_LIT>" . join ( parts ) , base = <NUM_LIT:16> ) <EOL> def int_to_mac ( mac ) : <EOL> if type ( mac ) == str and "<STR_LIT::>" in str : <EOL> return mac <EOL> s = "<STR_LIT>" % long ( mac ) <EOL> m = re . findall ( "<STR_LIT>" , s ) <EOL> return "<STR_LIT::>" . join ( m ) <EOL> def dpid_to_long ( dpid ) : <EOL> assert ( re . match ( "<STR_LIT>" , dpid ) ) <EOL> parts = dpid . split ( "<STR_LIT::>" ) <EOL> return int ( "<STR_LIT>" . join ( parts ) , base = <NUM_LIT:16> ) <EOL> def long_to_dpid ( l ) : <EOL> if type ( l ) == str and "<STR_LIT::>" in str : <EOL> return l <EOL> s = "<STR_LIT>" % long ( l ) <EOL> m = re . findall ( "<STR_LIT>" , s ) <EOL> return "<STR_LIT::>" . join ( m ) <EOL> def parseFVexception ( e , s = "<STR_LIT>" ) : <EOL> try : <EOL> r = re . findall ( "<STR_LIT>" , str ( e ) ) <EOL> except Exception , a : <EOL> return "<STR_LIT>" + s + str ( e ) + "<STR_LIT>" <EOL> if r : <EOL> return "<STR_LIT>" + s + r [ <NUM_LIT:0> ] . split ( "<STR_LIT::>" ) [ - <NUM_LIT:1> ] + "<STR_LIT>" <EOL> else : <EOL> return "<STR_LIT>" + s + str ( e ) + "<STR_LIT>" </s>
