コード例 #1
0
ファイル: plugin.py プロジェクト: shiva16/openalea
 def instances(self, category, name=None, class_args=None, class_kwds=None):
     """
     Return all existing instances corresponding to this plugin
     """
     valid_instances = []
     if name is None:
         for plugin_name in self._plugin_instances.get(category, []):
             instances = list(self._plugin_instances[category][plugin_name])
             for weakref in instances:
                 obj = weakref()
                 if obj is None:
                     self._plugin_instances[category][plugin_name].remove(
                         weakref)
                 else:
                     valid_instances.append(obj)
     else:
         try:
             # return actual value instead of weakref
             valid_instances = []
             for weakref in self._plugin_instances[category][name]:
                 obj = weakref()
                 if obj is None:
                     self._plugin_instances[category][name].remove(weakref)
                 else:
                     valid_instances.append(obj)
         except KeyError:
             pass
     return valid_instances
コード例 #2
0
ファイル: plugin.py プロジェクト: VirtualPlants/openalea
 def instances(self, category, name=None, class_args=None, class_kwds=None):
     """
     Return all existing instances corresponding to this plugin
     """
     valid_instances = []
     if name is None:
         for plugin_name in self._plugin_instances.get(category, []):
             instances = list(self._plugin_instances[category][plugin_name])
             for weakref in instances:
                 obj = weakref()
                 if obj is None:
                     self._plugin_instances[category][plugin_name].remove(weakref)
                 else:
                     valid_instances.append(obj)
     else:
         try:
             # return actual value instead of weakref
             valid_instances = []
             for weakref in self._plugin_instances[category][name]:
                 obj = weakref()
                 if obj is None:
                     self._plugin_instances[category][name].remove(weakref)
                 else:
                     valid_instances.append(obj)
         except KeyError:
             pass
     return valid_instances
コード例 #3
0
    def __do_all_statements(self, action, reset_cursors):
        for weakref in self.__statements:
            statement = weakref()
            if statement is not None:
                action(statement)

        if reset_cursors:
            for weakref in self.__cursors:
                cursor = weakref()
                if cursor is not None:
                    cursor._reset = True
コード例 #4
0
ファイル: _sqlite3.py プロジェクト: mozillazg/pypy
    def __do_all_statements(self, action, reset_cursors):
        for weakref in self.__statements:
            statement = weakref()
            if statement is not None:
                action(statement)

        if reset_cursors:
            for weakref in self.__cursors:
                cursor = weakref()
                if cursor is not None:
                    cursor._reset = True
コード例 #5
0
 def _reset_already_committed_statements(self):
     lst = self.__statements_already_committed
     self.__statements_already_committed = []
     for weakref in lst:
         statement = weakref()
         if statement is not None:
             statement._reset()
コード例 #6
0
ファイル: weakreflist.py プロジェクト: saka16888/test
 def __setitem__(self, index, item):
     if isinstance(index, slice):
         return super(Weakreflist,
                      self).__setitem__(index,
                                        [weakref.ref(i) for i in item])
     else:
         return super(Weakreflist, self).__setitem(index, weakref(item))
コード例 #7
0
 def __init__(self, filename):
     if isinstance(self, CIndexedRowset):
         parent = CIndexedRowset
         self.cdata = True
     elif isinstance(self, CFilterRowset):
         parent = CFilterRowset
         self.cdata = False
     else:
         raise RuntimeError("CRowsetDiskBase: No support for '%s'" %
                            type(self))
     f = blue.ResFile()
     f.OpenAlways(filename + '.index.cr')
     indexData = blue.marshal.Load(f.Read())
     if indexData[0] != ROWSETVERSION:
         msg = 'DiskData: File %s is version %s, but I want %s' % (
             filename, indexData.version, ROWSETVERSION)
         raise RuntimeError(msg)
     parent.__init__(self, indexData[1], indexData[2])
     self.offsets = indexData[3]
     self.dataFile = blue.ResFile()
     self.dataFile.OpenAlways(filename + '.data.cr')
     self.maxUsage = 1
     self.minAge = 60
     self.loaded = {}
     self.__diskRowsets__ = weakref(self)
コード例 #8
0
 def removeView(self, view):
     """
     Remove a view that the model no longer should keep track of.
     """
     for weakref in list(self.views):
         ref = weakref()
         if ref is view or ref is None:
             self.views.remove(weakref)
