[pygobject/gsoc2009: 88/160] Honour underscore notation



commit 19cf9dfbfb1987c331719e14c9a74ec2d94787b3
Author: Simon van der Linden <svdlinden src gnome org>
Date:   Mon Aug 3 13:03:57 2009 +0200

    Honour underscore notation

 gi/module.py               |   28 ++++++++++++++--------------
 gi/pygiinfo.c              |   40 +++++++++++++++++++++-------------------
 gi/types.py                |   36 ++++++++++++++++++------------------
 tests/test_girepository.py |    2 +-
 4 files changed, 54 insertions(+), 52 deletions(-)
---
diff --git a/gi/module.py b/gi/module.py
index 1edce01..a4d2663 100644
--- a/gi/module.py
+++ b/gi/module.py
@@ -46,13 +46,13 @@ repository = Repository.get_default()
 
 
 def get_parent_for_object(object_info):
-    parent_object_info = object_info.getParent()
+    parent_object_info = object_info.get_parent()
 
     if not parent_object_info:
         return object
 
-    namespace = parent_object_info.getNamespace()
-    name = parent_object_info.getName()
+    namespace = parent_object_info.get_namespace()
+    name = parent_object_info.get_name()
 
     # Workaround for GObject.Object and GObject.InitiallyUnowned.
     if namespace == 'GObject' and name == 'Object' or name == 'InitiallyUnowned':
@@ -77,14 +77,14 @@ class DynamicModule(object):
         if isinstance(info, StructInfo):
             # FIXME: This could be wrong for structures that are registered (like GValue or GClosure).
             bases = (GIStruct,)
-            name = info.getName()
+            name = info.get_name()
             dict_ = {
                 '__info__': info,
-                '__module__': info.getNamespace()
+                '__module__': info.get_namespace()
             }
             value = GObjectIntrospectionMeta(name, bases, dict_)
         elif isinstance(info, EnumInfo):
-            type_ = info.getGType()
+            type_ = info.get_g_type()
             if type_.is_a(gobject.TYPE_ENUM):
                 value = gobject.enum_from_g_type(type_)
             elif type_.is_a(gobject.TYPE_FLAGS):
@@ -92,15 +92,15 @@ class DynamicModule(object):
             else:
                 raise TypeError, "Must be a subtype of either gobject.TYPE_ENUM, or gobject.TYPE_FLAGS"
             value.__info__ = info
-            value.__module__ = info.getNamespace()
+            value.__module__ = info.get_namespace()
 
-            for value_info in info.getValues():
-                name = value_info.getName().upper()
-                setattr(value, name, value(value_info.getValue()))
+            for value_info in info.get_values():
+                name = value_info.get_name().upper()
+                setattr(value, name, value(value_info.get_value()))
 
         elif isinstance(info, RegisteredTypeInfo):
             # Check if there is already a Python wrapper.
-            gtype = info.getGType()
+            gtype = info.get_g_type()
             if gtype.pytype is not None:
                 self.__dict__[name] = gtype.pytype
                 return
@@ -114,10 +114,10 @@ class DynamicModule(object):
             else:
                 raise NotImplementedError(info)
 
-            name = info.getName()
+            name = info.get_name()
             dict_ = {
                 '__info__': info,
-                '__module__': info.getNamespace(),
+                '__module__': info.get_namespace(),
                 '__gtype__': gtype
             }
             value = GObjectIntrospectionMeta(name, bases, dict_)
@@ -136,6 +136,6 @@ class DynamicModule(object):
         for type_info in repository.get_infos(self.__namespace__):
             if type_info is None:
                 continue
-            r.append(type_info.getName())
+            r.append(type_info.get_name())
         return r
 
