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


Python WeakKeyDictionary.has_key方法代码示例

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


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

示例1: __init__

# 需要导入模块: from weakref import WeakKeyDictionary [as 别名]
# 或者: from weakref.WeakKeyDictionary import has_key [as 别名]
class EventManager:
    """this object is responsible for coordinating most communication
    between the Model, View, and Controller."""
    def __init__(self, initlist=None ):
        self.listeners = WeakKeyDictionary()
        self.eventQueue = []
     
        self.__lock = threading.Lock()


    #----------------------------------------------------------------------
    def RegisterListener( self, listener , eventList):
        #if not hasattr( listener, "Notify" ): raise blah blah...
        self.listeners[ listener ] = eventList
    
    def addListener(self, listener, eventList):
    
        if self.listeners.has_key( listener ):
            self.listeners[ listener ].append( eventList )
        else:
            self.listeners[ listener ] = eventList

    #----------------------------------------------------------------------
    def UnregisterListener( self, listener ):
        if listener in self.listeners.keys():
            del self.listeners[ listener ]
        
    #----------------------------------------------------------------------
    def Post( self, event ):

        if event==OneSecondEvent:
            self.sendEvent( event )
                
        if not event==TickEvent: 
            self.__lock.acquire()
            self.eventQueue.append( event )
            self.__lock.release()
        else:
            self.flushEvents()

            #at the end, notify listeners of the Tick event
            for listener in self.listeners.keys():
                listener.Notify( event )
        
        
    def flushEvents(self):
        if self.eventQueue:
            for k in range(len(self.eventQueue)):
                ev = self.eventQueue.pop(0)
                self.sendEvent(ev)
                
    def sendEvent(self, ev):
        for listener in self.listeners.keys():
            throwable_events = self.listeners[listener]
            if ev in throwable_events:
                listener.Notify( ev )
开发者ID:jbittencourt,项目名称:cooperativa_client,代码行数:58,代码来源:eventmanager.py

示例2: __init__

