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

Python weakref.weakref_ref函数代码示例

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

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



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

示例1: __init__

 def __init__(self, agent, mta):
     self.messages = []
     self.agent = weakref_ref(agent)
     self.mta = weakref_ref(mta)
     self.events = agent.getEvents()
     for event in self.events:
         mta.registerMailingList(self, event)
开发者ID:zhuyue1314,项目名称:segvault,代码行数:7,代码来源:mailbox.py


示例2: __setstate__

 def __setstate__(self, state):
     self.byObject = dict(
         (id(obj), key) for key, obj  in state['bySymbol'] )
     self.bySymbol = dict(
         (key, weakref_ref(obj)) for key, obj in state['bySymbol'] )
     self.aliases = dict(
         (key, weakref_ref(obj)) for key, obj in state['aliases'] )
开发者ID:Pyomo,项目名称:pyomo,代码行数:7,代码来源:symbol_map.py


示例3: __init__

    def __init__(self, method, cb = None):
        from util.introspect import funcinfo
        assert hasattr(method, 'im_self'), 'no im_self: %s' % funcinfo(method)

        self.object = weakref_ref(method.im_self, cb)
        self.func   = weakref_ref(method.im_func)
        self.cls    = weakref_ref(method.im_class)
开发者ID:AlexUlrich,项目名称:digsby,代码行数:7,代码来源:refs.py


示例4: set_value

    def set_value(self, vals):
        """Set the port attributes on this arc"""
        # the following allows m.a = Arc(directed=True); m.a = (m.p, m.q)
        # and m.a will be directed
        d = self._directed if self._directed is not None else \
            self.parent_component()._init_directed

        vals = _iterable_to_dict(vals, d, self.name)

        source = vals.pop("source", None)
        destination = vals.pop("destination", None)
        ports = vals.pop("ports", None)
        directed = vals.pop("directed", None)

        if len(vals):
            raise ValueError(
                "set_value passed unrecognized keywords in val:\n\t" +
                "\n\t".join("%s = %s" % (k, v) for k, v in iteritems(vals)))

        if directed is not None:
            if source is None and destination is None:
                if directed and ports is not None:
                    # implicitly directed ports tuple, transfer to src and dest
                    try:
                        source, destination = ports
                        ports = None
                    except:
                        raise ValueError(
                            "Failed to unpack 'ports' argument of arc '%s'. "
                            "Argument must be a 2-member tuple or list."
                            % self.name)
            elif not directed:
                # throw an error if they gave an inconsistent directed value
                raise ValueError(
                    "Passed False value for 'directed' for arc '%s', but "
                    "specified source or destination." % self.name)

        self._validate_ports(source, destination, ports)

        if self.ports is not None:
            # we are reassigning this arc's values, clean up port lists
            weakref_self = weakref_ref(self)
            for port in self.ports:
                port._arcs.remove(weakref_self)
            if self._directed:
                self.source._dests.remove(weakref_self)
                self.destination._sources.remove(weakref_self)

        self._ports = tuple(ports) if ports is not None \
            else (source, destination)
        self._directed = source is not None
        weakref_self = weakref_ref(self)
        for port in self._ports:
            port._arcs.append(weakref_self)
        if self._directed:
            source._dests.append(weakref_self)
            destination._sources.append(weakref_self)
开发者ID:Pyomo,项目名称:pyomo,代码行数:57,代码来源:arc.py


示例5: __init__

 def __init__(self, project, name, mta=None, application=None):
     if not mta:
         mta = project.mta()
     Agent.__init__(self, name, mta)
     self.project = weakref_ref(project)
     if not application:
         application = project.application()
     self.application = weakref_ref(application)
     if project is not self:
         self.score_weight = 1.0
         self.register()
开发者ID:cherry-wb,项目名称:segvault,代码行数:11,代码来源:project_agent.py


示例6: getSymbol

 def getSymbol(self, obj, labeler=None, *args):
     """
     Return the symbol for an object.  If it has not already been cached
     in the symbol map, then create it.
     """
     obj_id = id(obj)
     if obj_id in self.byObject:
         return self.byObject[obj_id]
     #
     # Create a new symbol, performing an error check if it is a duplicate
     #
     if labeler:
         symb = labeler(obj)
     elif self.default_labeler:
         symb = self.default_labeler(obj)
     else:
         symb = str(obj)
     if symb in self.bySymbol:
         if self.bySymbol[symb]() is not obj:
             raise RuntimeError(
                 "Duplicate symbol '%s' already associated with "
                 "component '%s' (conflicting component: '%s')"
                 % (symb, self.bySymbol[symb]().name, obj.name) )
     self.bySymbol[symb] = weakref_ref(obj)
     self.byObject[obj_id] = symb
     return symb
开发者ID:Pyomo,项目名称:pyomo,代码行数:26,代码来源:symbol_map.py


