• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python common.unwrapWeakref函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中music21.common.unwrapWeakref函数的典型用法代码示例。如果您正苦于以下问题:Python unwrapWeakref函数的具体用法?Python unwrapWeakref怎么用?Python unwrapWeakref使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



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

示例1: element

 def element(self):
     '''
     defined so a TimespanTree can be used like an PitchedTimespan
     
     TODO: Look at subclassing or at least deriving from a common base...
     '''
     return common.unwrapWeakref(self._source)
开发者ID:blakme,项目名称:music21,代码行数:7,代码来源:timespanTree.py


示例2: getComponents

    def getComponents(self, spanner):
        """Given a spanner defined in this Spanners, return a list of associated components. 

        Components, while stored as weakrefs, are unwrapped.

        >>> from music21 import *
        >>> class TestMock(object): pass
        >>> tm1 = TestMock()
        >>> n1 = note.Note('c2')
        >>> n2 = note.Note('g3')
        >>> sp1 = Spanners()
        >>> sp1.add(tm1, [n1, n2])
        >>> sp1.getComponents(tm1) == [n1, n2]
        True
        """
        idSpanner = id(spanner)
        if idSpanner not in self.keys():
            raise SpannersException(
                "cannot return comoponents from an object not defined in spanners: %s" % repr(spanner)
            )

        post = []
        # get all objects, unwrap
        # second index is list of components
        for wr in self._storage[idSpanner][1]:
            post.append(common.unwrapWeakref(wr))
        return post
开发者ID:jamesdoherty,项目名称:music21,代码行数:27,代码来源:spanners.py


示例3: getSpanner

    def getSpanner(self, component):
        """Given a component, return a list of all spanner objects that bundle that component.

        >>> from music21 import *
        >>> class TestMock(object): pass
        >>> tm1 = TestMock()
        >>> n1 = note.Note('c2')
        >>> n2 = note.Note('g3')
        >>> sp1 = Spanners()
        >>> sp1.add(tm1, [n1, n2])
        >>> sp1.getSpanner(n2) == [tm1]
        True
        """
        idComponent = id(component)
        # find all keys
        spannerKeys = []
        for key in self.keys():
            # look at all component ids
            for idKnown in self._idRef[key]:
                if idKnown == idComponent:
                    spannerKeys.append(key)
                    break
        # unwrap spanner for found keys
        post = []
        for key in spannerKeys:
            # first index is spanner object
            post.append(common.unwrapWeakref(self._storage[key][0]))

        return post
开发者ID:jamesdoherty,项目名称:music21,代码行数:29,代码来源:spanners.py


示例4: client

 def client(self):
     c = common.unwrapWeakref(self._client)
     if c is None and self._clientId is not None:
         self._clientId = None
         self._client = None
         self._origin = None
         self._originId = None
     return c
开发者ID:EQ4,项目名称:music21,代码行数:8,代码来源:derivation.py


示例5: testWeakref

    def testWeakref(self):
        from music21 import note

        n = note.Note()
        idStored = id(n)
        wn = common.wrapWeakref(n)
        n2 = common.unwrapWeakref(n)
        self.assertEqual(id(n), id(n2))
开发者ID:jamesdoherty,项目名称:music21,代码行数:8,代码来源:spanners.py


示例6: _getParent

 def _getParent(self):
     if self._parent is None:
         return None
     post = common.unwrapWeakref(self._parent)
     if post is None:
         # set attribute for speed
         self._parent = None
     return post
开发者ID:msampaio,项目名称:music21,代码行数:8,代码来源:volume.py


示例7: client

    def client(self):
        '''
        The client stores a reference to the Plot that
        makes reference to this axis.

        (Like all music21 clients, It is normally stored internally as a weakref,
        so no need for garbage collecting)
        '''
        return common.unwrapWeakref(self._client)
开发者ID:cuthbertLab,项目名称:music21,代码行数:9,代码来源:axis.py