# 需要导入模块: from weakref import WeakKeyDictionary [as 别名]
# 或者: from weakref.WeakKeyDictionary import has_key [as 别名]
class PolicyEnv:
  def __init__(self):
    self.policies = WeakKeyDictionary()

  def mkLabel(self, name="", uniquify=True):
    label = fast.AST.Var(name, uniquify)
    return label

  # policy is a function from context to bool which returns true
  # if the label is allowed to be HIGH
  def restrict(self, label, policy, use_empty_env=False):
    pcFormula = fast.AST.Constant(True) if use_empty_env \
                    else JeevesLib.jeevesState.pathenv.getPathFormula()
    
    label_var_set = label.vars()
    assert(len(label_var_set) == 1)
    label_var = list(label_var_set)[0]
    if self.policies.has_key(label_var):
        self.policies[label_var] = (lambda ctxt:
            fast.AST.Implies(
                pcFormula,
                fast.AST.And(fast.AST.fexpr_cast(policy(ctxt))
                    , fast.AST.fexpr_cast(self.policies[label_var](ctxt)))))
    else:
        self.policies[label_var] = (lambda ctxt:
            fast.AST.Implies(
                pcFormula,
                fast.AST.fexpr_cast(policy(ctxt)),
            ))

  def getNewSolverState(self, ctxt):
    return SolverState(self.policies, ctxt)

  def concretizeExp(self, ctxt, f, pathenv):
    solver_state = self.getNewSolverState(ctxt)
    return solver_state.concretizeExp(f, pathenv)

  """
开发者ID:jeanqasaur,项目名称:jeeves,代码行数:40,代码来源:PolicyEnv.py

示例3: KVOBroker

# 需要导入模块: from weakref import WeakKeyDictionary [as 别名]
# 或者: from weakref.WeakKeyDictionary import has_key [as 别名]
class KVOBroker(object):
    """
    Helper class which simplifies handling of key-value observers.
    
    Can be used as a mixin or standalone.
    """
    
    implements(IKeyValueObservable)
    
    __kvobservers = None
    
    def addObserver(self, observer, propertyNames=None):
        assert IKeyValueObserver.providedBy(observer)
        
        if self.__kvobservers == None:
            self.__kvobservers = WeakKeyDictionary()
        
        if propertyNames == None:
            self.__kvobservers[observer] = None
            return
        
        if isinstance(propertyNames, basestring):
            propertyNames = [propertyNames]
        
        propertyNames = set(propertyNames)
        
        if self.__kvobservers.has_key(observer):
            self.__kvobservers[observer] |= propertyNames
        else:
            self.__kvobservers[observer] = propertyNames
    
    def removeObserver(self, observer, propertyNames=None):
        assert IKeyValueObserver.providedBy(observer)
        
        if self.__kvobservers == None:
            return
        
        if self.__kvobservers.has_key(observer):
            if propertyNames == None:
                del self.__kvobservers[observer]
            else:
                self.__kvobservers[observer] -= propertyNames
                if len(self.__kvobservers[observer]) == 0:
                    del self.__kvobservers[observer]
    
    def notifyPropertyWillChange(self, propertyName, srcobject=None):
        """
        Call this to inform the respective observers of an impending change.
        
        You must call `notifyPropertyDidChange()` after you performed the
        changes. The call is not stackable.
        """
        
        if srcobject == None:
            srcobject = self
        self.__propertyName = propertyName
        self.__srcobject = srcobject
        
        if self.__kvobservers != None:
            for observer, propertyNames in dict(self.__kvobservers).iteritems():
                if propertyNames == None or propertyName in propertyNames:
                    observer.observedPropertyWillChange(srcobject, propertyName)
    
    def notifyPropertyDidChange(self):
        """
        Call this to inform the respective observers of a performed change.
        
        You must have called `notifyPropertyWillChange()` before.
        """
        
        if self.__kvobservers != None:
            for observer, propertyNames in dict(self.__kvobservers).iteritems():
                if propertyNames == None or self.__propertyName in propertyNames:
                    observer.observedPropertyDidChange(self.__srcobject, self.__propertyName)
        
        del self.__propertyName
        del self.__srcobject
开发者ID:p2k,项目名称:CPL,代码行数:79,代码来源:broker.py

示例4: Model

# 需要导入模块: from weakref import WeakKeyDictionary [as 别名]
# 或者: from weakref.WeakKeyDictionary import has_key [as 别名]

#.........这里部分代码省略.........
            for prop in cls.all_properties:
                if prop.name == name:
                    return prop

        pass # end of class

    def __init__(self):
        Observer.__init__(self)


        self._prop_lock = threading.RLock() # @UndefinedVariable
        self.__observers = WeakList()
        self.__observer_threads = WeakKeyDictionary()

        # keys are properties names, values are pairs (method,
        # kwargs|None) inside the observer. kwargs is the keyword
        # argument possibly specified when explicitly defining the
        # notification method in observers, and it is used to build
        # the NTInfo instance passed down when the notification method
        # is invoked. If kwargs is None (special case), the
        # notification method is "old style" (property_<name>_...) and
        # won't be receiving the property name.
        self.__value_notifications = {}
        self.__instance_notif_before = {}
        self.__instance_notif_after = {}
        self.__signal_notif = {}

        for prop in self.get_properties(): self.register_property(prop)
        return

    def register_property(self, prop):
        """Registers an existing property to be monitored, and sets
        up notifiers for notifications"""
        if not self.__value_notifications.has_key(prop.name):
            self.__value_notifications[prop.name] = []
            pass

        # registers observable wrappers
        propval = getattr(self, prop.get_private_name(), None)

        if isinstance(propval, ObsWrapperBase):
            propval.__add_model__(self, prop.name)

            if isinstance(propval, Signal):
                if not self.__signal_notif.has_key(prop.name):
                    self.__signal_notif[prop.name] = []
                    pass
                pass
            else:
                if not self.__instance_notif_before.has_key(prop.name):
                    self.__instance_notif_before[prop.name] = []
                    pass
                if not self.__instance_notif_after.has_key(prop.name):
                    self.__instance_notif_after[prop.name] = []
                    pass
                pass
            pass

        return

    def has_property(self, name):
        """Returns true if given property name refers an observable
        property inside self or inside derived classes."""
        for prop in self.get_all_properties():
            if prop.name == name:
                return True
开发者ID:claudioquaglia,项目名称:PyXRD,代码行数:70,代码来源:base.py

示例5: findHBonds

# 需要导入模块: from weakref import WeakKeyDictionary [as 别名]
# 或者: from weakref.WeakKeyDictionary import has_key [as 别名]

#.........这里部分代码省略.........
						distSlop, angleSlop))
	genericAccInfo['Sar'] = genericAccInfo['S3-'] = (accGeneric,
			_processArgTuple([3.83, 85], distSlop, angleSlop))
	# now the donors...
	
	# planar nitrogens
	genDonNpl1HParams = (donThetaTau, _processArgTuple([2.23, 136,
		2.23, 141, 140, 2.46, 136, 140], distSlop, angleSlop))
	genDonNpl2HParams = (donUpsilonTau, _processArgTuple([3.30, 90, -153,
		135, -45, 3.30, 90, -146, 140, -37.5, 130, 3.40, 108, -166, 125,
		-35, 140], distSlop, angleSlop))
	genDonODists = [2.41, 2.28, 2.28, 3.27, 3.14, 3.14]
	genDonOParams = (donGeneric, _processArgTuple(
					genDonODists, distSlop, angleSlop))
	genDonNDists = [2.36, 2.48, 2.48, 3.30, 3.42, 3.42]
	genDonNParams = (donGeneric, _processArgTuple(
					genDonNDists, distSlop, angleSlop))
	genDonSDists = [2.42, 2.42, 2.42, 3.65, 3.65, 3.65]
	genDonSParams = (donGeneric, _processArgTuple(
					genDonSDists, distSlop, angleSlop))
	genericDonInfo = {
		'O': genDonOParams,
		'N': genDonNParams,
		'S': genDonSParams
	}

	accTrees = {}
	hbonds = []
	hasSulfur = {}
	for model in models:
		replyobj.status("Finding acceptors in model '%s'\n"
						% model.name, blankAfter=0)
		if cacheDA \
		and _Acache.has_key(model) \
		and _Acache[model].has_key((distSlop, angleSlop)):
			accAtoms = []
			accData = []
			for accAtom, data in _Acache[model][(distSlop,
							angleSlop)].items():
				if not accAtom.__destroyed__:
					accAtoms.append(accAtom)
					accData.append(data)
		else:
			accAtoms, accData = _findAcceptors(model, aParams,
					limitedAcceptors, genericAccInfo)
			if cacheDA:
				cache = WeakKeyDictionary()
				for i in range(len(accAtoms)):
					cache[accAtoms[i]] = accData[i]
				if not _Acache.has_key(model):
					_Acache[model] = {}
				_Acache[model][(distSlop, angleSlop)] = cache
		xyz = []
		hasSulfur[model] = False
		for accAtom in accAtoms:
			c = accAtom.xformCoord()
			xyz.append([c.x, c.y, c.z])
			if accAtom.element.number == Element.S:
				hasSulfur[model] = True
		replyobj.status("Building search tree of acceptor atoms\n",
								blankAfter=0)
		accTrees[model] = AdaptiveTree(xyz, accData, 3.0)
	
	if processKey not in processedDonorParams:
		# find max donor distances before they get squared..
开发者ID:davem22101,项目名称:semanticscience,代码行数:69,代码来源:base.py


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