Пример #1
0
 def __init__(self, conn, disconnect):
     self.conn = conn
     if not callable(disconnect):
         raise TypeError(CALLABLE_ERROR %
                         ('disconnect', disconnect, type(disconnect)))
     self.disconnect = disconnect
     lock(self)
Пример #2
0
 def __init__(self, conn, disconnect):
     self.conn = conn
     if not callable(disconnect):
         raise TypeError(
            CALLABLE_ERROR % ('disconnect', disconnect, type(disconnect))
         )
     self.disconnect = disconnect
     lock(self)
Пример #3
0
 def __init__(self, p):
     assert isinstance(p, PluginInstance)
     self.created = p.created
     self.name = p.klass.__name__
     self.module = str(p.klass.__module__)
     self.plugin = '%s.%s' % (self.module, self.name)
     self.bases = tuple(b.__name__ for b in p.bases)
     if not is_production_mode(self):
         lock(self)
Пример #4
0
 def __init__(self, p):
     assert isinstance(p, PluginInstance)
     self.created = p.created
     self.name = p.klass.__name__
     self.module = str(p.klass.__module__)
     self.plugin = '%s.%s' % (self.module, self.name)
     self.bases = tuple(b.__name__ for b in p.bases)
     if not is_production_mode(self):
         lock(self)
Пример #5
0
 def __init__(self, s):
     """
     :param s: The target set-like object (a set, frozenset, or dict)
     """
     allowed = (set, frozenset, dict)
     if type(s) not in allowed:
         raise TypeError('%r not in %r' % (type(s), allowed))
     self.__s = s
     if not is_production_mode(self):
         lock(self)
Пример #6
0
 def __init__(self, s):
     """
     :param s: The target set-like object (a set, frozenset, or dict)
     """
     allowed = (set, frozenset, dict)
     if type(s) not in allowed:
         raise TypeError('%r not in %r' % (type(s), allowed))
     self.__s = s
     if not is_production_mode(self):
         lock(self)
Пример #7
0
    def finalize(self):
        """
        Finalize the registration, instantiate the plugins.

        `API.bootstrap` will automatically be called if it hasn't been
        already.
        """
        self.__doing('finalize')
        self.__do_if_not_done('load_plugins')

        production_mode = self.is_production_mode()
        plugins = {}
        plugin_info = {}

        for base in self.bases:
            name = base.__name__
            sub_d = self.__plugins.get(base, {})

            members = []
            for klass in sub_d.itervalues():
                try:
                    instance = plugins[klass]
                except KeyError:
                    instance = plugins[klass] = klass(self)
                members.append(instance)
                plugin_info.setdefault(
                    '%s.%s' % (klass.__module__, klass.__name__),
                    []).append(name)

            if not production_mode:
                assert not hasattr(self, name)
            setattr(self, name, NameSpace(members))

        for klass, instance in plugins.iteritems():
            if not production_mode:
                assert instance.api is self
            if klass.finalize_early or not self.env.plugins_on_demand:
                instance.ensure_finalized()
                if not production_mode:
                    assert islocked(instance)

        self.__finalized = True
        self.plugins = tuple((k, tuple(v)) for k, v in plugin_info.iteritems())

        if not production_mode:
            lock(self)
Пример #8
0
    def finalize(self):
        """
        Finalize plugin initialization.

        This method calls `_on_finalize()` and locks the plugin object.

        Subclasses should not override this method. Custom finalization is done
        in `_on_finalize()`.
        """
        with self.__finalize_lock:
            assert self.__finalized is False
            if self.__finalize_called:
                # No recursive calls!
                return
            self.__finalize_called = True
            self._on_finalize()
            self.__finalized = True
            if not is_production_mode(self):
                lock(self)
Пример #9
0
    def finalize(self):
        """
        Finalize plugin initialization.

        This method calls `_on_finalize()` and locks the plugin object.

        Subclasses should not override this method. Custom finalization is done
        in `_on_finalize()`.
        """
        with self.__finalize_lock:
            assert self.__finalized is False
            if self.__finalize_called:
                # No recursive calls!
                return
            self.__finalize_called = True
            self._on_finalize()
            self.__finalized = True
            if not is_production_mode(self):
                lock(self)