示例8: purgeLocations

    def purgeLocations(self, rescanIsDead=False):
        '''
        Clean all locations that refer to objects that no longer exist.

        The `removeOrphanedSites` option removes sites that may have been the
        result of deepcopy: the element has the site, but the site does not
        have the element. This results b/c Sites are shallow-copied, and then
        elements are re-added.

        >>> class Mock(base.Music21Object):
        ...     pass
        ...
        >>> aSite = Mock()
        >>> cSite = Mock()
        >>> aLocations = sites.Sites()
        >>> aLocations.add(aSite, 0)
        >>> aLocations.add(cSite) # a context
        >>> del aSite
        >>> len(aLocations)
        2

        >>> aLocations.purgeLocations(rescanIsDead=True)
        >>> len(aLocations)
        1
        '''
        # first, check if any sites are dead, and cache the results
        if rescanIsDead:
            for idKey in self._locationKeys:
                if idKey is None:
                    continue
                siteRef = self.siteDict[idKey]
                #if siteRef.isDead:
                #    continue  # already marked -- do it again, in case it is reused
                if WEAKREF_ACTIVE:
                    obj = common.unwrapWeakref(
                        siteRef.site)
                else:
                    obj = siteRef.site
                if obj is None: # if None, it no longer exists
                    siteRef.isDead = True
                else:
                    siteRef.isDead = False
        # use previously set isDead entry, so as not to
        # unwrap all references
        remove = []
        for idKey in self._locationKeys:
            if idKey is None:
                continue
            siteRef = self.siteDict[idKey]
            if siteRef.isDead:
                remove.append(idKey)
                
        for idKey in remove:
            # this call changes the ._locationKeys list, and thus must be
            # out side _locationKeys loop
            self.removeById(idKey)
开发者ID:05565,项目名称:music21,代码行数:56,代码来源:sites.py


示例9: _getAndUnwrapSite

 def _getAndUnwrapSite(self):
     if WEAKREF_ACTIVE:
         ret = common.unwrapWeakref(self.siteWeakref)
     else:
         ret = self.siteWeakref
         
     if ret is None and self is not _NoneSiteRef:
         self.isDead = True
         
     return ret
开发者ID:cuthbertLab,项目名称:music21,代码行数:10,代码来源:sites.py


示例10: client

 def client(self):
     '''
     Get or set the client, which must be a note.NotRest subclass. The
     client is wrapped in a weak reference.
     '''
     if self._client is None:
         return None
     post = common.unwrapWeakref(self._client)
     if post is None:
         # set attribute for speed
         self._client = None
     return post
开发者ID:willingc,项目名称:music21,代码行数:12,代码来源:volume.py


示例11: getSites

    def getSites(self, idExclude=None, excludeNone=False):
        """
        Get all Site objects in .siteDict that are locations. 
        Note that this unwraps all sites from weakrefs and is thus an expensive operation.

        ::
        
            >>> import music21
            >>> class Mock(music21.Music21Object):
            ...     pass
            ...
            >>> aObj = Mock()
            >>> bObj = Mock()
            >>> aSites = music21.Sites()
            >>> aSites.add(aObj, 234)
            >>> aSites.add(bObj, 3000)
            >>> len(aSites._locationKeys) == 2
            True

        ::

            >>> len(aSites.getSites()) == 2
            True

        """
        #         if idExclude is None:
        #             idExclude = [] # else, assume a list
        # use pre-collected keys
        post = []
        for idKey in self._locationKeys:
            if idExclude is not None:
                if idKey in idExclude:
                    continue
            try:
                objRef = self.siteDict[idKey].site
            except KeyError:
                raise SitesException("no such site: %s" % idKey)
            # skip dead references
            if self.siteDict[idKey].isDead:
                continue
            if idKey is None:
                if not excludeNone:
                    post.append(None)  # keep None as site
            elif not WEAKREF_ACTIVE:  # leave None alone
                post.append(objRef)
            else:
                obj = common.unwrapWeakref(objRef)
                if obj is None:
                    self.siteDict[idKey].isDead = True
                    continue
                post.append(obj)
        return post
开发者ID:ifitz,项目名称:music21,代码行数:52,代码来源:sites.py


示例12: unwrapWeakref

    def unwrapWeakref(self):
        '''Unwrap any and all weakrefs stored.

        >>> from music21 import *  
        >>> s1 = stream.Stream()
        >>> s2 = stream.Stream()
        >>> d1 = derivation.Derivation(s1) # sets container
        >>> d1.setAncestor(s2)
        >>> common.isWeakref(d1._container)
        True
        >>> d1.unwrapWeakref()
        >>> common.isWeakref(d1._container)
        False
        '''
        #environLocal.pd(['derivation pre unwrap: self._container', self._container])
        post = common.unwrapWeakref(self._container)
        self._container = post
