[pygobject] Add a __repr__() method to DynamicModule.



commit 4992dca9f5cea68d85eb2ed86105c9c6b8311d79
Author: Laszlo Pandy <laszlok2 gmail com>
Date:   Tue Jan 11 19:30:38 2011 +0100

    Add a __repr__() method to DynamicModule.
    
    This patch adds a __repr__() method to DynamicModule so that modules provide a
    meaningful string with the typelib path included:
    
    >>> from gi.repository import Gtk
    >>> Gtk
    <gi.module.DynamicModule 'Gtk' from
    '/home/laszlo/Dev/gnome-jh-install/lib64/girepository-1.0/Gtk-3.0.typelib'>
    
    https://bugzilla.gnome.org/show_bug.cgi?id=639232

 gi/module.py |    9 +++++++++
 1 files changed, 9 insertions(+), 0 deletions(-)
---
diff --git a/gi/module.py b/gi/module.py
index 3586eac..126d2d7 100644
--- a/gi/module.py
+++ b/gi/module.py
@@ -260,3 +260,12 @@ class DynamicModule(object):
         result = [info.get_name() for info in namespace_infos]
         result.extend(self.__dict__.keys())
         return result
+
+    def __repr__(self):
+        repository.require(self._namespace, self._version)
+
+        path = repository.get_typelib_path(self._namespace)
+        return "<%s.%s %r from %r>" % (self.__class__.__module__,
+                                      self.__class__.__name__,
+                                      self._namespace,
+                                      path)



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