Python ipaddress._BaseAddress() Examples
The following are 5
code examples of ipaddress._BaseAddress().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
ipaddress
, or try the search function
.
Example #1
Source File: test_get_my_ip.py From Freenom-dns-updater with MIT License | 6 votes |
def test_get_my_ip(self): httpretty.register_uri(httpretty.GET, "http://test.com/", body=json.dumps({ "address": "fd2b:1c1b:3641:1cd8::", "proto": "ipv6"}), content_type='text/json') res = get_my_ip('http://test.com/') self.assertIsInstance(res, ipaddress._BaseAddress) self.assertEqual(ipaddress.ip_address(u"fd2b:1c1b:3641:1cd8::"), res) httpretty.register_uri(httpretty.GET, "http://test.com/", body=json.dumps({ "address": "49.20.57.31", "proto": "ipv4"}), content_type='text/json') res = get_my_ip('http://test.com/') self.assertIsInstance(res, ipaddress._BaseAddress) self.assertEqual(ipaddress.ip_address(u"49.20.57.31"), res)
Example #2
Source File: normalize.py From genielibs with Apache License 2.0 | 5 votes |
def _convert_obj_to_value(value): if isinstance(value, Neighbor): value = value.ip.compressed elif isinstance(value, Enum): value = value.value elif isinstance(value, _BaseAddress): value = value.compressed return value
Example #3
Source File: test_ipaddress.py From ironpython3 with Apache License 2.0 | 5 votes |
def testMissingAddressVersion(self): class Broken(ipaddress._BaseAddress): pass broken = Broken('127.0.0.1') with self.assertRaisesRegex(NotImplementedError, "Broken.*version"): broken.version
Example #4
Source File: test_get_my_ip.py From Freenom-dns-updater with MIT License | 5 votes |
def test_get_my_ip(self): res = get_my_ip() self.assertIsInstance(res, ipaddress._BaseAddress)
Example #5
Source File: normalize.py From genielibs with Apache License 2.0 | 4 votes |
def merge_all_keys(cls, temp_ret, temp_dict, ret_source): # Merge all the keys into a group keys that make sense # This code...is not optimal temp_ret = deepcopy(temp_ret) #temp_dict = [] # temp_ret = previous requirements found information skip = {} found = False for temp in temp_ret: temp_found = False temp_values = {} # Evaluate how many are needed here. for key, value in ret_source.items(): # Convert obj to string if isinstance(value, Neighbor): value = value.ip.compressed elif isinstance(value, Enum): value = value.value elif isinstance(value, _BaseAddress): value = value.compressed if key in temp: if temp[key] == value or (isinstance(value, Iterable) and temp[key] in value): if key in skip: del skip[key] continue # This mean this ret_source does not respect # an existing key, but it could respect from another # temp_ret. # So keep in memory # Dict so its faster skip[key] = False break # Key does not exists temp_values[key] = value continue else: # Good found a match temp_found = found = True if temp_values: if temp in temp_dict: temp_dict.remove(temp) temp.update(temp_values) if temp not in temp_dict and temp_found: # Temp was not found temp_dict.append(temp) # Make sure no value was still in skip. If so, do not add if not skip and not found and ret_source not in temp_dict: temp_dict.append(ret_source) return temp_dict