当前位置: 首页>>代码示例>>Python>>正文


Python ipaddress._BaseAddress方法代码示例

本文整理汇总了Python中ipaddress._BaseAddress方法的典型用法代码示例。如果您正苦于以下问题:Python ipaddress._BaseAddress方法的具体用法?Python ipaddress._BaseAddress怎么用?Python ipaddress._BaseAddress使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ipaddress的用法示例。


在下文中一共展示了ipaddress._BaseAddress方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_get_my_ip

# 需要导入模块: import ipaddress [as 别名]
# 或者: from ipaddress import _BaseAddress [as 别名]
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) 
开发者ID:maxisoft,项目名称:Freenom-dns-updater,代码行数:22,代码来源:test_get_my_ip.py

示例2: _convert_obj_to_value

# 需要导入模块: import ipaddress [as 别名]
# 或者: from ipaddress import _BaseAddress [as 别名]
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 
开发者ID:CiscoTestAutomation,项目名称:genielibs,代码行数:10,代码来源:normalize.py

示例3: testMissingAddressVersion

# 需要导入模块: import ipaddress [as 别名]
# 或者: from ipaddress import _BaseAddress [as 别名]
def testMissingAddressVersion(self):
        class Broken(ipaddress._BaseAddress):
            pass
        broken = Broken('127.0.0.1')
        with self.assertRaisesRegex(NotImplementedError, "Broken.*version"):
            broken.version 
开发者ID:IronLanguages,项目名称:ironpython3,代码行数:8,代码来源:test_ipaddress.py

示例4: merge_all_keys

# 需要导入模块: import ipaddress [as 别名]
# 或者: from ipaddress import _BaseAddress [as 别名]
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 
开发者ID:CiscoTestAutomation,项目名称:genielibs,代码行数:57,代码来源:normalize.py


注:本文中的ipaddress._BaseAddress方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。