示例#1
0
 def test_ensureWhenNotImportedDontPrevent(self):
     """
     If the specified modules have never been imported, and import
     prevention is not requested, L{ensureNotImported} has no effect.
     """
     modules = {}
     self.patch(sys, "modules", modules)
     ensureNotImported(["m1", "m2"], "A message.")
     self.assertEqual(modules, {})
示例#2
0
 def test_ensureWhenFailedToImport(self):
     """
     If the specified modules have been set to L{None} in C{sys.modules},
     L{ensureNotImported} does not complain.
     """
     modules = {"m2": None}
     self.patch(sys, "modules", modules)
     ensureNotImported(["m1", "m2"], "A message.", preventImports=["m1", "m2"])
     self.assertEqual(modules, {"m1": None, "m2": None})
示例#3
0
 def test_ensureWhenFailedToImport(self):
     """
     If the specified modules have been set to C{None} in C{sys.modules},
     L{ensureNotImported} does not complain.
     """
     modules = {"m2": None}
     self.patch(sys, "modules", modules)
     ensureNotImported(["m1", "m2"], "A message.", preventImports=["m1", "m2"])
     self.assertEqual(modules, {"m1": None, "m2": None})
示例#4
0
 def test_ensureWhenNotImportedDontPrevent(self):
     """
     If the specified modules have never been imported, and import
     prevention is not requested, L{ensureNotImported} has no effect.
     """
     modules = {}
     self.patch(sys, "modules", modules)
     ensureNotImported(["m1", "m2"], "A message.")
     self.assertEqual(modules, {})
示例#5
0
 def test_ensureWhenNotImported(self):
     """
     If the specified modules have never been imported, and import
     prevention is requested, L{ensureNotImported} makes sure they will not
     be imported in the future.
     """
     modules = {}
     self.patch(sys, "modules", modules)
     ensureNotImported(["m1", "m2"], "A message.", preventImports=["m1", "m2", "m3"])
     self.assertEqual(modules, {"m1": None, "m2": None, "m3": None})
示例#6
0
 def test_ensureWhenNotImported(self):
     """
     If the specified modules have never been imported, and import
     prevention is requested, L{ensureNotImported} makes sure they will not
     be imported in the future.
     """
     modules = {}
     self.patch(sys, "modules", modules)
     ensureNotImported(["m1", "m2"], "A message.", preventImports=["m1", "m2", "m3"])
     self.assertEquals(modules, {"m1": None, "m2": None, "m3": None})
示例#7
0
def _oldGiInit():
    """
    Make sure pygtk and gi aren't loaded at the same time, and import Glib if
    possible.
    """
    # We can't immediately prevent imports, because that confuses some buggy
    # code in gi:
    _glibbase.ensureNotImported(
        _PYGTK_MODULES,
        "Introspected and static glib/gtk bindings must not be mixed; can't "
        "import gireactor since pygtk2 module is already imported.")

    global GLib
    from gi.repository import GLib
    if getattr(GLib, "threads_init", None) is not None:
        GLib.threads_init()

    _glibbase.ensureNotImported([], "", preventImports=_PYGTK_MODULES)
示例#8
0
def _oldGiInit():
    """
    Make sure pygtk and gi aren't loaded at the same time, and import Glib if
    possible.
    """
    # We can't immediately prevent imports, because that confuses some buggy
    # code in gi:
    _glibbase.ensureNotImported(
        _PYGTK_MODULES,
        "Introspected and static glib/gtk bindings must not be mixed; can't "
        "import gireactor since pygtk2 module is already imported.")

    global GLib
    from gi.repository import GLib
    if getattr(GLib, "threads_init", None) is not None:
        GLib.threads_init()

    _glibbase.ensureNotImported([], "",
                                preventImports=_PYGTK_MODULES)
示例#9
0
    gtk2reactor.install()

Then use twisted.internet APIs as usual.  The other methods here are not
intended to be called directly.
"""

# System Imports
import sys

# Twisted Imports
from twisted.internet import _glibbase
from twisted.python import runtime

_glibbase.ensureNotImported(
    ["gi"],
    "Introspected and static glib/gtk bindings must not be mixed; can't "
    "import gtk2reactor since gi module is already imported.",
    preventImports=["gi"])

try:
    if not hasattr(sys, 'frozen'):
        # Don't want to check this for py2exe
        import pygtk
        pygtk.require('2.0')
except (ImportError, AttributeError):
    pass  # maybe we're using pygtk before this hack existed.

import gobject
if hasattr(gobject, "threads_init"):
    # recent versions of python-gtk expose this. python-gtk=2.4.1
    # (wrapping glib-2.4.7) does. python-gtk=2.0.0 (wrapping
示例#10
0
    from twisted.internet import gireactor
    gireactor.install()

Then use twisted.internet APIs as usual.  The other methods here are not
intended to be called directly.
"""

import sys
from twisted.internet import _glibbase
from twisted.python import runtime

# We can't immediately prevent imports, because that confuses some buggy code
# in gi:
_glibbase.ensureNotImported(
    ['gobject' 'glib', 'gio', 'gtk'],
    "Introspected and static glib/gtk bindings must not be mixed; can't "
    "import gireactor since pygtk2 module is already imported.")

from gi.repository import GLib
GLib.threads_init()

_glibbase.ensureNotImported([], "",
                            preventImports=['gobject' 'glib', 'gio', 'gtk'])



class GIReactor(_glibbase.GlibReactorBase):
    """
    GObject-introspection event loop reactor.
    """
    _POLL_DISCONNECTED = (GLib.IOCondition.HUP | GLib.IOCondition.ERR |
示例#11
0
    from twisted.internet import reactor
    reactor.registerGApplication(app)

Then use twisted.internet APIs as usual.
"""

import sys
from twisted.internet.error import ReactorAlreadyRunning
from twisted.internet import _glibbase
from twisted.python import runtime

# We can't immediately prevent imports, because that confuses some buggy code
# in gi:
_glibbase.ensureNotImported(
    ['gobject' 'glib', 'gio', 'gtk'],
    "Introspected and static glib/gtk bindings must not be mixed; can't "
    "import gireactor since pygtk2 module is already imported.")

from gi.repository import GLib
GLib.threads_init()

_glibbase.ensureNotImported([], "",
                            preventImports=['gobject' 'glib', 'gio', 'gtk'])



class GIReactor(_glibbase.GlibReactorBase):
    """
    GObject-introspection event loop reactor.

    @ivar _gapplication: A C{Gio.Application} instance that was registered