本文整理汇总了Python中durus.persistent_dict.PersistentDict.iterkeys方法的典型用法代码示例。如果您正苦于以下问题:Python PersistentDict.iterkeys方法的具体用法?Python PersistentDict.iterkeys怎么用?Python PersistentDict.iterkeys使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类durus.persistent_dict.PersistentDict
的用法示例。
在下文中一共展示了PersistentDict.iterkeys方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_iter
# 需要导入模块: from durus.persistent_dict import PersistentDict [as 别名]
# 或者: from durus.persistent_dict.PersistentDict import iterkeys [as 别名]
def test_iter(self):
pd = PersistentDict((x, True) for x in range(10))
if hasattr({}, 'iteritems'):
assert list(pd.iteritems()) == list(zip(pd.iterkeys(), pd.itervalues()))
else:
assert list(pd.items()) == list(zip(pd.keys(), pd.values()))
assert list(pd.items()) == list(zip(pd.keys(), pd.values()))
示例2: iter
# 需要导入模块: from durus.persistent_dict import PersistentDict [as 别名]
# 或者: from durus.persistent_dict.PersistentDict import iterkeys [as 别名]
def iter(self):
pd = PersistentDict((x, True) for x in range(10))
assert list(pd.iteritems()) == list(zip(pd.iterkeys(), pd.itervalues()))
assert list(pd.items()) == list(zip(pd.keys(), pd.values()))
示例3: IPAssignments
# 需要导入模块: from durus.persistent_dict import PersistentDict [as 别名]
# 或者: from durus.persistent_dict.PersistentDict import iterkeys [as 别名]
class IPAssignments(OwnedPersistent):
def __init__(self, name, *args):
super(IPAssignments, self).__init__()
self.name = name
self._store = PersistentDict()
for arg in args:
self.add(arg)
def __contains__(self, address):
if isinstance(address, str):
address = ipv4.IPv4(address)
for ip in self._store.iterkeys():
if address == ip:
return True
return False
def __str__(self):
s = []
for address, disp in self._store.items():
s.append("%s is %s\n" % (address.cidr(), IF(disp, "used.", "free.")))
s.sort()
return "".join(s)
def __repr__(self):
return "%s(%r, ...)" % (self.__class__.__name__, self.name)
def __iter__(self):
return self._store.iteritems()
def get(self, ip):
if isinstance(ip, str):
ip = ipv4.IPv4(ip)
return ip, self._store.get(ip)
def add(self, arg):
if isinstance(arg, str):
arg = ipv4.IPv4(arg)
if isinstance(arg, ipv4.IPRange):
for ip in arg:
self._store[ip] = False
elif isinstance(arg, ipv4.IPv4):
for ip in arg[1:-1]:
self._store[ip] = False
else:
raise ValueError, "must be IP address or Range."
# IPv4 used as a VLSM range here
def add_net(self, ipnet):
if isinstance(ipnet, str):
ipnet = ipv4.IPv4(ipnet)
if isinstance(ipnet, ipv4.IPv4):
for ip in ipnet[1:-1]:
self._store[ip] = False
else:
raise ValueError, "must add IPv4 network"
add_network = add_net
def add_range(self, addr1, addr2):
rng = ipv4.IPRange(addr1, addr2)
for ip in rng:
self._store[ip] = False
def remove(self, arg):
if isinstance(arg, str):
arg = ipv4.IPv4(arg)
if isinstance(arg, ipv4.IPRange):
for ip in arg:
try:
del self._store[ip]
except KeyError:
pass
elif isinstance(arg, ipv4.IPv4):
for ip in arg[1:-1]:
try:
del self._store[ip]
except KeyError:
pass
else:
raise ValueError, "must be IP address or Range."
# removes the given range of IP. Useful for making "holes"
def remove_range(self, addr1, addr2):
rng = ipv4.IPRange(addr1, addr2)
for ip in rng:
try:
del self._store[ip]
except KeyError:
pass
def remove_net(self, ipnet):
if isinstance(ipnet, str):
ipnet = ipv4.IPv4(ipnet)
if isinstance(ipnet, ipv4.IPv4):
for ip in ipnet[1:-1]:
try:
del self._store[ip]
except KeyError:
pass
else:
raise ValueError, "must add IPv4 network"
#.........这里部分代码省略.........