當前位置: 首頁>>代碼示例>>Python>>正文


Python PersistentDict.iteritems方法代碼示例

本文整理匯總了Python中durus.persistent_dict.PersistentDict.iteritems方法的典型用法代碼示例。如果您正苦於以下問題:Python PersistentDict.iteritems方法的具體用法?Python PersistentDict.iteritems怎麽用?Python PersistentDict.iteritems使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在durus.persistent_dict.PersistentDict的用法示例。


在下文中一共展示了PersistentDict.iteritems方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_iter

# 需要導入模塊: from durus.persistent_dict import PersistentDict [as 別名]
# 或者: from durus.persistent_dict.PersistentDict import iteritems [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()))
開發者ID:ctismer,項目名稱:durus,代碼行數:9,代碼來源:test_persistent_dict.py

示例2: iter

# 需要導入模塊: from durus.persistent_dict import PersistentDict [as 別名]
# 或者: from durus.persistent_dict.PersistentDict import iteritems [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()))
開發者ID:cfobel,項目名稱:durus,代碼行數:6,代碼來源:utest_persistent_dict.py

示例3: IPAssignments

# 需要導入模塊: from durus.persistent_dict import PersistentDict [as 別名]
# 或者: from durus.persistent_dict.PersistentDict import iteritems [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"
#.........這裏部分代碼省略.........
開發者ID:pruan,項目名稱:TestDepot,代碼行數:103,代碼來源:netobjects.py


注:本文中的durus.persistent_dict.PersistentDict.iteritems方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。