Commit 09c21c79 authored by Laszlo Pandy's avatar Laszlo Pandy
Browse files

In IntrospectionModule and DynamicModule classes, make all instance attributes...

In IntrospectionModule and DynamicModule classes, make all instance attributes start with an underscore.

This changes IntrospectionModule.version to _version and DynamicModule.introspection_module to _introspection_module.
This is done to mark the attributes as private, and also avoid name collisions with attributes from the typelib.
In Gstreamer, there is a function gst_version, which was previously inaccessible because of IntrospectionModule.version overriding it.
parent 2c70beca
......@@ -82,14 +82,14 @@ class IntrospectionModule(object):
def __init__(self, namespace, version=None):
repository.require(namespace, version)
self._namespace = namespace
self.version = version
self._version = version
self.__name__ = 'gi.repository.' + namespace
repository.require(self._namespace, self.version)
repository.require(self._namespace, self._version)
self.__path__ = repository.get_typelib_path(self._namespace)
if self.version is None:
self.version = repository.get_version(self._namespace)
if self._version is None:
self._version = repository.get_version(self._namespace)
def __getattr__(self, name):
info = repository.find_by_name(self._namespace, name)
......@@ -223,27 +223,27 @@ class DynamicGObjectModule(IntrospectionModule):
class DynamicModule(object):
def __init__(self, namespace):
self._namespace = namespace
self.introspection_module = None
self._introspection_module = None
self._version = None
self._overrides_module = None
self.__path__ = None
def require_version(self, version):
if self.introspection_module is not None and \
self.introspection_module.version != version:
if self._introspection_module is not None and \
self._introspection_module._version != version:
raise RuntimeError('Module has been already loaded ')
self._version = version
def _import(self):
self.introspection_module = IntrospectionModule(self._namespace,
self._version)
self._introspection_module = IntrospectionModule(self._namespace,
self._version)
overrides_modules = __import__('gi.overrides', fromlist=[self._namespace])
self._overrides_module = getattr(overrides_modules, self._namespace, None)
self.__path__ = repository.get_typelib_path(self._namespace)
def __getattr__(self, name):
if self.introspection_module is None:
if self._introspection_module is None:
self._import()
if self._overrides_module is not None:
......@@ -260,17 +260,17 @@ class DynamicModule(object):
if key in registry:
return registry[key]
return getattr(self.introspection_module, name)
return getattr(self._introspection_module, name)
def __dir__ (self):
if self.introspection_module is None:
if self._introspection_module is None:
self._import()
# Python's default dir() is just dir(self.__class__) + self.__dict__.keys()
result = set(dir(self.__class__))
result.update(self.__dict__.keys())
result.update(dir(self.introspection_module))
result.update(dir(self._introspection_module))
override_exports = getattr(self._overrides_module, '__all__', ())
result.update(override_exports)
return list(result)
......
......@@ -21,7 +21,7 @@
from ..overrides import override
from ..importer import modules
GIMarshallingTests = modules['GIMarshallingTests'].introspection_module
GIMarshallingTests = modules['GIMarshallingTests']._introspection_module
__all__ = []
......
......@@ -21,7 +21,7 @@
from ..importer import modules
from .._gi import variant_new_tuple, variant_type_from_string
GLib = modules['GLib'].introspection_module
GLib = modules['GLib']._introspection_module
__all__ = []
......
......@@ -22,7 +22,7 @@
from ..overrides import override
from ..importer import modules
Gdk = modules['Gdk'].introspection_module
Gdk = modules['Gdk']._introspection_module
__all__ = []
......@@ -43,7 +43,7 @@ class Color(Gdk.Color):
Color = override(Color)
__all__.append('Color')
if Gdk.version == '2.0':
if Gdk._version == '2.0':
class Rectangle(Gdk.Rectangle):
def __init__(self, x, y, width, height):
......@@ -62,7 +62,7 @@ if Gdk.version == '2.0':
Rectangle = override(Rectangle)
__all__.append('Rectangle')
if Gdk.version == '2.0':
if Gdk._version == '2.0':
class Drawable(Gdk.Drawable):
def cairo_create(self):
return Gdk.cairo_create(self)
......@@ -111,7 +111,7 @@ class Event(Gdk.Event):
Gdk.EventType.VISIBILITY_NOTIFY: 'visibility',
}
if Gdk.version == '2.0':
if Gdk._version == '2.0':
_UNION_MEMBERS[Gdk.EventType.NO_EXPOSE] = 'no_expose'
def __new__(cls, *args, **kwargs):
......@@ -129,7 +129,7 @@ __all__.append('Event')
class DragContext(Gdk.DragContext):
def finish(self, success, del_, time):
Gtk = modules['Gtk'].introspection_module
Gtk = modules['Gtk']._introspection_module
Gtk.drag_finish(self, success, del_, time)
DragContext = override(DragContext)
......
......@@ -32,7 +32,7 @@ else:
_basestring = basestring
_callable = callable
Gtk = modules['Gtk'].introspection_module
Gtk = modules['Gtk']._introspection_module
__all__ = []
class Widget(Gtk.Widget):
......
......@@ -21,7 +21,7 @@
from ..overrides import override
from ..importer import modules
Pango = modules['Pango'].introspection_module
Pango = modules['Pango']._introspection_module
__all__ = []
......
......@@ -44,7 +44,7 @@ class overridefunc(object):
if not hasattr(func, '__info__'):
raise TypeError("func must be an gi function")
from ..importer import modules
self.module = modules[func.__module__].introspection_module
self.module = modules[func.__module__]._introspection_module
def __call__(self, func):
def wrapper(*args, **kwargs):
......
......@@ -145,7 +145,7 @@ class TestEverything(unittest.TestCase):
# test that instance members are listed
self.assertTrue('_namespace' in attr_list)
self.assertTrue('version' in attr_list)
self.assertTrue('_version' in attr_list)
# test that there are no duplicates returned
self.assertEqual(len(attr_list), len(set(attr_list)))
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment