[pygobject] Remove DynamicGLibModule and DynamicGObjectModule
- From: Simon Feltman <sfeltman src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pygobject] Remove DynamicGLibModule and DynamicGObjectModule
- Date: Tue, 6 Nov 2012 08:14:55 +0000 (UTC)
commit 2cbb54e79c23b96486d4a2bfa170460df5bd6c84
Author: Simon Feltman <sfeltman src gnome org>
Date: Mon Nov 5 18:27:56 2012 -0800
Remove DynamicGLibModule and DynamicGObjectModule
Move final bits of _glib static binding imports directly into
the GLib override. Change _glib/option use the .so directly
rather than the staged variables in _glib/__init__.py.
Remove DynamicGLibModule and DynamicGObjectModule and update
unittest.
https://bugzilla.gnome.org/show_bug.cgi?id=687488
gi/_glib/__init__.py | 11 ---------
gi/_glib/option.py | 16 ++++++------
gi/importer.py | 12 +--------
gi/module.py | 60 --------------------------------------------------
gi/overrides/GLib.py | 14 +++++++++++
tests/test_gi.py | 9 +-----
6 files changed, 26 insertions(+), 96 deletions(-)
---
diff --git a/gi/_glib/__init__.py b/gi/_glib/__init__.py
index 14699f0..0b9df9a 100644
--- a/gi/_glib/__init__.py
+++ b/gi/_glib/__init__.py
@@ -23,14 +23,3 @@ from . import _glib
# Internal API
_PyGLib_API = _glib._PyGLib_API
-
-# Types
-GError = _glib.GError
-OptionContext = _glib.OptionContext
-OptionGroup = _glib.OptionGroup
-Pid = _glib.Pid
-PollFD = _glib.PollFD
-
-# Functions
-spawn_async = _glib.spawn_async
-threads_init = _glib.threads_init
diff --git a/gi/_glib/option.py b/gi/_glib/option.py
index b6f5fb8..35de765 100644
--- a/gi/_glib/option.py
+++ b/gi/_glib/option.py
@@ -42,7 +42,7 @@ else:
_basestring = basestring
_bytes = str
-import gi._glib
+from gi._glib import _glib
GLib = get_introspection_module('GLib')
OPTION_CONTEXT_ERROR_QUARK = GLib.quark_to_string(GLib.option_error_quark())
@@ -196,13 +196,13 @@ class OptionGroup(optparse.OptionGroup):
opt.process(option_name, option_value, self.values, parser)
except OptionValueError:
error = sys.exc_info()[1]
- gerror = gi._glib.GError(str(error))
+ gerror = _glib.GError(str(error))
gerror.domain = OPTION_CONTEXT_ERROR_QUARK
gerror.code = GLib.OptionError.BAD_VALUE
gerror.message = str(error)
raise gerror
- group = gi._glib.OptionGroup(self.name, self.description,
+ group = _glib.OptionGroup(self.name, self.description,
self.help_description, callback)
if self.translation_domain:
group.set_translation_domain(self.translation_domain)
@@ -277,12 +277,12 @@ class OptionParser(optparse.OptionParser):
parameter_string = self.usage + " - " + self.description
else:
parameter_string = self.usage
- context = gi._glib.OptionContext(parameter_string)
+ context = _glib.OptionContext(parameter_string)
context.set_help_enabled(self.help_enabled)
context.set_ignore_unknown_options(self.ignore_unknown_options)
for option_group in self.option_groups:
- if isinstance(option_group, gi._glib.OptionGroup):
+ if isinstance(option_group, _glib.OptionGroup):
g_group = option_group
else:
g_group = option_group.get_option_group(self)
@@ -295,7 +295,7 @@ class OptionParser(optparse.OptionParser):
opt = self._short_opt[option_name]
opt.process(option_name, option_value, values, self)
- main_group = gi._glib.OptionGroup(None, None, None, callback)
+ main_group = _glib.OptionGroup(None, None, None, callback)
main_entries = []
for option in self.option_list:
main_entries.extend(option._to_goptionentries())
@@ -315,7 +315,7 @@ class OptionParser(optparse.OptionParser):
args[0].parser = self
if args[0].parser is not self:
raise ValueError("invalid OptionGroup (wrong parser)")
- if isinstance(args[0], gi._glib.OptionGroup):
+ if isinstance(args[0], _glib.OptionGroup):
self.option_groups.append(args[0])
return
optparse.OptionParser.add_option_group(self, *args, **kwargs)
@@ -340,7 +340,7 @@ class OptionParser(optparse.OptionParser):
try:
options, args = optparse.OptionParser.parse_args(
self, args, values)
- except gi._glib.GError:
+ except _glib.GError:
error = sys.exc_info()[1]
if error.domain != OPTION_CONTEXT_ERROR_QUARK:
raise
diff --git a/gi/importer.py b/gi/importer.py
index d83a384..aa95cf6 100644
--- a/gi/importer.py
+++ b/gi/importer.py
@@ -25,7 +25,7 @@ import logging
import sys
from ._gi import Repository
-from .module import DynamicModule, DynamicGObjectModule, DynamicGLibModule
+from .module import DynamicModule
repository = Repository.get_default()
@@ -58,15 +58,7 @@ class DynamicImporter(object):
return sys.modules[fullname]
path, namespace = fullname.rsplit('.', 1)
-
- # Special case GObject and GLib
- if namespace == 'GObject':
- dynamic_module = DynamicGObjectModule()
- elif namespace == "GLib":
- 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 1138871..3d18796 100644
--- a/gi/module.py
+++ b/gi/module.py
@@ -27,7 +27,6 @@ import types
_have_py3 = (sys.version_info[0] >= 3)
-from . import _glib
try:
maketrans = ''.maketrans
except AttributeError:
@@ -332,62 +331,3 @@ class DynamicModule(types.ModuleType):
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
diff --git a/gi/overrides/GLib.py b/gi/overrides/GLib.py
index 4f538c0..ed63679 100644
--- a/gi/overrides/GLib.py
+++ b/gi/overrides/GLib.py
@@ -37,6 +37,20 @@ option # pyflakes
__all__.append('option')
+# Types and functions still needed from static bindings
+from gi._glib import _glib
+GError = _glib.GError
+OptionContext = _glib.OptionContext
+OptionGroup = _glib.OptionGroup
+Pid = _glib.Pid
+PollFD = _glib.PollFD
+spawn_async = _glib.spawn_async
+threads_init = _glib.threads_init
+
+__all__ += ['GError', 'OptionContext', 'OptionGroup', 'Pid', 'PollFD',
+ 'spawn_async', 'threads_init']
+
+
class _VariantCreator(object):
_LEAF_CONSTRUCTORS = {
diff --git a/tests/test_gi.py b/tests/test_gi.py
index 61a84d5..ac2418b 100644
--- a/tests/test_gi.py
+++ b/tests/test_gi.py
@@ -1747,13 +1747,8 @@ class TestPythonGObject(unittest.TestCase):
self.assertEqual(object_.val, 87)
def test_dynamic_module(self):
- from gi.module import DynamicGObjectModule
- self.assertTrue(isinstance(GObject, DynamicGObjectModule))
- # compare the same enum from both the pygobject attrs and gi GObject attrs
- self.assertEqual(GObject.SIGNAL_ACTION, GObject.SignalFlags.ACTION)
- # compare a static gobject attr with a dynamic GObject attr
- import gi._gobject
- self.assertEqual(GObject.GObject, gi._gobject.GObject)
+ from gi.module import DynamicModule
+ self.assertTrue(isinstance(GObject, DynamicModule))
def test_subobject_non_vfunc_do_method(self):
class PythonObjectWithNonVFuncDoMethod:
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]