示例7: __setstate__

 def __setstate__(self, state):
     """
     This method must be defined to support unpickling because this class
     owns weakrefs for '_component'.
     """
     #
     # FIXME: We shouldn't have to check for weakref.ref here, but if
     # we don't the model cloning appears to fail (in the Benders
     # example)
     #
     if state['_component'] is not None and \
             type(state['_component']) is not weakref_ref:
         state['_component'] = weakref_ref(state['_component'])
     #
     # Note: our model for setstate is for derived classes to modify
     # the state dictionary as control passes up the inheritance
     # hierarchy (using super() calls).  All assignment of state ->
     # object attributes is handled at the last class before 'object'
     # (which may -- or may not (thanks to MRO) -- be here.
     #
     _base = super(ComponentData,self)
     if hasattr(_base, '__setstate__'):
         return _base.__setstate__(state)
     else:
         for key, val in iteritems(state):
             # Note: per the Python data model docs, we explicitly
             # set the attribute using object.__setattr__() instead
             # of setting self.__dict__[key] = val.
             object.__setattr__(self, key, val)
开发者ID:Juanlu001,项目名称:pyomo,代码行数:29,代码来源:component.py


示例8: getSymbol

 def getSymbol(self, obj, labeler=None, *args):
     """
     Return the symbol for an object.  If it has not already been cached
     in the symbol map, then create it.
     """
     obj_id = id(obj)
     if obj_id in self.byObject:
         return self.byObject[obj_id]
     #
     # Create a new symbol, performing an error check if it is a duplicate
     #
     if labeler is None:
         raise RuntimeError("Object %s is not in the symbol map. "
                            "Cannot create a new symbol without "
                            "a labeler." % obj.cname(True))
     symb = labeler(obj)
     if symb in self.bySymbol:
         if self.bySymbol[symb]() is not obj:
             raise RuntimeError(
                 "Duplicate symbol '%s' already associated with "
                 "component '%s' (conflicting component: '%s')"
                 % (symb, self.bySymbol[symb]().cname(True), obj.cname(True)) )
     self.bySymbol[symb] = weakref_ref(obj)
     self.byObject[obj_id] = symb
     return symb
开发者ID:Juanlu001,项目名称:pyomo,代码行数:25,代码来源:symbol_map.py


示例9: __setitem__

 def __setitem__(self, i, item):
     if isinstance(item, self._interface_datatype):
         if item._component is None:
             item._component = weakref_ref(self)
             if hasattr(self, "_active"):
                 self._active |= getattr(item, '_active', True)
             # release the current component (assuming we don't get
             # an index error)
             # * see __delitem__ for explanation
             self._data[i]._component = None
             self._data[i] = item
             return
         # see note about allowing components to live in more than
         # one container
         raise ValueError(
             "Invalid component object assignment to ComponentList "
             "%s at index %s. A parent component has already been "
             "assigned the object: %s"
             % (self.cname(True),
                i,
                item.parent_component().cname(True)))
     # see note about implicit assignment and update
     raise TypeError(
         "ComponentList must be assigned objects "
         "of type %s. Invalid type for key %s: %s"
         % (self._interface_datatype.__name__,
            i,
            type(item)))
开发者ID:SemanticBeeng,项目名称:pyomo,代码行数:28,代码来源:list_objects.py


示例10: __init__

 def __init__(self, domain=Reals, component=None):
     #
     # These lines represent in-lining of the
     # following constructors:
     #   - _VarData
     #   - ComponentData
     #   - NumericValue
     self._component = weakref_ref(component) if (component is not None) \
                       else None
     self._value = None
     #
     # The type of the lower and upper bound attributes can either
     # be atomic numeric types in Python, expressions, etc.
     # Basically, they can be anything that passes an "is_fixed" test.
     #
     self._lb = None
     self._ub = None
     self._domain = None
     self.fixed = False
     self.stale = True
     # don't call the property setter here because
     # the SimplVar constructor will fail
     if hasattr(domain, 'bounds'):
         self._domain = domain
     else:
         raise ValueError(
             "%s is not a valid domain. Variable domains must be an "
             "instance of one of %s an object that declares a method "
             "for bounds (like a Pyomo Set). Examples: NonNegativeReals, "
             "Integers, Binary" % (domain, (RealSet, IntegerSet, BooleanSet)))
开发者ID:Juanlu001,项目名称:pyomo,代码行数:30,代码来源:var.py


示例11: __setstate__

 def __setstate__(self, state):
     self._metadata = state['_metadata']
     self._entry = {}
     for name, data in iteritems(state['_entry']):
         tmp = self._entry[name] = {}
         for obj, entry in data:
             tmp[ id(obj) ] = ( weakref_ref(obj), entry )
开发者ID:Pyomo,项目名称:pyomo,代码行数:7,代码来源:PyomoModel.py


示例12: __setitem__

 def __setitem__(self, key, val):
     if isinstance(val, self._interface_datatype):
         if val._component is None:
             val._component = weakref_ref(self)
             self._active |= getattr(val, '_active', True)
             if key in self._data:
                 # release the current component
                 # * see __delitem__ for explanation
                 self._data[key]._component = None
             self._data[key] = val
             return
         # see note about allowing components to live in more than
         # one container
         raise ValueError(
             "Invalid component object assignment to ComponentDict "
             "%s at key %s. A parent component has already been "
             "assigned the object: %s"
             % (self.cname(True),
                key,
                val.parent_component().cname(True)))
     # see note about implicit assignment and update
     raise TypeError(
         "ComponentDict must be assigned objects "
         "of type %s. Invalid type for key %s: %s"
         % (self._interface_datatype.__name__,
            key,
            type(val)))
