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


Python IPy.parseAddress方法代码示例

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


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

示例1: mod_change_cache

# 需要导入模块: import IPy [as 别名]
# 或者: from IPy import parseAddress [as 别名]
def mod_change_cache(zona=None, rr=None, rtype=None, ttl=1800, data=None, action=None, username=None, del_id=None, operation=None):
    """Modify the publish queue"""
    zone_id = zones.select().where(zones.zone == zona).get()
    if rtype == "A" or rtype == "NS":
        try:
            IPy.parseAddress(data)
        except ValueError:
            return False

    if operation == "add_unpub":
        for item in [zona, rr, rtype, ttl, data, action, operation]:
            if item is None:
                return False

        if change_cache.select().where(change_cache.rr == rr,
                                       change_cache.zone_id == zone_id,
                                       change_cache.type == rtype,
                                       change_cache.data == data,
                                       change_cache.action == "add").count():
                return True
        change_cache.create(username=username,
                            rr=rr,
                            zone_id=zone_id,
                            type=rtype,
                            ttl=ttl,
                            data=data,
                            action=action)
        return True

    elif operation == "del_unpub":
        delete_query = change_cache.delete().where((change_cache.id == del_id) & (change_cache.zone_id == zone_id))
        delete_query.execute()
        return True
开发者ID:the-elven-archer,项目名称:bind_manager,代码行数:35,代码来源:main.py

示例2: multi_ipcheck

# 需要导入模块: import IPy [as 别名]
# 或者: from IPy import parseAddress [as 别名]
def multi_ipcheck(form, field):
    error = []
    for x in field.data.split():
        try:
            IPy.parseAddress(x)
        except ValueError:
            error.append( x )

    if error:
        raise ValidationError( _('Error IP: %s') % error )
开发者ID:alayasix,项目名称:LuoYunCloud,代码行数:12,代码来源:forms.py

示例3: testRandomValuesv6

# 需要导入模块: import IPy [as 别名]
# 或者: from IPy import parseAddress [as 别名]
 def testRandomValuesv6(self):
     for i in range(testloops):
         question = ((random.randrange(0x7fffffff) + random.randrange(0x7fffffff)) +
                     ((random.randrange(0x7fffffff) + random.randrange(0x7fffffff)) << 32) +
                     ((random.randrange(0x7fffffff) + random.randrange(0x7fffffff)) << 64) +
                     ((random.randrange(0x7fffffff) + random.randrange(0x7fffffff)) << 96))
         self.assertEqual(IPy.parseAddress(IPy.intToIp(question, 6)), (question, 6), hex(question))
开发者ID:Guojian,项目名称:python-ipy,代码行数:9,代码来源:test_IPy.py

示例4: check_ip_address

# 需要导入模块: import IPy [as 别名]
# 或者: from IPy import parseAddress [as 别名]
def check_ip_address(address, version=None):
    try:
        _ip, ver = IPy.parseAddress(address)
    except ValueError:
        return False
    if version and version == ver:
        return True
开发者ID:uofis,项目名称:qubes-installer-qubes-os,代码行数:9,代码来源:network.py

示例5: ip_version_validator

# 需要导入模块: import IPy [as 别名]
# 或者: from IPy import parseAddress [as 别名]
def ip_version_validator(value, version, message):
	try:
		ip, v = IPy.parseAddress(value)
	except ValueError:
		raise forms.ValidationError(message)
	if v != version:
		raise forms.ValidationError(message)
开发者ID:wiedi,项目名称:django-netmgt,代码行数:9,代码来源:forms.py

示例6: query

# 需要导入模块: import IPy [as 别名]
# 或者: from IPy import parseAddress [as 别名]
 def query(self, sql):
     print "executing sql : " + sql
     self.cur.execute(sql)
     alldata = self.cur.fetchall()
     if alldata:
         for data in alldata:
             eid = IPy.parseAddress(data[0])
             #print eid
             print data[0], data[1]
     return alldata
开发者ID:zhenshengcai,项目名称:xTRController,代码行数:12,代码来源:db_access.py

示例7: address_check

# 需要导入模块: import IPy [as 别名]
# 或者: from IPy import parseAddress [as 别名]
def address_check(address):
    '''
    Check if the IP address is valid.

    :param str address: IP address to check
    :return: tuple of (address, version), where address is cleaned up IP address
             and version is 4 for IPv4 and 6 for IPv6
    :rtype: tuple of (str, int)
    :raises: IPCheckFailed
    '''
    try:
        address_int, version = IPy.parseAddress(address)
    except ValueError:
        raise IPCheckFailed("Invalid IP address: %s" % address)
    address = IPy.intToIp(address_int, version)
    return (address, version)
开发者ID:balamurugana,项目名称:openlmi-scripts,代码行数:18,代码来源:util.py

示例8: ipcheck

# 需要导入模块: import IPy [as 别名]
# 或者: from IPy import parseAddress [as 别名]
def ipcheck(form, field):
    try:
        IPy.parseAddress(field.data)
    except ValueError, msg:
        # msg is "single byte must be 0 <= byte < 256"
        raise ValidationError(msg)
