本文整理汇总了Python中java.util.HashSet.iterator方法的典型用法代码示例。如果您正苦于以下问题:Python HashSet.iterator方法的具体用法?Python HashSet.iterator怎么用?Python HashSet.iterator使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.HashSet
的用法示例。
在下文中一共展示了HashSet.iterator方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: getConnectionData
# 需要导入模块: from java.util import HashSet [as 别名]
# 或者: from java.util.HashSet import iterator [as 别名]
def getConnectionData(Framework, protocolType, acceptedProtocols):
ips = HashSet()
ports = HashSet()
sids = HashSet()
#fill IPs, ports and SIDs from DB
destIps = Framework.getTriggerCIDataAsList('application_ip')
destPort = Framework.getTriggerCIDataAsList('application_port')
destSids = Framework.getTriggerCIDataAsList('sid')
for i in range(0, len(destIps)):
#make sure to skip adding corrupted data to the list of connections - e.g. when SID contains whitespace characters
if protocolType.lower() in (DbTypes.MsSqlServer, DbTypes.MsSqlServerNtlm, DbTypes.Oracle, DbTypes.Db2) and re.search('\s', destSids[i]):
continue
#named MSSQL has SID: hostName\instanceName or clusterName\instanceName
sidName = destSids[i]
if sidName and sidName.find('\\') > 0 and protocolType.lower() in (DbTypes.MsSqlServer, DbTypes.MsSqlServerNtlm, DbTypes.MsSqlServerNtlmV2):
destSids[i] = sidName[sidName.find('\\')+1:]
add(ips, destIps[i])
add(ports, destPort[i])
add(sids, destSids[i].upper())
#fill IPs
destIps = Framework.getTriggerCIDataAsList('ip_address')
if destIps != None:
for i in range(0, len(destIps)):
add(ips, destIps[i])
#fill IPs and port from service address
destIps = Framework.getTriggerCIDataAsList('sa_ip')
destPort = Framework.getTriggerCIDataAsList('sa_port')
for i in range(0, len(destIps)):
add(ips, destIps[i])
add(ports, destPort[i])
#ensure that DBs with non-relevant SID will be present in the list
if not protocolType in (DbTypes.Oracle, DbTypes.Db2):
sids.add(None)
connectionData = []
for protocolId in acceptedProtocols:
logger.debug('Collecting data to connect with protocol %s' % protocolId)
ipsToConnect = []
portsToConnect = []
sidsToConnect = []
#only those IPs will be used which are in protocol range
ipIter = ips.iterator()
protocolObj = protocol.MANAGER_INSTANCE.getProtocolById(protocolId)
while ipIter.hasNext():
ip = ipIter.next()
if protocolObj.isInScope(ip):
ipsToConnect.append(ip)
if len(ipsToConnect) == 0:
logger.warn('No suitable IP address found for protocol range')
continue
#add protocol port if exists
protocolPort = Framework.getProtocolProperty(protocolId, CollectorsConstants.PROTOCOL_ATTRIBUTE_PORT, NA)
if protocolPort != NA:
portsToConnect.append(protocolPort)
else: #all collected ports will be used for connect
portIter = ports.iterator()
while portIter.hasNext():
portsToConnect.append(portIter.next())
if len(portsToConnect) == 0:
logger.warn('No port collected for protocol')
continue
#add protocol SID if exists, otherwise add all from triggered CI data
dbName = Framework.getProtocolProperty(protocolId, CollectorsConstants.SQL_PROTOCOL_ATTRIBUTE_DBSID, NA)
if dbName == NA:
dbName = Framework.getProtocolProperty(protocolId, CollectorsConstants.SQL_PROTOCOL_ATTRIBUTE_DBNAME, NA)
if dbName != NA:
sidsToConnect.append(dbName)
else:
sidIter = sids.iterator()
while sidIter.hasNext():
sidsToConnect.append(sidIter.next())
if len(sidsToConnect) == 0:
logger.warn('Database type %s requires instance name to connect' % protocolType)
continue
connectionDataItem = (protocolId, ipsToConnect, portsToConnect, sidsToConnect)
connectionData.append(connectionDataItem)
return connectionData