diff --git a/gi/pygiinfo.c b/gi/pygiinfo.c
index af4dc58..7346b4e 100644
--- a/gi/pygiinfo.c
+++ b/gi/pygiinfo.c
@@ -197,8 +197,8 @@ _wrap_g_base_info_get_namespace(PyGIBaseInfo *self)
 }
 
 static PyMethodDef _PyGIBaseInfo_methods[] = {
-    { "getName", (PyCFunction)_wrap_g_base_info_get_name, METH_NOARGS },
-    { "getNamespace", (PyCFunction)_wrap_g_base_info_get_namespace, METH_NOARGS },
+    { "get_name", (PyCFunction)_wrap_g_base_info_get_name, METH_NOARGS },
+    { "get_namespace", (PyCFunction)_wrap_g_base_info_get_namespace, METH_NOARGS },
     { NULL, NULL, 0 }
 };
 
@@ -319,6 +319,7 @@ pygi_gi_base_info_get_fullname(GIBaseInfo *info) {
     return fullname;
 }
 
+
 /* CallableInfo */
 PYGIINFO_DEFINE_TYPE("CallableInfo", GICallableInfo, PyGIBaseInfo_Type);
 
@@ -326,6 +327,7 @@ static PyMethodDef _PyGICallableInfo_methods[] = {
     { NULL, NULL, 0 }
 };
 
+
 /* FunctionInfo */
 PYGIINFO_DEFINE_TYPE("FunctionInfo", GIFunctionInfo, PyGICallableInfo_Type);
 
@@ -1022,8 +1024,8 @@ return_:
 }
 
 static PyMethodDef _PyGIFunctionInfo_methods[] = {
-    { "isConstructor", (PyCFunction)_wrap_g_function_info_is_constructor, METH_NOARGS },
-    { "isMethod", (PyCFunction)_wrap_g_function_info_is_method, METH_NOARGS },
+    { "is_constructor", (PyCFunction)_wrap_g_function_info_is_constructor, METH_NOARGS },
+    { "is_method", (PyCFunction)_wrap_g_function_info_is_method, METH_NOARGS },
     { "invoke", (PyCFunction)_wrap_g_function_info_invoke, METH_VARARGS },
     { NULL, NULL, 0 }
 };
@@ -1041,7 +1043,7 @@ _wrap_g_registered_type_info_get_g_type (PyGIBaseInfo* self)
 }
 
 static PyMethodDef _PyGIRegisteredTypeInfo_methods[] = {
-    { "getGType", (PyCFunction)_wrap_g_registered_type_info_get_g_type, METH_NOARGS },
+    { "get_g_type", (PyCFunction)_wrap_g_registered_type_info_get_g_type, METH_NOARGS },
     { NULL, NULL, 0 }
 };
 
@@ -1100,9 +1102,9 @@ _wrap_g_struct_info_new_buffer(PyGIBaseInfo *self)
 }
 
 static PyMethodDef _PyGIStructInfo_methods[] = {
-    { "getFields", (PyCFunction)_wrap_g_struct_info_get_fields, METH_NOARGS },
-    { "getMethods", (PyCFunction)_wrap_g_struct_info_get_methods, METH_NOARGS },
-    { "newBuffer", (PyCFunction)_wrap_g_struct_info_new_buffer, METH_NOARGS },
+    { "get_fields", (PyCFunction)_wrap_g_struct_info_get_fields, METH_NOARGS },
+    { "get_methods", (PyCFunction)_wrap_g_struct_info_get_methods, METH_NOARGS },
+    { "new_buffer", (PyCFunction)_wrap_g_struct_info_new_buffer, METH_NOARGS },
     { NULL, NULL, 0 }
 };
 
@@ -1131,7 +1133,7 @@ _wrap_g_enum_info_get_values(PyGIBaseInfo *self)
 }
 
 static PyMethodDef _PyGIEnumInfo_methods[] = {
-    { "getValues", (PyCFunction)_wrap_g_enum_info_get_values, METH_NOARGS },
+    { "get_values", (PyCFunction)_wrap_g_enum_info_get_values, METH_NOARGS },
     { NULL, NULL, 0 }
 };
 