开发者ID:msampaio,项目名称:music21,代码行数:17,代码来源:derivation.py


示例13: getSitesByClass

    def getSitesByClass(self, className):
        """
        Return a list of unwrapped site from siteDict.site [SiteRef.site] (generally a Stream) 
        that matches the provided class.

        Input can be either a Class object or a string

            >>> import music21
            >>> from music21 import stream
            >>> class Mock(music21.Music21Object):
            ...     pass
            ...
            >>> aObj = Mock()
            >>> bObj = Mock()
            >>> cObj = stream.Stream()
            >>> aSites = music21.Sites()
            >>> aSites.add(aObj, 234)
            >>> aSites.add(bObj, 3000)
            >>> aSites.add(cObj, 200)
            >>> aSites.getSitesByClass(Mock) == [aObj, bObj]
            True

        ::

            >>> aSites.getSitesByClass('Stream') == [cObj]
            True

        """
        found = []
        if not isinstance(className, str):
            className = common.classToClassStr(className)

        for idKey in self._locationKeys:
            siteRef = self.siteDict[idKey]
            if siteRef.isDead:
                continue
            classStr = siteRef.classString
            if classStr == className:
                objRef = siteRef.site
                if not WEAKREF_ACTIVE:  # leave None alone
                    obj = objRef
                else:
                    obj = common.unwrapWeakref(objRef)
                found.append(obj)
        return found
开发者ID:ifitz,项目名称:music21,代码行数:45,代码来源:sites.py


示例14: affectTokenAfterParse

 def affectTokenAfterParse(self, m21Obj):
     '''
     called to modify the tokenObj after parsing
     
     tokenObj may be None if another
     state has deleted it.
     '''
     self.affectedTokens.append(m21Obj)
     if self.autoExpires is not False:
         if len(self.affectedTokens) == self.autoExpires:
             self.end()
             p = common.unwrapWeakref(self.parent)
             for i in range(len(p.activeStates)):
                 backCount = -1 * (i+1)
                 if p.activeStates[backCount] is self:
                     p.activeStates.pop(backCount)
                     break
     return m21Obj
开发者ID:00gavin,项目名称:music21,代码行数:18,代码来源:tinyNotation.py


示例15: corpus

    def corpus(self):
        r'''
        The `corpus.corpora.Corpus` object associated with the metadata
        bundle's name.

        >>> from music21 import metadata
        >>> coreBundle = corpus.corpora.CoreCorpus().metadataBundle
        >>> coreBundle
        <music21.metadata.bundles.MetadataBundle 'core': {150... entries}>
        >>> coreBundle.corpus
        <music21.corpus.corpora.CoreCorpus>
        '''
        if self._corpus is not None:
            cObj = common.unwrapWeakref(self._corpus)
            if cObj is not None:
                return cObj
            
        if self.name is None:
            return None
        
        from music21.corpus import manager
        return manager.fromName(self.name)
开发者ID:sbrother,项目名称:music21,代码行数:22,代码来源:bundles.py


示例16: _getParent

 def _getParent(self):
     return common.unwrapWeakref(self._parent)
开发者ID:matyastr,项目名称:msps,代码行数:2,代码来源:clercqTemperley.py


示例17: _getAndUnwrapSite

 def _getAndUnwrapSite(self):
     # should set isDead?
     return common.unwrapWeakref(self.siteWeakref)
开发者ID:ifitz,项目名称:music21,代码行数:3,代码来源:sites.py


示例18: client

 def client(self):
     return common.unwrapWeakref(self._client)
开发者ID:Aminor7,项目名称:music21,代码行数:2,代码来源:streamStatus.py


示例19: __getstate__

 def __getstate__(self):
     self._client = common.unwrapWeakref(self._client)
     return SlottedObject.__getstate__(self)
开发者ID:Aminor7,项目名称:music21,代码行数:3,代码来源:streamStatus.py


示例20: _getSpineCollection

 def _getSpineCollection(self):
     return common.unwrapWeakref(self._spineCollection)
开发者ID:knuton,项目名称:music21,代码行数:2,代码来源:spineParser.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python common.wrapWeakref函数代码示例发布时间:2022-05-27
下一篇:
Python common.relativepath函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap