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


Python PersistentDict.values方法代码示例

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


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

示例1: test_iter

# 需要导入模块: from durus.persistent_dict import PersistentDict [as 别名]
# 或者: from durus.persistent_dict.PersistentDict import values [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: CFeeds

# 需要导入模块: from durus.persistent_dict import PersistentDict [as 别名]
# 或者: from durus.persistent_dict.PersistentDict import values [as 别名]
class CFeeds(Persistent):
    def __init__(self):
        self.data = PersistentDict() # {url feed: CFeed}
        
        
    def __getitem__(self, key):
        return self.data[key]

    def __setitem__(self, key, item):
        self.data[key] = item

    def __delitem__(self, key):
        self._p_note_change()
        del self.data[key]

    def get(self, key):
        return self.data.get(key)

    def keys(self):
        return self.data.keys()

    def values(self):
        return self.data.values()
开发者ID:BackupTheBerlios,项目名称:jfn-svn,代码行数:25,代码来源:feeds.py

示例3: iter

# 需要导入模块: from durus.persistent_dict import PersistentDict [as 别名]
# 或者: from durus.persistent_dict.PersistentDict import values [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

示例4: NetworkDevice

# 需要导入模块: from durus.persistent_dict import PersistentDict [as 别名]
# 或者: from durus.persistent_dict.PersistentDict import values [as 别名]

#.........这里部分代码省略.........
	def add_interface(self, devname, address=None, mask=None, hostname=None, linktype=BROADCAST):
		"""add_interface(devname, [address, [mask, [hostname, [linktype]]]])
Adds a new network interface to the device. Supply its interface name, and its
address.
		"""
		devname = self.INTERFACEMAP.get(devname, devname)
		if self._interfaces.has_key(devname):
			return self._interfaces[devname].update(address, mask, hostname, linktype)
		if not address:
			try:
				address=ipv4.IPv4(self.hostname)
			except:
				address = None
		if not hostname:
			if address:
				try:
					hostname = address.hostname
				except:
					hostname = "%s_%s" % (self.hostname, devname)
			else:
				hostname = "%s_%s" % (self.hostname, devname)
		intf = Interface(devname, address, mask, hostname, linktype)
		self._interfaces[devname] = intf
		intf.owner = self
		self._p_note_change()
		return intf

	def update_interface(self, devname, address=None, mask=None, hostname=None, linktype=BROADCAST):
		devname = self.INTERFACEMAP.get(devname, devname)
		return self._interfaces[devname].update(address, mask, hostname, linktype)

	def get_interface(self, devname):
		"""Return an Interface object from the index. The index value may be an integer or a name.  """
		devname = self.INTERFACEMAP.get(devname, devname)
		return self._interfaces[devname]

	def set_interface(self, intf):
		if isinstance(intf, Interface):
			self._interfaces[intf.device] = intf
		else:
			raise ValueError, "interfaces: value must be Interface object."

	def del_interface(self, devname):
		"""Delete an interface given the name, or index as an integer."""
		devname = self.INTERFACEMAP.get(devname, devname)
		intf = self._interfaces[devname]
		del self._interfaces[devname]
		intf.owner = None

	def get_interfaces(self):
		return self._interfaces.copy()

	def del_interfaces(self):
		self._interfaces.clear()

	interfaces = property(get_interfaces, None, del_interfaces, "device interfaces")

	# return a list of IPv4 addresses used by the data interfaces of this device.
	def _get_ipv4(self):
		rv = []
		for name in self.data_interfaces:
			intf = self._interfaces[name]
			rv.append(intf.address)
		return rv
	addresses = property(_get_ipv4)

	def get_address(self, ifname):
		return self._interfaces[ifname].address

	def reset(self):
		self._interfaces.clear()
		self.set_hostname("")
		self.disown()

	def connect(self, ifname, network):
		"""Connect this device to a network object (the supplied parameter)."""
		assert isinstance(network, Network), "network parameter must be a Network object."
		ifname = self.INTERFACEMAP.get(ifname, ifname)
		try:
			intf = self._interfaces[ifname]
		except KeyError:
			intf = self.add_interface(ifname)
		intf.connect(network)
	
	def disconnect(self, ifname):
		"""disconnect the named interface from its network."""
		ifname = self.INTERFACEMAP.get(ifname, ifname)
		intf = self._interfaces[ifname]
		intf.disconnect()

	def connections(self, network=None):
		"""Return a list of interfaces connected to the given network object,
		or all connections if no network provided."""
		rv = []
		for intf in self._interfaces.values():
			if network is None and intf.network is not None:
				rv.append(intf)
			elif intf.network is network:
				rv.append(intf)
		return rv
开发者ID:pruan,项目名称:TestDepot,代码行数:104,代码来源:netobjects.py

示例5: Network

# 需要导入模块: from durus.persistent_dict import PersistentDict [as 别名]
# 或者: from durus.persistent_dict.PersistentDict import values [as 别名]
class Network(OwnedPersistent):
	_netnode_template = """|  +---------------------------------------------+
|--| %-20.20s (%-20.20s) |
|  +---------------------------------------------+""" # don't touch this 
	def __init__(self, subnet=None, subnetname=None):
		super(Network, self).__init__()
		self.name = None
		self.mask = None
		self._subnets = PersistentList()
		self.nodes = PersistentDict() # actually, Interface objects
		self._gatways = PersistentList()
		if subnet:
			self.add_subnet(subnet, subnetname)

	def __str__(self):
		s = ["-"*70]
		sbl = []
		sn = []
		for subnet, name in self._subnets:
			sbl.append("%20s" % (subnet,))
			sn.append("%20s" % (name,))
		s.append(" | ".join(sbl))
		s.append(" | ".join(sn))
		s.append("-"*70)
		for node in self.nodes.values():
			s.append(self._netnode_template % (node.owner.name, node.owner.__class__.__name__))
		return "\n".join(s)

	def __repr__(self):
		try:
			addr, name = self._subnets[0]
			return "%s(%r, %r)" % (self.__class__.__name__, addr, name)
		except IndexError:
			return "%s()" % (self.__class__.__name__)

	def __getitem__(self, idx):
		return self._subnets[idx]

	def __iter__(self):
		return iter(self._subnets)

	def add_interface(self, interface):
		self.nodes[interface.hostname] = interface
		interface.network = self

	def del_interface(self, interface):
		del self.nodes[interface.hostname]
		interface.network = None

	def get_interfaces(self):
		return self.nodes.copy()

	def get_node(self, hostname):
		intf = self.nodes[str(hostname)]
		return intf.owner

	def add_node(self, netdev):
		for intf in netdev.interfaces.values():
			for subnet, name in self._subnets:
				if intf.address in subnet:
					self.nodes[intf.name] = intf
					intf.network = self
					return

	def add_subnet(self, addr, name=None):
		sn = ipv4.IPv4(addr)
		sn.host = 0
		name = name or sn.cidr() 
		if not self._subnets: # first subnet sets the name and mask
			self.name = name
			self.mask = sn.mask 
		self._subnets.append((sn, name))
		self._p_note_change()
		return sn
	
	def remove_subnet(self, name):
		for i, (sn, netname) in enumerate(self._subnets[:]):
			if netname == name:
				del self._subnets[i]

	def get_subnets(self):
		return list(self._subnets)
	subnets = property(get_subnets)

	def __contains__(self, address):
		if isinstance(address, str):
			address = ipv4.IPv4(address)
		for subnet, name in self._subnets:
			if address in subnet:
				return True
		return False
开发者ID:pruan,项目名称:TestDepot,代码行数:93,代码来源:netobjects.py


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