@@ -1218,10 +1220,10 @@ _wrap_g_object_info_get_interfaces(PyGIBaseInfo *self)
 }
 
 static PyMethodDef _PyGIObjectInfo_methods[] = {
-    { "getParent", (PyCFunction)_wrap_g_object_info_get_parent, METH_NOARGS },
-    { "getMethods", (PyCFunction)_wrap_g_object_info_get_methods, METH_NOARGS },
-    { "getFields", (PyCFunction)_wrap_g_object_info_get_fields, METH_NOARGS },
-    { "getInterfaces", (PyCFunction)_wrap_g_object_info_get_interfaces, METH_NOARGS },
+    { "get_parent", (PyCFunction)_wrap_g_object_info_get_parent, METH_NOARGS },
+    { "get_methods", (PyCFunction)_wrap_g_object_info_get_methods, METH_NOARGS },
+    { "get_fields", (PyCFunction)_wrap_g_object_info_get_fields, METH_NOARGS },
+    { "get_interfaces", (PyCFunction)_wrap_g_object_info_get_interfaces, METH_NOARGS },
     { NULL, NULL, 0 }
 };
 
@@ -1308,7 +1310,7 @@ _wrap_g_interface_info_register(PyGIBaseInfo *self)
 }
 
 static PyMethodDef _PyGIInterfaceInfo_methods[] = {
-    { "getMethods", (PyCFunction)_wrap_g_interface_info_get_methods, METH_NOARGS },
+    { "get_methods", (PyCFunction)_wrap_g_interface_info_get_methods, METH_NOARGS },
     { "register", (PyCFunction)_wrap_g_interface_info_register, METH_NOARGS },
     { NULL, NULL, 0 }
 };
@@ -1331,7 +1333,7 @@ _wrap_g_value_info_get_value(PyGIBaseInfo *self)
 
 
 static PyMethodDef _PyGIValueInfo_methods[] = {
-    { "getValue", (PyCFunction)_wrap_g_value_info_get_value, METH_NOARGS },
+    { "get_value", (PyCFunction)_wrap_g_value_info_get_value, METH_NOARGS },
     { NULL, NULL, 0 }
 };
 
@@ -1352,7 +1354,7 @@ _wrap_g_field_info_get_value(PyGIBaseInfo *self, PyObject *args)
 
     retval = NULL;
 