コード例 #9
0
 def removeView(self, view):
     """
     Remove a view that the model no longer should keep track of.
     """
     # AM: loop on a _copy_ of the list, since we're changing it!!!
     for weakref in list(self.views):
         ref = weakref()
         if ref is view or ref is None:
             self.views.remove(weakref)
コード例 #10
0
 def __init__(self, coordinates, unique_id):
     import weakref
     self.position = coordinates
     self.id = unique_id  # integer
     self.input = {}  # node id of parent
     self.output = {}  # node is of daughter
     self.inlet = False
     self.outlet = False
     self._instances.add(weakref(self))
コード例 #11
0
ファイル: model.py プロジェクト: KatiaBorges/exeLearning
 def removeView(self, view):
     """
     Remove a view that the model no longer should keep track of.
     """
     # AM: loop on a _copy_ of the list, since we're changing it!!!
     for weakref in list(self.views):
         ref = weakref()
         if ref is view or ref is None:
             self.views.remove(weakref)
コード例 #12
0
 def __init__(self, filename):
     if isinstance(self, CIndexedRowset):
         parent = CIndexedRowset
         self.cdata = True
     elif isinstance(self, CFilterRowset):
         parent = CFilterRowset
         self.cdata = False
     else:
         raise RuntimeError("CRowsetDiskBase: No support for '%s'" % type(self))
     f = blue.ResFile()
     f.OpenAlways(filename + '.index.cr')
     indexData = blue.marshal.Load(f.Read())
     if indexData[0] != ROWSETVERSION:
         msg = 'DiskData: File %s is version %s, but I want %s' % (filename, indexData.version, ROWSETVERSION)
         raise RuntimeError(msg)
     parent.__init__(self, indexData[1], indexData[2])
     self.offsets = indexData[3]
     self.dataFile = blue.ResFile()
     self.dataFile.OpenAlways(filename + '.data.cr')
     self.maxUsage = 1
     self.minAge = 60
     self.loaded = {}
     self.__diskRowsets__ = weakref(self)
コード例 #13
0
 def proxy(*args, **kwargs):
     if weakref() is not None:
         weakref()(*args, **kwargs)
コード例 #14
0
class Signal:
    """
    Base class for all signals

    Internal attributes:

        receivers
            { receiverkey (id) : weakref(receiver) }
    """
    def __init__(self, providing_args=None, use_caching=False):
        """
        Create a new signal.

        providing_args
            A list of the arguments this signal can pass along in a send() call.
        """
        self.receivers = []
        if providing_args is None:
            providing_args = []
        self.providing_args = set(providing_args)
        self.lock = threading.Lock()
        self.use_caching = use_caching
        # For convenience we create empty caches even if they are not used.
        # A note about caching: if use_caching is defined, then for each
        # distinct sender we cache the receivers that sender has in
        # 'sender_receivers_cache'. The cache is cleaned when .connect() or
        # .disconnect() is called and populated on send().
        self.sender_receivers_cache = weakref.WeakKeyDictionary() if use_caching else {}
        self._dead_receivers = False

    def connect(self, receiver, sender=None, weak=True, dispatch_uid=None):
        """
        Connect receiver to sender for signal.

        Arguments:

            receiver
                A function or an instance method which is to receive signals.
                Receivers must be hashable objects.

                If weak is True, then receiver must be weak referenceable.

                Receivers must be able to accept keyword arguments.

                If a receiver is connected with a dispatch_uid argument, it
                will not be added if another receiver was already connected
                with that dispatch_uid.

            sender
                The sender to which the receiver should respond. Must either be
                a Python object, or None to receive events from any sender.

       import threading
import weakref

from django.utils.inspect import func_accepts_kwargs


def _make_id(target):
    if hasattr(target, '__func__'):
        return (id(target.__self__), id(target.__func__))
    return id(target)


NONE_ID = _make_id(None)

# A marker for caching
NO_RECEIVERS = object()


class Signal:
    """
    Base class for all signals

    Internal attributes:

        receivers
            { receiverkey (id) : weakref(receiver) }
コード例 #15
0
 def __setitem__(self, key1, key2):
     self.keys1[key1] = None
     self.keys2[key2] = None
     self.keys1[key1] = weakref()
     ...
コード例 #16
0
ファイル: renderer.py プロジェクト: shughes-uk/Jata
 def on_draw(self):
     self.clear()
     self.render_list = [ref for ref in self.render_list if ref()]
     for weakref in self.render_list:
         weakref().draw()