[pygobject] refactor gi module to import and use internal _gobject module
- From: John Palmieri <johnp src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pygobject] refactor gi module to import and use internal _gobject module
- Date: Thu, 11 Aug 2011 12:48:35 +0000 (UTC)
commit 59ed1289f76bc287443b3974710ea0da3e2cc8cc
Author: John (J5) Palmieri <johnp redhat com>
Date: Fri Jul 22 11:07:10 2011 -0400
refactor gi module to import and use internal _gobject module
https://bugzilla.gnome.org/show_bug.cgi?id=642048
gi/importer.py | 2 --
gi/module.py | 31 ++++++++++++++++---------------
gi/overrides/Gtk.py | 2 +-
gi/overrides/__init__.py | 6 +++---
gi/pygobject-external.h | 2 +-
gi/types.py | 12 ++++++------
6 files changed, 27 insertions(+), 28 deletions(-)
---
diff --git a/gi/importer.py b/gi/importer.py
index df08274..180d1c3 100644
--- a/gi/importer.py
+++ b/gi/importer.py
@@ -24,8 +24,6 @@ from __future__ import absolute_import
import logging
import sys
-import gobject
-
from ._gi import Repository, RepositoryError
from .module import DynamicModule, DynamicGObjectModule
diff --git a/gi/module.py b/gi/module.py
index d56bdaf..4493bd0 100644
--- a/gi/module.py
+++ b/gi/module.py
@@ -23,7 +23,8 @@
from __future__ import absolute_import
import os
-import gobject
+from . import _gobject
+
try:
maketrans = ''.maketrans
except AttributeError:
@@ -67,7 +68,7 @@ def get_parent_for_object(object_info):
# Workaround for GObject.Object and GObject.InitiallyUnowned.
if namespace == 'GObject' and name == 'Object' or name == 'InitiallyUnowned':
- return gobject.GObject
+ return _gobject.GObject
module = __import__('gi.repository.%s' % namespace, fromlist=[name])
return getattr(module, name)
@@ -110,16 +111,16 @@ class IntrospectionModule(object):
if wrapper is None:
if info.is_flags():
- if g_type.is_a(gobject.TYPE_FLAGS):
+ if g_type.is_a(_gobject.TYPE_FLAGS):
wrapper = flags_add(g_type)
else:
- assert g_type == gobject.TYPE_NONE
+ assert g_type == _gobject.TYPE_NONE
wrapper = flags_register_new_gtype_and_add(info)
else:
- if g_type.is_a(gobject.TYPE_ENUM):
+ if g_type.is_a(_gobject.TYPE_ENUM):
wrapper = enum_add(g_type)
else:
- assert g_type == gobject.TYPE_NONE
+ assert g_type == _gobject.TYPE_NONE
wrapper = enum_register_new_gtype_and_add(info)
wrapper.__info__ = info
@@ -135,14 +136,14 @@ class IntrospectionModule(object):
value_name = value_info.get_name().translate(ascii_upper_trans)
setattr(wrapper, value_name, wrapper(value_info.get_value()))
- if g_type != gobject.TYPE_NONE:
+ if g_type != _gobject.TYPE_NONE:
g_type.pytype = wrapper
elif isinstance(info, RegisteredTypeInfo):
g_type = info.get_g_type()
# Check if there is already a Python wrapper.
- if g_type != gobject.TYPE_NONE:
+ if g_type != _gobject.TYPE_NONE:
type_ = g_type.pytype
if type_ is not None:
self.__dict__[name] = type_
@@ -156,13 +157,13 @@ class IntrospectionModule(object):
bases = (parent,) + interfaces
metaclass = GObjectMeta
elif isinstance(info, InterfaceInfo):
- bases = (gobject.GInterface,)
+ bases = (_gobject.GInterface,)
metaclass = GObjectMeta
elif isinstance(info, (StructInfo, UnionInfo)):
- if g_type.is_a(gobject.TYPE_BOXED):
+ if g_type.is_a(_gobject.TYPE_BOXED):
bases = (Boxed,)
- elif g_type.is_a(gobject.TYPE_POINTER) or \
- g_type == gobject.TYPE_NONE or \
+ elif g_type.is_a(_gobject.TYPE_POINTER) or \
+ g_type == _gobject.TYPE_NONE or \
g_type.fundamental == g_type:
bases = (Struct,)
else:
@@ -180,7 +181,7 @@ class IntrospectionModule(object):
wrapper = metaclass(name, bases, dict_)
# Register the new Python wrapper.
- if g_type != gobject.TYPE_NONE:
+ if g_type != _gobject.TYPE_NONE:
g_type.pytype = wrapper
elif isinstance(info, FunctionInfo):
@@ -230,8 +231,8 @@ class DynamicGObjectModule(IntrospectionModule):
IntrospectionModule.__init__(self, namespace='GObject')
def __getattr__(self, name):
- # first see if this attr is in the gobject module
- attr = getattr(gobject, name, None)
+ # 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:
diff --git a/gi/overrides/Gtk.py b/gi/overrides/Gtk.py
index 9c35b06..84660eb 100644
--- a/gi/overrides/Gtk.py
+++ b/gi/overrides/Gtk.py
@@ -20,7 +20,7 @@
# USA
import sys
-import gobject
+from gi import _gobject
from gi.repository import GObject
from ..overrides import override
from ..importer import modules
diff --git a/gi/overrides/__init__.py b/gi/overrides/__init__.py
index a98974f..ce98538 100644
--- a/gi/overrides/__init__.py
+++ b/gi/overrides/__init__.py
@@ -1,7 +1,7 @@
import sys
import types
-import gobject
+from gi import _gobject
registry = None
class _Registry(dict):
@@ -25,8 +25,8 @@ class _Registry(dict):
raise KeyError('You have tried to modify the registry outside of the overrides module. This is not allowed')
g_type = info.get_g_type()
- assert g_type != gobject.TYPE_NONE
- if g_type != gobject.TYPE_INVALID:
+ assert g_type != _gobject.TYPE_NONE
+ if g_type != _gobject.TYPE_INVALID:
g_type.pytype = value
# strip gi.overrides from module name
diff --git a/gi/pygobject-external.h b/gi/pygobject-external.h
index 00b8b6f..4d873bc 100644
--- a/gi/pygobject-external.h
+++ b/gi/pygobject-external.h
@@ -50,7 +50,7 @@ _pygobject_import (void)
return -1;
}
- module = PyImport_ImportModuleEx ("gobject", NULL, NULL, from_list);
+ module = PyImport_ImportModuleEx ("gi._gobject", NULL, NULL, from_list);
Py_DECREF (from_list);
diff --git a/gi/types.py b/gi/types.py
index 9241a65..00e0568 100644
--- a/gi/types.py
+++ b/gi/types.py
@@ -23,7 +23,7 @@
from __future__ import absolute_import
import sys
-import gobject
+from . import _gobject
from ._gi import \
InterfaceInfo, \
@@ -172,8 +172,8 @@ def find_vfunc_info_in_interface(bases, vfunc_name):
# This can be seen in IntrospectionModule.__getattr__() in module.py.
# We do not need to search regular classes here, only wrapped interfaces.
# We also skip GInterface, because it is not wrapped and has no __info__ attr.
- if base is gobject.GInterface or\
- not issubclass(base, gobject.GInterface) or\
+ if base is _gobject.GInterface or\
+ not issubclass(base, _gobject.GInterface) or\
not isinstance(base.__info__, InterfaceInfo):
continue
@@ -203,7 +203,7 @@ def find_vfunc_conflict_in_bases(vfunc, bases):
return aklass
return None
-class GObjectMeta(gobject.GObjectMeta, MetaClassHelper):
+class GObjectMeta(_gobject.GObjectMeta, MetaClassHelper):
def __init__(cls, name, bases, dict_):
super(GObjectMeta, cls).__init__(name, bases, dict_)
@@ -250,7 +250,7 @@ def mro(C):
for subclass_bases in bases_of_subclasses:
candidate = subclass_bases[0]
not_head = [s for s in bases_of_subclasses if candidate in s[1:]]
- if not_head and gobject.GInterface not in candidate.__bases__:
+ if not_head and _gobject.GInterface not in candidate.__bases__:
candidate = None # conflict, reject candidate
else:
break
@@ -277,7 +277,7 @@ class StructMeta(type, MetaClassHelper):
# Avoid touching anything else than the base class.
g_type = cls.__info__.get_g_type()
- if g_type != gobject.TYPE_INVALID and g_type.pytype is not None:
+ if g_type != _gobject.TYPE_INVALID and g_type.pytype is not None:
return
cls._setup_fields()
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]