开发者ID:Juanlu001,项目名称:pyomo,代码行数:27,代码来源:dict_objects.py


示例13: __init__

    def __init__(self, application):
        self.application = weakref_ref(application)
        self.timestamp_format = '%(asctime)s: %(message)s'

        # Choose log levels
        if application.options.debug:
            stdout_level = INFO
            file_level = DEBUG
        elif application.options.verbose:
            stdout_level = WARNING
            file_level = INFO
        elif not application.options.quiet:
            stdout_level = ERROR
            file_level = WARNING
        else:
            stdout_level = ERROR
            file_level = INFO

        self.logger = getLogger()

        # fusil.log file
        self.filename = LOG_FILENAME
        self.file_handler = self.addFileHandler(self.filename, file_level)

        # Create stdout logger
        handler = StreamHandler(stdout)
        self.addHandler(handler, stdout_level)
开发者ID:tuwid,项目名称:darkc0de-old-stuff,代码行数:27,代码来源:application_logger.py


示例14: __init__

 def __init__(self, process):
     type = process.stdout
     if type not in ('null', 'file'):
         raise ValueError('Invalid stdout type: %r' % type)
     SessionAgent.__init__(self, process.project().session, "stdout file")
     self.type = type
     self.process = weakref_ref(process)
开发者ID:tuwid,项目名称:darkc0de-old-stuff,代码行数:7,代码来源:stdout.py


示例15: construct

    def construct(self, data=None):
        """Construct this component."""

        if __debug__ and logger.isEnabledFor(logging.DEBUG):   #pragma:nocover
            try:
                name = str(self.cname(True))
            except:
                # Some Var components don't have a name yet, so just use the type
                name = type(self)
            if logger.isEnabledFor(logging.DEBUG):
                logger.debug(
                    "Constructing Variable, name=%s, from data=%s"
                    % (name, str(data)))

        if self._constructed:
            return
        self._constructed=True

        #
        # Construct _VarData objects for all index values
        #
        if not self.is_indexed():
            self._data[None] = self
            self._initialize_members([None])
        elif self._dense:
            # This loop is optimized for speed with pypy.
            # Calling dict.update((...) for ...) is roughly
            # 30% slower
            self_weakref = weakref_ref(self)
            for ndx in self._index:
                cdata = _GeneralVarData(Reals, component=None)
                cdata._component = self_weakref
                self._data[ndx] = cdata
            self._initialize_members(self._index)
开发者ID:Juanlu001,项目名称:pyomo,代码行数:34,代码来源:var.py


示例16: __init__

 def __init__(self, session, name, project=None):
     if project:
         mta = project.mta()
     else:
         mta = session.mta()
         project = session.project()
     self.session = weakref_ref(session)
     ProjectAgent.__init__(self, project, name, mta=mta)
     self.activate()
开发者ID:tuwid,项目名称:darkc0de-old-stuff,代码行数:9,代码来源:session_agent.py


示例17: __init__

 def __init__(self, session, server, socket, address, family):
     self.server = weakref_ref(server)
     self.socket = socket
     self.address = address
     self.family = family
     name = "net_client:" + formatAddress(self.family, self.address, short=True)
     SessionAgent.__init__(self, session, name)
     self.tx_bytes = 0
     self.rx_bytes = 0
开发者ID:cherry-wb,项目名称:segvault,代码行数:9,代码来源:server_client.py


示例18: getSubIStream

 def getSubIStream(self):
     if hasattr(self, "_sub_istream"):
         stream = self._sub_istream()
     else:
         stream = None
     if stream is None:
         stream = self._createInputStream()
         self._sub_istream = weakref_ref(stream)
     return stream
开发者ID:BirdAPI,项目名称:Sick-Beard,代码行数:9,代码来源:field.py


示例19: __init__

 def __init__(self, component):
     #
     # ComponentData objects are typically *private* objects for
     # indexed / sparse indexed components.  As such, the (derived)
     # class needs to make sure that the owning component is *always*
     # passed as the owner (and that owner is never None).  Not validating
     # this assumption is significantly faster.
     #
     self._component = weakref_ref(component)
开发者ID:Pyomo,项目名称:pyomo,代码行数:9,代码来源:component.py


示例20: addSymbols

    def addSymbols(self, obj_symbol_tuples):
        """
        Add (object, symbol) tuples from an iterable object.

        This method assumes that symbol names will not conflict.
        """
        tuples = list((obj, symb) for obj,symb in obj_symbol_tuples)
        self.byObject.update((id(obj_), symb_) for obj_,symb_ in tuples)
        self.bySymbol.update((symb_, weakref_ref(obj_)) for obj_,symb_ in tuples)
开发者ID:Pyomo,项目名称:pyomo,代码行数:9,代码来源:symbol_map.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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