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


Python PersistentDict.has_key方法代码示例

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


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

示例1: categoricalIndex

# 需要导入模块: from durus.persistent_dict import PersistentDict [as 别名]
# 或者: from durus.persistent_dict.PersistentDict import has_key [as 别名]
class categoricalIndex(Persistent):
    def __init__(self, name, low, high, legalValues):
        self.name = name
        self.data = PersistentDict()
        for l in legalValues:
            self.data[l] = PersistentSet()
    
    def __getitem__(self, keys):
        if isinstance(keys,slice):
            raise Exception('A categorical index cannot be sliced.')
        elif isinstance(keys,set):
            keys = list(keys)
        elif not isinstance(keys,list):
            keys = [keys]
        
        # start with the smallest set
        smallestSize=sys.maxint
        smallestKey=None
        for k in keys:
            if len(self.data[k]) < smallestSize:
                smallestSize = len(self.data[k])
            smallestKey = k
        if smallestKey == None:
            return set()
        
        results = set(self.data[smallestKey])
        for k in keys:
            if k == smallestKey:
                continue
            results.intersection_update(self.data[k])
        return results
    
    def __setitem__(self, key, value):
        if not self.data.has_key(key):
            raise Exception('Unknown categorical key: %s' % key)
        else:
            self.data[key].add(value)
    
    def count(self, keys):
        if isinstance(keys,slice):
            raise Exception('A categorical index cannot be sliced.')
        elif isinstance(keys,set):
            keys = list(keys)
        elif not isinstance(keys,list):
            keys = [keys]
        
        count = 0
        for k in keys:
            count += len(self.data[k])
        return count
    
    def has_key(self, key):
        return self.data.has_key(key)
开发者ID:alex-r-bigelow,项目名称:compreheNGSive,代码行数:55,代码来源:structures.py

示例2: test_clear

# 需要导入模块: from durus.persistent_dict import PersistentDict [as 别名]
# 或者: from durus.persistent_dict.PersistentDict import has_key [as 别名]
 def test_clear(self):
     pd = PersistentDict((x, True) for x in range(10))
     assert pd.has_key(2)
     pd.clear()
     assert not pd.has_key(2)
     assert list(pd.keys()) == []
开发者ID:ctismer,项目名称:durus,代码行数:8,代码来源:test_persistent_dict.py

示例3: test_has_key

# 需要导入模块: from durus.persistent_dict import PersistentDict [as 别名]
# 或者: from durus.persistent_dict.PersistentDict import has_key [as 别名]
 def test_has_key(self):
     pd = PersistentDict((x, True) for x in range(10))
     assert pd.has_key(2)
     assert not pd.has_key(-1)
开发者ID:ctismer,项目名称:durus,代码行数:6,代码来源:test_persistent_dict.py

示例4: NetworkDevice

# 需要导入模块: from durus.persistent_dict import PersistentDict [as 别名]
# 或者: from durus.persistent_dict.PersistentDict import has_key [as 别名]
class NetworkDevice(OwnedPersistent):
	"""NetworkDevice([name])
This object is a persistent store object that represents a networked device as
a collection of interfaces. It has a name that is used for string conversion.
	"""
	# the following (class-level attributes) become the default values for
	# various methods. Set an instance attribute of the same name to override
	# these values.
	user = None # default user to log in as
	password = None # default password for default user
	prompt = "# " # default CLI prompt for interactive sessions
	accessmethod = "ssh" # default. Possible are: ssh, console, serial, telnet, snmp
	initialaccessmethod = "console" # how to access for initial (before accessmethod is available) access
	console_server = (None, None) # host and TCP port used to connect to device serial console
	power_controller = (None, None) # APC host and outlet number used to control power
	monitor_port = (None, None) # may contain tuple of (device, interface) of an etherswitch to monitor
	domain = None # default DNS domain of the device
	nameservers = []	   # default DNS server list to be configured
	ntpserver = None	   # default NTP server to configure
	sysObjectID = None # The SNMP object identifier for a (sub)class of device.
	snmpRoCommunity = "public"	   # default RO SNMP community to use
	snmpRwCommunity = "private"    # default RW SNMP community to use
	admin_interface = "eth0" # interface on administrative network. This interface is "invisible" to device methods.
	data_interfaces = ["eth0"] # the "business" interfaces that are in use.

	def __init__(self, name):
		super(NetworkDevice, self).__init__()
		self.name = self.hostname = str(name)
		self.INTERFACEMAP = PersistentDict()
		self._interfaces = PersistentDict()
		self.data_interfaces = PersistentList()
		self.admin_interface = None
		self.initialize() # subclass interface

	# a non-persistent dictionary to cache transient attributes from a device
	def _get_cache(self):
		try:
			return self.__dict__["_cache_"]
		except KeyError:
			import dictlib
			c = dictlib.AttrDict()
			self.__dict__["_cache_"] = c
			return c
	_cache = property(_get_cache)

	def __repr__(self):
		return "%s(%r)" % (self.__class__.__name__, self.name)

	def __str__(self):
		return self.name # don't change this or you will break a lot of things 

	def initialize(self):
		pass

	def interface_alias(self, name, alias=None):
		"""sets (or removes) an alias name for an interface."""
		if alias is not None:
			self.INTERFACEMAP[str(alias)] = str(name)
		else:
			del self.INTERFACEMAP[str(name)]

	def set_hostname(self, name):
		"""Sets the hostname (and alias "name" attribute)."""
		self.name = self.hostname = str(name)

	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]
#.........这里部分代码省略.........
开发者ID:pruan,项目名称:TestDepot,代码行数:103,代码来源:netobjects.py


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