开发者ID:alayasix,项目名称:LuoYunCloud,代码行数:8,代码来源:forms.py

示例9: testVersionDistinction

# 需要导入模块: import IPy [as 别名]
# 或者: from IPy import parseAddress [as 别名]
 def testVersionDistinction(self):
     """problems destinguishing IPv4 and IPv6"""
     (result, version) = IPy.parseAddress("0xffffffff")
     self.assertEqual(version, 4)
     (result, version) = IPy.parseAddress("0x100000000")
     self.assertEqual(version, 6)
开发者ID:ingenarius,项目名称:ipall,代码行数:8,代码来源:test_IPy.py

示例10: testKnownValues

# 需要导入模块: import IPy [as 别名]
# 或者: from IPy import parseAddress [as 别名]
 def testKnownValues(self):
     """parsing of known values should give known results"""
     for x in self.okValues:
         (question, answer) = x
         (result, version) = IPy.parseAddress(question)
         self.assertEqual(answer, result, "%r, %r, %r" % (question, answer, result))
开发者ID:ingenarius,项目名称:ipall,代码行数:8,代码来源:test_IPy.py

示例11: testRandomValuesv4

# 需要导入模块: import IPy [as 别名]
# 或者: from IPy import parseAddress [as 别名]
 def testRandomValuesv4(self):
     for i in range(testloops):
         question = long(random.randrange(0x7FFFFFFF)) + long(random.randrange(0x7FFFFFFF))
         self.assertEqual(IPy.parseAddress(IPy.intToIp(question, 4)), (question, 4), hex(question))
开发者ID:ingenarius,项目名称:ipall,代码行数:6,代码来源:test_IPy.py

示例12: parseIPAddress

# 需要导入模块: import IPy [as 别名]
# 或者: from IPy import parseAddress [as 别名]
def parseIPAddress(ipstr, return_ipv4=True):
    """
    pass an string or binary IP and return IPV4
    """
    newip=[]
    isBin=False

    if ipstr == "::1":
        # localhost in IPV6
        return "127.0.0.1"

    # GDM when change username use a $DISPLAY like this "::12"
    if re.match("::([0-9]{1,9})$", ipstr):
        return ""

    # XEPHYR NAME ':20.0'
    if re.match(":([0-9]{1,9}|[0-9]{1,9}.[0-9]{1,9})$", ipstr):
        return ""

    # match x.x.x.x:0 or x.x.x.x:0.0
    if re.match(".*:([0-9]{1,9}|[0-9{1-9}].[0-9{1-9}])$", ipstr):
        #print_debug("delete display from IP\n\n")
        ipstr=ipstr.rsplit(":", 1)[0]

    # match "localhost:10"
    if re.match("[a-zA-Z].*:([0-9]{1,9})", ipstr):
        ipstr=ipstr.rsplit(":", 1)[0]
        return ipstr
    
    # match "127.0.0.1:10.0"
    if re.match(".*:([0-9{1-9}][0-9{1-9}].[0-9{1-9}])$", ipstr):
        ipstr=ipstr.rsplit(":", 1)[0]
        return ipstr

    # hostname must start with letter and contain letters numbers and '-' or '.'
    if re.match("^[a-zA-Z][a-zA-Z0-9.-]+$", ipstr):
        # ipstr is a hostname
        return ipstr

    for it in ipstr:
        eol=is_bin(binascii.hexlify(it))
        if eol:
            isBin=True
        #print_debug("%s => %s string=%s"%(it, binascii.hexlify(it), eol) )
        newip.append(binascii.hexlify(it))
    
    if ipstr == '':
        return ''
    
    if isBin:
        try:
            ip=ipaddr.IPAddress(IPy.parseAddress("0x" + "".join(newip) )[0])
        except:
            return ipstr
    else:
        try:
            ip=ipaddr.IPAddress(ipstr)
        #except Exception:
        except Exception, err:
            print_debug("      parseIPAddress() Exception, error=%s"%err)
            return ipstr
开发者ID:mariodebian,项目名称:tcosmonitor,代码行数:63,代码来源:shared.py

示例13: testRandomValuesv6

# 需要导入模块: import IPy [as 别名]
# 或者: from IPy import parseAddress [as 别名]
 def testRandomValuesv6(self):
     question = random.randrange(0xffffffffffffffffffffffffffffffff)
     self.assertEqual(IPy.parseAddress(IPy.intToIp(question, 6)), (question, 6), hex(question))
开发者ID:2089764,项目名称:python-ipy,代码行数:5,代码来源:test_fuzz.py

示例14: compare_address

# 需要导入模块: import IPy [as 别名]
# 或者: from IPy import parseAddress [as 别名]
def compare_address(address1, address2):
    address_int1, version1 = IPy.parseAddress(address1)
    address_int2, version2 = IPy.parseAddress(address2)
    if version1 != version2:
        return False
    return address_int1 == address_int2
开发者ID:balamurugana,项目名称:openlmi-scripts,代码行数:8,代码来源:util.py


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