def dpid_to_str(dpid, alwaysLong=False):
 if ((type(dpid) is long) or (type(dpid) is int)):
  dpid = struct.pack('!Q', dpid)
 assert (len(dpid) == 8)
 r = '-'.join([('%02x' % (ord(x),)) for x in dpid[2:]])
 if (alwaysLong or (dpid[0:2] != ('\x00' * 2))):
  r += ('|' + str(struct.unpack('!H', dpid[0:2])[0]))
 return r

def dpid_to_str ( dpid , alwaysLong = False ) : if ( ( type ( dpid ) is long ) or ( type ( dpid ) is int ) ) : dpid = struct . pack ( '!Q' , dpid ) assert ( len ( dpid ) == 8 ) r = '-' . join ( [ ( '%02x' % ( ord ( x ) , ) ) for x in dpid [ 2 : ] ] ) if ( alwaysLong or ( dpid [ 0 : 2 ] != ( '\x00' * 2 ) ) ) : r += ( '|' + str ( struct . unpack ( '!H' , dpid [ 0 : 2 ] ) [ 0 ] ) ) return r
convert a dpid from a long into into the canonical string form .