[pygobject/gsoc2009: 38/160] Get rid of gi.repository
- From: Simon van der Linden <svdlinden src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [pygobject/gsoc2009: 38/160] Get rid of gi.repository
- Date: Fri, 14 Aug 2009 21:25:17 +0000 (UTC)
commit 2e2be5739c6a8dd67671ca0733dc1a73925317af
Author: Simon van der Linden <svdlinden src gnome org>
Date: Tue Jul 14 16:18:44 2009 +0200
Get rid of gi.repository
The only interesting feature of the module was the modules cache, which can be
implemented directly in the importer.
The ref. count of the repository in _wrap_g_irepository_get_default must be
incremented before returning the object, since we keep a static reference.
I also offered _wrap_g_irepository_get_default a little style enhancement.
gi/Makefile.am | 1 -
gi/importer.py | 27 +++++++++++++++++-------
gi/module.py | 19 ++++++++++-------
gi/pygirepository.c | 19 +++++++++--------
gi/repository.py | 54 ---------------------------------------------------
gi/types.py | 1 -
6 files changed, 40 insertions(+), 81 deletions(-)
---
diff --git a/gi/Makefile.am b/gi/Makefile.am
index f48d610..afad920 100644
--- a/gi/Makefile.am
+++ b/gi/Makefile.am
@@ -19,7 +19,6 @@ pkgpyexecdir = $(pyexecdir)/gtk-2.0/gi
pygidir = $(pkgpyexecdir)
pygi_PYTHON = \
types.py \
- repository.py \
module.py \
importer.py \
__init__.py
diff --git a/gi/importer.py b/gi/importer.py
index 35950ff..7ef4fab 100644
--- a/gi/importer.py
+++ b/gi/importer.py
@@ -21,10 +21,18 @@
# USA
import sys
+import gobject
-from .repository import repository
+from ._gi import Repository
from .module import DynamicModule
+
+repository = Repository.get_default()
+modules = {
+ 'GObject': gobject
+}
+
+
class DynamicImporter(object):
def __init__(self, name, path):
self.name = name
@@ -39,17 +47,20 @@ class DynamicImporter(object):
return DynamicImporter(name, path)
def load_module(self, name):
- module = repository.get_module(name)
- if module is not None:
- return module
+ if name in modules:
+ return modules[name]
module_name = 'gi.overrides.%s' % (name,)
try:
- module = __import__(module_name, {}, {}, ['%sModule' % (name,)])
- modtype = getattr(module, name + 'Module')
+ overrides_module = __import__(module_name, {}, {}, ['%sModule' % (name,)])
+ module_type = getattr(overrides_module, name + 'Module')
except ImportError, e:
- modtype = DynamicModule
- return modtype(name, self.path)
+ module_type = DynamicModule
+
+ module = module_type(name, self.path)
+ modules[name] = module
+
+ return module
def install_importhook():
diff --git a/gi/module.py b/gi/module.py
index 00020d6..4e1c616 100644
--- a/gi/module.py
+++ b/gi/module.py
@@ -28,8 +28,8 @@ from gobject import \
GInterface, \
GEnum
-from .repository import repository
from ._gi import \
+ Repository, \
UnresolvedInfo, \
FunctionInfo, \
RegisteredTypeInfo, \
@@ -44,6 +44,9 @@ from .types import \
Function
+repository = Repository.get_default()
+
+
def get_parent_for_object(object_info):
parent_object_info = object_info.getParent()
@@ -51,14 +54,15 @@ def get_parent_for_object(object_info):
return object
namespace = parent_object_info.getNamespace()
+ name = parent_object_info.getName()
+
+ module = __import__(namespace)
+
if isinstance(parent_object_info, UnresolvedInfo):
- # Import the module and try again.
- __import__(namespace)
+ # The module has been imported, try again.
parent_object_info = object_info.getParent()
- module = repository.get_module(namespace)
- name = parent_object_info.getName()
- # Workaround for gobject.Object.
+ # Workaround for gobject.Object and gobject.InitiallyUnowned.
if module == gobject and name == 'Object' or name == 'InitiallyUnowned':
return GObject
@@ -70,7 +74,6 @@ class DynamicModule(object):
def __init__(self, namespace, path):
self._namespace = namespace
self._path = path
- repository.register(self, namespace, path)
@property
def __file__(self):
@@ -88,7 +91,7 @@ class DynamicModule(object):
return "<dyn-module %r from %r>" % (self._namespace, self._path)
def __getattr__(self, name):
- info = repository.get_by_name(self._namespace, name)
+ info = repository.find_by_name(self._namespace, name)
if not info:
raise AttributeError("%r object has no attribute %r" % (
self.__class__.__name__, name))
diff --git a/gi/pygirepository.c b/gi/pygirepository.c
index a7a6ef4..c640b51 100644
--- a/gi/pygirepository.c
+++ b/gi/pygirepository.c
@@ -199,20 +199,21 @@ _wrap_g_irepository_get_c_prefix(PyGIRepository *self,
}
static PyObject *
-_wrap_g_irepository_get_default(PyObject *_)
+_wrap_g_irepository_get_default(PyObject *self)
{
- static PyGIRepository *self = NULL;
+ static PyGIRepository *repository = NULL;
- if (!self) {
- self = (PyGIRepository *)PyObject_New(PyGIRepository,
- &PyGIRepository_Type);
- if (self == NULL)
- return NULL;
+ if (!repository) {
+ repository = (PyGIRepository *)PyObject_New(PyGIRepository, &PyGIRepository_Type);
+ if (repository == NULL) {
+ return NULL;
+ }
- self->repository = g_irepository_get_default();
+ repository->repository = g_irepository_get_default();
}
- return (PyObject*)self;
+ Py_INCREF((PyObject *)repository);
+ return (PyObject *)repository;
}
static PyMethodDef _PyGIRepository_methods[] = {
diff --git a/gi/types.py b/gi/types.py
index b00bc62..682b4ad 100644
--- a/gi/types.py
+++ b/gi/types.py
@@ -30,7 +30,6 @@ from ._gi import \
ObjectInfo, \
StructInfo, \
EnumInfo
-from .repository import repository
def Function(info):
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]