def convert_to_eaddr(val): if isinstance(val, ethernetaddr): return val if isinstance(val, array.array): val = val.tostring() if isinstance(val, str) and len(val) == ethernetaddr.LEN: return create_bin_eaddr(val) elif isinstance(val, str) or isinstance(val, int) or isinstance(val, long): return create_eaddr(val) return None
def convert_to_eaddr(val): if isinstance(val, ethernetaddr): return val if isinstance(val, array.array): val = val.tostring() if isinstance(val, str) and re.search("([0-9a-fA-F][0-9a-fA-F]:){6,6}", val+ ":") is None: if len(val) < ethernetaddr.LEN: return None return create_bin_eaddr(val) elif isinstance(val, str) or isinstance(val, int) or isinstance(val, long): return create_eaddr(val) return None
def __dladdr_check__(addr): if isinstance(addr, basestring) and len(addr) == ethernetaddr.LEN: addr = create_bin_eaddr(addr) elif isinstance(addr, basestring) or ((isinstance(addr, long) or isinstance(addr, int)) and addr >= 0): addr = create_eaddr(addr) elif not isinstance(addr, ethernetaddr): return None if addr == None: return None return addr.hb_long()
def convert_to_eaddr(val): if isinstance(val, ethernetaddr): return val if isinstance(val, array.array): val = val.tostring() if isinstance(val, str) and re.search("([0-9a-fA-F][0-9a-fA-F]:){6,6}", val + ":") is None: if len(val) < ethernetaddr.LEN: return None return create_bin_eaddr(val) elif isinstance(val, str) or isinstance(val, int) or isinstance(val, long): return create_eaddr(val) return None
def dladdr_check(addr, translate=False): # should check if defined constant here if isinstance(addr, unicode): addr = addr.encode('utf-8') if isinstance(addr, str) and not (':' in addr): if len(addr) != ethernetaddr.LEN: return defer.succeed(None) addr = create_bin_eaddr(addr) elif isinstance(addr, str) or ((isinstance(addr, long) or isinstance(addr, int)) and addr >= 0): addr = create_eaddr(addr) elif not isinstance(addr, ethernetaddr): return defer.succeed(None) if addr is None: return defer.succeed(None) if translate: return addr.nb_long() return defer.succeed(unicode(str(addr)))