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


Python weakref.weakref_ref函数代码示例

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


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


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