-    if (!PyArg_ParseTuple(args, "O:FieldInfo.getValue", &object)) {
+    if (!PyArg_ParseTuple(args, "O:FieldInfo.get_value", &object)) {
         return NULL;
     }
 
@@ -1451,7 +1453,7 @@ _wrap_g_field_info_set_value(PyGIBaseInfo *self, PyObject *args)
 
     retval = NULL;
 
-    if (!PyArg_ParseTuple(args, "OO:FieldInfo.setValue", &object, &py_value)) {
+    if (!PyArg_ParseTuple(args, "OO:FieldInfo.set_value", &object, &py_value)) {
         return NULL;
     }
 
@@ -1542,8 +1544,8 @@ return_:
 }
 
 static PyMethodDef _PyGIFieldInfo_methods[] = {
-    { "getValue", (PyCFunction)_wrap_g_field_info_get_value, METH_VARARGS },
-    { "setValue", (PyCFunction)_wrap_g_field_info_set_value, METH_VARARGS },
+    { "get_value", (PyCFunction)_wrap_g_field_info_get_value, METH_VARARGS },
+    { "set_value", (PyCFunction)_wrap_g_field_info_set_value, METH_VARARGS },
     { NULL, NULL, 0 }
 };
 
diff --git a/gi/types.py b/gi/types.py
index 00198ef..0dbadb2 100644
--- a/gi/types.py
+++ b/gi/types.py
@@ -36,8 +36,8 @@ def Function(info):
     def function(*args):
         return info.invoke(*args)
     function.__info__ = info
-    function.__name__ = info.getName()
-    function.__module__ = info.getNamespace()
+    function.__name__ = info.get_name()
+    function.__module__ = info.get_namespace()
 
     return function
 
@@ -48,10 +48,10 @@ class Field(object):
         self.info = info
 
     def __get__(self, instance, owner):
-        return self.info.getValue(instance)
+        return self.info.get_value(instance)
 
     def __set__(self, instance, value):
-        return self.info.setValue(instance, value)
+        return self.info.set_value(instance, value)
 
 
 class GObjectIntrospectionMeta(gobject.GObjectMeta):
@@ -63,7 +63,7 @@ class GObjectIntrospectionMeta(gobject.GObjectMeta):
             setObjectHasNewConstructor(cls.__gtype__)
 
         # Only set up the wrapper methods and fields in their base classes.
-        if cls.__name__ == cls.__info__.getName():
+        if cls.__name__ == cls.__info__.get_name():
             if isinstance(cls.__info__, InterfaceInfo):
                 cls._setup_methods()
 
@@ -77,22 +77,22 @@ class GObjectIntrospectionMeta(gobject.GObjectMeta):
 
     def _setup_methods(cls):
         constructor_infos = []
-        method_infos = cls.__info__.getMethods()
-        if hasattr(cls.__info__, 'getInterfaces'):
-            method_infos += reduce(lambda x, y: x + y, [interface_info.getMethods() for interface_info in cls.__info__.getInterfaces()], ())
+        method_infos = cls.__info__.get_methods()
+        if hasattr(cls.__info__, 'get_interfaces'):
+            method_infos += reduce(lambda x, y: x + y, [interface_info.get_methods() for interface_info in cls.__info__.get_interfaces()], ())
 
         for method_info in method_infos:
-            name = method_info.getName()
+            name = method_info.get_name()
             function = Function(method_info)
-            if method_info.isMethod():
+            if method_info.is_method():
                 method = instancemethod(function, None, cls)
-            elif method_info.isConstructor():
+            elif method_info.is_constructor():
                 method = classmethod(function)
             else:
                 method = staticmethod(function)
             setattr(cls, name, method)
 
-            if method_info.isConstructor():
+            if method_info.is_constructor():
                 constructor_infos.append(method_info)
 
         default_constructor_info = None
@@ -100,7 +100,7 @@ class GObjectIntrospectionMeta(gobject.GObjectMeta):
             (default_constructor_info,) = constructor_infos
         else:
             for constructor_info in constructor_infos:
-                if constructor_info.getName() == 'new':
+                if constructor_info.get_name() == 'new':
                     default_constructor_info = constructor_info
                     break
 
@@ -111,8 +111,8 @@ class GObjectIntrospectionMeta(gobject.GObjectMeta):
             cls.__init__ = lambda self, *args, **kwargs: super(cls, self).__init__()
 
     def _setup_fields(cls):
-        for field_info in cls.__info__.getFields():
-            name = field_info.getName().replace('-', '_')
+        for field_info in cls.__info__.get_fields():
+            name = field_info.get_name().replace('-', '_')
             setattr(cls, name, Field(field_info))
 
 
@@ -120,12 +120,12 @@ class GIStruct(object):
 
     def __init__(self, buffer=None):
         if buffer is None:
-            buffer = self.__info__.newBuffer()
+            buffer = self.__info__.new_buffer()
         self.__buffer__ = buffer
 
     def __eq__(self, other):
-        for field_info in self.__info__.getFields():
-            name = field_info.getName()
+        for field_info in self.__info__.get_fields():
+            name = field_info.get_name()
             if getattr(self, name) != getattr(other, name):
                 return False
         return True
diff --git a/tests/test_girepository.py b/tests/test_girepository.py
index 7e3e74b..8174881 100644
--- a/tests/test_girepository.py
+++ b/tests/test_girepository.py
@@ -630,7 +630,7 @@ class TestGIEverything(unittest.TestCase):
     def testObj(self):
         # Test inheritance.
         self.assertTrue(issubclass(Everything.TestObj, gobject.GObject))
-        self.assertEquals(Everything.TestObj.__gtype__, Everything.TestObj.__info__.getGType())
+        self.assertEquals(Everything.TestObj.__gtype__, Everything.TestObj.__info__.get_g_type())
 
     def testDefaultConstructor(self):
         # Test instanciation.



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