當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。