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


Python Helper.isPositiveInt方法代码示例

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


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

示例1: parse_summary

# 需要导入模块: from Helper import Helper [as 别名]
# 或者: from Helper.Helper import isPositiveInt [as 别名]
 def parse_summary(ixp, inputfile, ipversion, ixpParam):
     """
     Function to parse a  BGP summary output file.
     It prints the ASN->Neighbor IP mapping in a file
     """
     ipToAsn = {}
     addrPos, asnPos, ipcountPos, rtrType = [int(ixpParam["summary"]["ip"]), int(ixpParam["summary"]["asn"]),
                                             int(ixpParam["summary"]["ipCount"]), ixpParam["type"]]
     with open(inputfile, 'rb') as f:
         for line in f:
             # split the line to white spaces
             lineTokens = line.strip().split()
             if len(lineTokens) <= ipcountPos: continue
             interfaces = re.findall(
                 r'(?:\s|^|\(|\[)(?:[\d]{1,3})\.(?:[\d]{1,3})\.(?:[\d]{1,3})\.(?:[\d]{1,3})(?:\s|\)|$|\])', line)
             if len(lineTokens) > addrPos and len(interfaces) > 0:
                 # check if the string that is supposed to be in the position of the address is indeed a valid IP address
                 ip = lineTokens[addrPos]
                 ipType = Helper.getIPNetwork(ip)
                 if str(ipType) == str(ipversion) or (ipType > 0 and int(ipversion) == 10):
                     # check if the string in the position of the ASN is a valid number
                     asn = lineTokens[asnPos]
                     asn = asn.replace("AS", "")
                     if '.' in asn:
                         asn = Helper.convertToAsn32(asn)
                     if Helper.isPositiveInt(asn):
                         # check if the ASN is active and advertises prefixes
                         # often the number of advertised prefixes may be split in total received/best
                         # in this case we want the total which is the first of the two numbers
                         ipcount = lineTokens[ipcountPos]
                         try:
                             if rtrType == "bird":
                                 received = re.findall(r"[\w']+", ipcount)[0]
                             elif rtrType == "quagga":
                                 received = ipcount
                         except:
                             print ipcount
                         # if string represents a valid positive number add asn->ip mapping to the dictionary
                         if Helper.isPositiveInt(received):
                             if ip not in ipToAsn:
                                 ipToAsn[ip] = asn
     return ipToAsn
开发者ID:vgiotsas,项目名称:multilateral,代码行数:44,代码来源:BgpParser.py


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