[pygobject] make GObject and GLib able to take overrides



commit 25d2d05cba05414cd4551e0e06f6286a9b97a509
Author: John (J5) Palmieri <johnp redhat com>
Date:   Fri Jul 22 15:46:31 2011 -0400

    make GObject and GLib able to take overrides
    
    * derive directly from DynamicModule instead of InterfaceModule
    
    https://bugzilla.gnome.org/show_bug.cgi?id=642048

 gi/importer.py |   11 ++---
 gi/module.py   |  118 ++++++++++++++++++++++++++++----------------------------
 2 files changed, 64 insertions(+), 65 deletions(-)
---
diff --git a/gi/importer.py b/gi/importer.py
index 75ba177..62555b1 100644
--- a/gi/importer.py
+++ b/gi/importer.py
@@ -59,15 +59,14 @@ class DynamicImporter(object):
 
         path, namespace = fullname.rsplit('.', 1)
 
-        # Workaround for GObject and GLib
+        # Special case GObject and GLib
         if namespace == 'GObject':
-            sys.modules[fullname] = DynamicGObjectModule()
-            return sys.modules[fullname]
+            dynamic_module = DynamicGObjectModule()
         elif namespace == "GLib":
-            sys.modules[fullname] = DynamicGLibModule()
-            return sys.modules[fullname]
+            dynamic_module = DynamicGLibModule()
+        else:
+            dynamic_module = DynamicModule(namespace)
 
-        dynamic_module = DynamicModule(namespace)
         modules[namespace] = dynamic_module
 
         dynamic_module.__file__ = '<%s>' % fullname
diff --git a/gi/module.py b/gi/module.py
index b5629a1..b749491 100644
--- a/gi/module.py
+++ b/gi/module.py
@@ -23,9 +23,7 @@
 from __future__ import absolute_import
 
 import os
-from . import _gobject
-from . import _glib
-
+from . import _glib, _gobject
 try:
     maketrans = ''.maketrans
 except AttributeError:
@@ -211,62 +209,6 @@ class IntrospectionModule(object):
 
         return list(result)
 
-class DynamicGLibModule(IntrospectionModule):
-    """Wrapper for the internal GLib module
-
-    This class allows us to access both the static internal PyGLib module and the GI GLib module
-    through the same interface.  It is returned when by importing GLib from the gi repository:
-
-    from gi.repository import GLib
-
-    We use this because some PyGI interfaces generated from the GIR require GLib types not wrapped
-    by the static bindings.  This also allows access to module attributes in a way that is more
-    familiar to GI application developers.
-    """
-
-    def __init__(self):
-        IntrospectionModule.__init__(self, namespace='GLib')
-
-    def __getattr__(self, name):
-        # first see if this attr is in the internal _gobject module
-        attr = getattr(_glib, name, None)
-
-        # if not in module assume request for an attr exported through GI
-        if attr is None:
-            attr = super(DynamicGLibModule, self).__getattr__(name)
-
-        return attr
-
-
-class DynamicGObjectModule(IntrospectionModule):
-    """Wrapper for the internal GObject module
-
-    This class allows us to access both the static internal PyGObject module and the GI GObject module
-    through the same interface.  It is returned when by importing GObject from the gi repository:
-
-    from gi.repository import GObject
-
-    We use this because some PyGI interfaces generated from the GIR require GObject types not wrapped
-    by the static bindings.  This also allows access to module attributes in a way that is more
-    familiar to GI application developers.  Take signal flags as an example.  The G_SIGNAL_RUN_FIRST
-    flag would be accessed as GObject.SIGNAL_RUN_FIRST in the static bindings but in the dynamic bindings
-    can be accessed as GObject.SignalFlags.RUN_FIRST.  The latter follows a GI naming convention which
-    would be familiar to GI application developers in a number of languages.
-    """
-
-    def __init__(self):
-        IntrospectionModule.__init__(self, namespace='GObject')
-
-    def __getattr__(self, name):
-        # first see if this attr is in the internal _gobject module
-        attr = getattr(_gobject, name, None)
-
-        # if not in module assume request for an attr exported through GI
-        if attr is None:
-            attr = super(DynamicGObjectModule, self).__getattr__(name)
-
-        return attr
-
 class DynamicModule(object):
     def __init__(self, namespace):
         self._namespace = namespace
@@ -316,3 +258,61 @@ class DynamicModule(object):
                                       self.__class__.__name__,
                                       self._namespace,
                                       path)
+
+class DynamicGObjectModule(DynamicModule):
+    """Wrapper for the internal GObject module
+
+    This class allows us to access both the static internal PyGObject module and the GI GObject module
+    through the same interface.  It is returned when by importing GObject from the gi repository:
+
+    from gi.repository import GObject
+
+    We use this because some PyGI interfaces generated from the GIR require GObject types not wrapped
+    by the static bindings.  This also allows access to module attributes in a way that is more
+    familiar to GI application developers.  Take signal flags as an example.  The G_SIGNAL_RUN_FIRST
+    flag would be accessed as GObject.SIGNAL_RUN_FIRST in the static bindings but in the dynamic bindings
+    can be accessed as GObject.SignalFlags.RUN_FIRST.  The latter follows a GI naming convention which
+    would be familiar to GI application developers in a number of languages.
+    """
+
+    def __init__(self):
+        DynamicModule.__init__(self, namespace='GObject')
+
+    def __getattr__(self, name):
+        from . import _gobject
+
+        # first see if this attr is in the internal _gobject module
+        attr = getattr(_gobject, name, None)
+
+        # if not in module assume request for an attr exported through GI
+        if attr is None:
+            attr = super(DynamicGObjectModule, self).__getattr__(name)
+
+        return attr
+
+
+class DynamicGLibModule(DynamicModule):
+    """Wrapper for the internal GLib module
+
+    This class allows us to access both the static internal PyGLib module and the GI GLib module
+    through the same interface.  It is returned when by importing GLib from the gi repository:
+
+    from gi.repository import GLib
+
+    We use this because some PyGI interfaces generated from the GIR require GLib types not wrapped
+    by the static bindings.  This also allows access to module attributes in a way that is more
+    familiar to GI application developers.
+    """
+
+    def __init__(self):
+        DynamicModule.__init__(self, namespace='GLib')
+
+    def __getattr__(self, name):
+        # first see if this attr is in the internal _gobject module
+        attr = getattr(_glib, name, None)
+
+        # if not in module assume request for an attr exported through GI
+        if attr is None:
+            attr = super(DynamicGLibModule, self).__getattr__(name)
+
+        return attr



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]