def _to_gpb_value(self, value): """Converts the value into the GPB representation according to format.""" if self.format.value_is_mac(): return Convert.bytes_to_mac_str(value) if self.format.value_is_ip_addr(): return Convert.bytes_to_ip_addr(value) return value
def test_bytes_convert(self): illegal_var = '01:02:03:192.168.0.1:0a:0b:' try: Convert.bytes_to_mac_str(illegal_var) except TypeError: pass else: self.fail('illegal mac been converted') try: Convert.bytes_to_ipv4_str(illegal_var) except TypeError: pass else: self.fail('illegal ipv4 been converted') try: Convert.bytes_to_ipv6_str(illegal_var) except TypeError: pass else: self.fail('illegal ipv6 been converted') try: Convert.bytes_to_ip_addr(illegal_var) except TypeError: pass else: self.fail('illegal ip been converted') # try: ret = Convert.mac_to_tuple_of_bytes('-1:-2:-3:-4:-5') # except ValueError: # pass # else: # self.fail('illegal mac been converted: %s' % ret) self.assertIsNone(ret, 'illegal mac been converted: %s' % ret) self.assertFalse(Convert.is_valid_ipv4_address('a.b.c.d'))